Forum Discussion

Alusine_Kamara's avatar
2 years ago
Solved

Variables in DAX

Please help me. From survey data I have been working with, a variable is an entity that changes. Example, Household Size could be a variable the value of which changes per household. A column that co...
  • vanessafvg's avatar
    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 ( cathouseholdstotalhouseholds )
    RETURN
        result

     

    not sure if this is what you mean?