Forum Discussion
Variables in DAX
- 2 years ago
do you mean is the value variable or that you can set a variable to a value.
for example, when i use a variable its is because i need to precalulate something so i set a value i need into memory using a variable and then i can keep referring to that variable when i need it.
so when i use the function var variablename = my calculation. that will hold it in memory.
not sure if this makes sense or if this is not what you are asking. maybe if you can demonstrate with an example if this doesn't make sense
for example i might want calculate the % of the total households where the number of people category = "<=4"
% households where 4 or less people =
VAR totalhouseholds =
COUNTROWS ( households )
VAR cathouseholds =
CALCULATE ( COUNTROWS ( households ), category = "<=4" )
VAR result =
DIVIDE ( cathouseholds, totalhouseholds )
RETURN
resultnot sure if this is what you mean?
do you mean is the value variable or that you can set a variable to a value.
for example, when i use a variable its is because i need to precalulate something so i set a value i need into memory using a variable and then i can keep referring to that variable when i need it.
so when i use the function var variablename = my calculation. that will hold it in memory.
not sure if this makes sense or if this is not what you are asking. maybe if you can demonstrate with an example if this doesn't make sense
for example i might want calculate the % of the total households where the number of people category = "<=4"
% households where 4 or less people =
VAR totalhouseholds =
COUNTROWS ( households )
VAR cathouseholds =
CALCULATE ( COUNTROWS ( households ), category = "<=4" )
VAR result =
DIVIDE ( cathouseholds, totalhouseholds )
RETURN
result
not sure if this is what you mean?