I try to write formula in notion, that display in cell max value from another cell. But notion not allow me to set a circular dependency in formulas - formula

maxDebt - it is column with formula.
lastDebt - it is column with data.
I tried to write maxDebt formula like this:
if(
prop("lastDebt") == 0,
0,
if(
prop("lastDebt") > prop("maxDebt"),
prop("lastDebt"),
prop("maxDebt")
)
)
And notion ask me error: "Property maxDebt creates a circular dependency."
How to resolve this task differently?

Related

Using a function to change a variable in R

I am trying to change a variable in a function but even tho the function is producing the right values, when I go to use them in the next sections, R is still using the initial values.
I created a function to update my variables NetN and NetC:
Reproduction=function(NetN,NetC,cnrep=20){
if(NetC/NetN<=cnrep) {
DeltaC=NetC*p;
DeltaN=DeltaC/cnrep;
Crep=Crep+DeltaC;
Nrep=Nrep+DeltaN;
Brep=(Nrep*14+Crep*12)*2/1e6;
NetN=NetN-DeltaN; #/* Update N, C values */
NetC=NetC*(1-p)
print ("'Using C to allocate'")
}
else {
print("Using N to allocate");
DeltaN=NetN*p;
DeltaC=DeltaN*cnrep;
Nrep=Nrep+DeltaN;
Crep=Crep+DeltaC;
Brep=(Nrep*14+Crep*12)*2/1e6;
NetN=NetN*(1-p);
NetC=NetC-DeltaC;
} } return(c(NetC=NetC,NetN=NetN,NewB=NewB,Crep=Crep,Nrep=Nrep,Brep=Brep))}
When I use my function by say doing:
Reproduction(NetN=1.07149,NetC=0.0922349,cnrep=20)
I get the desired result printed out which includes:
NetC=7.378792e-02
However, when I go to use NetC in the next section of my code, R is still using NetC=0.0922349.
Can I make R update NetC without having to define a new variable?
In R, in general, functions shouldn't change things outside of the function. It's possible to do so using <<- or assign(), but this generally makes your function inflexible and very surprising.
Instead, functions should return values (which yours does nicely), and if you want to keep those values, you explicitly use <- or = to assign them to objects outside of the function. They way your function is built now, you can do that like this:
updates = Reproduction(NetN = 1.07149, NetC = 0.0922349, cnrep = 20)
NetC = updates["NetC"]
This way, you (a) still have all the other results of the function stored in updates, (b) if you wanted to run Reproduction() with a different set of inputs and compare the results, you can do that. (If NetC updated automatically, you could never see two different values), (c) You can potentially change variable names and still use the same function, (d) You can run the function to experiment/see what happens without saving/updating the values.
If you generally want to keep NetN, NetC, and cnrep in sync, I would recommend keeping them together in a named vector or list, and rewriting your function to take that list as input and return that list as output. Something like this:
params = list(NetN = 1.07149, NetC = 0.0922349, cnrep = 20)
Reproduction=function(param_list){
NetN = param_list$NetN
NetC = param_list$NetC
cnrep = param_list$cnrep
if(NetC/NetN <= cnrep) {
DeltaC=NetC*p;
DeltaN=DeltaC/cnrep;
Crep=Crep+DeltaC;
Nrep=Nrep+DeltaN;
Brep=(Nrep*14+Crep*12)*2/1e6;
NetN=NetN-DeltaN; #/* Update N, C values */
NetC=NetC*(1-p)
print ("'Using C to allocate'")
}
else {
print("Using N to allocate");
DeltaN=NetN*p;
DeltaC=DeltaN*cnrep;
Nrep=Nrep+DeltaN;
Crep=Crep+DeltaC;
Brep=(Nrep*14+Crep*12)*2/1e6;
NetN=NetN*(1-p);
NetC=NetC-DeltaC;
}
## Removed extra } and ) ??
return(list(NetC=NetC, NetN=NetN, NewB=NewB, Crep=Crep, Nrep=Nrep, Brep=Brep))
}
This way, you can use the single line params <- Reproduction(params) to update everything in your list. You can access individual items in the list with either params$Netc or params[["NetC"]].

How to apply if statement to calcuate integer value inside a group question in Enketo(KoboToolbox)?

I am building a survey form through KoboToolbox. The web forms are Enketo based. I have some questions of the following type (before comma is first column and first row is data titles in XLSform format):
type, name
begin_group, group_farmexpenses_q5
note, group_farmexpenses_q5_note
integer, group_farmexpenses_q5_p1
text, group_farmexpenses_q5_column_1
end_group,
begin_group, group_farmexpenses_q5_1
note, group_farmexpenses_q5_1_note
integer, group_farmexpenses_q5_1_p1
text, group_farmexpenses_q5_1_column_1
end_group,
What i want to do is apply if statement for the integer values inside these two groups, however I get error. Here is what I do to apply if-statement :
if(${group_farmexpenses_q5_p1}=999, 0, ${group_farmexpenses_q5_p1})
if(${group_farmexpenses_q5_1_p1}=999, 0, ${group_farmexpenses_q5_1_p1})
since the above are calculate statements and each one is referred to as "expense1" and "expense2"
i then just add them
${expense1} + ${expense2}
I get error message:
if({group_farmexpenses_q5_1_p1} = 999, 0,
/model/instance[1]/data/group_wx0mk24/group_farmexpenses_q5_1/group_farmexpenses_q5_1_p1
), message: The expression is not a legal expression. (line:
undefined, character: undefined)
Any ideas how to fix this? I think there should be an easy fix but I don't know much about XLSform structures.
Proposed solution through online search for #Ziaw. Instead of first conditioning and then adding, both can be done in one step:
calculated data field compute this
if(${fexp_q1} = 999, 0, ${fexp_q1}) + if(${fexp_q2} = 999, 0,
${fexp_q2})

iccube : How to remove certainn level(s) from hierarchy in a filter widget?

Using iccube reporting V6,
I'm looking for a way to remove some levels from a hierarchy (visually) on a filter widget.
This is working on "standards" widgets
but when using a Filter widget, i can only set 1 level as member.
Ok, I found a solution. The issue with the Tree filter is that it's using the parentUnique name to build the tree. But this is something we can trick.
For a time hierachy with multiple levels let's build a Tree with the Year and Month (without quarters). For this we can use this MDX
WITH
FUNCTION __currMember() AS [Date].[Date].hierarchy.currentmember
FUNCTION __defMember() AS {[Date].[Date].allmembers}(0).hierarchy.currentmember
FUNCTION __descendant(_c) AS Tail( Filter( Axis(1) as t, isAncestor(t.currentmember, _c )),1 )(0)
FUNCTION __unName(_c) AS IIF( _c is NULL, NULL, _c.uniqueName)
MEMBER ic3Name AS __currMember().name
MEMBER ic3UName AS __currMember().uniquename
MEMBER ic3PName AS __unName( __descendant(__currMember() ))
MEMBER ic3Measure AS 0
MEMBER ic3IsSelected AS false
MEMBER ic3FilterName as [Measures].[ic3Name]
MEMBER ic3Key as __currMember().key
SELECT
{[Measures].[ic3Name],[Measures].[ic3UName],[Measures].[ic3PName],[Measures].[ic3Measure],[Measures].[ic3IsSelected],[Measures].[ic3FilterName],[Measures].[ic3Key]} ON 0,
__defMember() + Hierarchize([Date].[Date].[Year] + [Date].[Date].[Month]) ON 1
FROM [Cube]
It's the descendant() function that is doing the trick. You can change the function if it's not suiting your needs or it's too slow for something checking the levels. Note, the algo is O(N*N) on the axis, it's not great. But I think it should be generic.
With a bit of imagination and MDX you can do a bit whatever you'd like as for building the tree we're using the measures ( ON 0 axis ).

Need to Print Value of a Variable using Paste in R

I am trying to create a data frame of various error messages based on Data to be cross checked between two dataframes and storing the message in a vector in an iterative manner . I am using the following snippet for this purpose :
> for(j in 1:nrow(MySQL_Data)){ date_mysql=
> paste("MySQL_Data[",j,",1]") date_red= paste("RED_Data[",j,",1]")
> body= c() if(!date_mysql == date_red) {
> body<- append(body,paste("'There is data missing for date",date_mysql,"in",table2)) }else {
> NULL }}
My table2 variable prints as MYSQL_Data[2,1] instead of the actual value of the variable which is a date
Following is the Output :
"'There is data missing for date MySQL_Data[ 2 ,1] in Dream11_UserRegistration"
Can someone help me with the error that I am committing here..
Thanks in Advance !
Your use of paste in the definitions of data_mysql and data_red makes no sense. I’m assuming that what you actually want is this:
data_mysql = MySQL_Data[j, 1]
data_red = RED_Data[j, i]
Furthermore, you’re resetting body in every loop iteration so it will only ever hold a single element.

IcCube - Treemap with Parent/Child dimension

I currently try to build a google treemap chart in IcCube. Do I do this using a Multi Level dimension and defining every Level of drilldown separately (as shown
here and here), everything works fine.
What I would like to do is using a Parent/Child dimension and telling the treemap, just to go down this hierarchy when drilling into the treemap chart.
Is that possible?
Here is the (not working) MDX I used, where [categories] is the Parent/Child dimension:
WITH
MEMBER [category_name] as [categories].[categories].currentmember.name
SELECT
{[category_name],[Measures].[count_clicks]} on 0,
non empty [categories].[categories] on 1
FROM
[Cube]
Treemap is a tricky visualization. You need to define the two first columns as defining the parent/child relation. For example :
'Global', null
'America', 'Global'
'Europe', 'Global'
'Brazil', 'America'
The first column is by construction the Axis(1) name, so the seconds has to be the name of the parent and not the name of the member. Something like :
MEMBER [parent_name] as IIF( [categories].[categories].currentmember is [categories].[categories].[ALL],
NULL,
[categories].[categories].currentmember.parent.name )
That you can use as :
WITH
MEMBER [parent_name] as IIF( [categories].[categories].currentmember is [categories].[categories].[ALL],NULL,[categories].categories].currentmember.parent.name )
SELECT
{[parent_name],[Measures].[count_clicks]} on 0,
non empty [categories].[categories] on 1
FROM
[Cube]
This should work better.
Hope it helps.
After struggling for a while with my own data, I took the IcCube example of the parent/child Dimension (http://www.iccube.com/support/documentation/user_guide/schemas_cubes/dim_parentchild.php). Then I tried your example:
WITH
MEMBER [parent_name] as IIF( [dim (ALL)].[Hierarchy].currentmember
is [dim (ALL)].[Hierarchy].[ALL],'',
[dim (ALL)]. [Hierarchy].currentmember.parent.name )
SELECT
{[parent_name],[Measures].[value]} on 0,
non empty [dim (ALL)].[Hierarchy] on 1
FROM
[Cube]
(The NULL value had to be replaced by '')
The first dimension works, but if I try to drill into the map, the system tells me, that there is no row with id 'World'. Do you have any ideas, how to fix that?
EDIT:
After using real names in the parent/child dimension instead of ids (child: Spain; parent: Europe, value: 3) and replacing [dim (ALL)].[Hierarchy] with [dim (ALL)].[Hierarchy].members() in the code, I got a treemap working so far:
WITH
MEMBER [parent_name] as IIF( [dim (ALL)].[Hierarchy].currentmember
is [dim (ALL)].[Hierarchy],'',
[dim (ALL)].[Hierarchy].currentmember.parent.name )
SELECT
{[parent_name],[Measures].[value]} on 0,
non empty [dim (ALL)].[Hierarchy].members() on 1
FROM
[Cube]
Now after drilling down to the next level, the is an error message 'failed to find row with id "Europe"'. And I added a 3 Level into my data (child: Madrid; parent: Spain, value: 5), but I am unable to go to this level. Clicking on "Spain" doesn't change anything.

Resources