Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Alusine_Kamara
Helper II
Helper II

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 contains Household Size is a variable.

In DAX, is a Variable in the same sense as the one described above for survey data? 

1 ACCEPTED SOLUTION
vanessafvg
Super User
Super User

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?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
Alusine_Kamara
Helper II
Helper II

Hi Vanessafvg, I wholeheartedly accept your solution. I have benefitted a lot from it. Coming from a research background, we talk a lot about Variables. With all respect, I have to google the meaning of Variable in Research, and I got this: 

In research, variables are any characteristics that can take on different values, such as height, age, temperature, or test scores. Researchers often manipulate or measure independent and dependent variables in studies to test cause-and-effect relationships. (what is a variable in research - Google Search)


Based on your explanation, with reference to the Google result and, with knowledge from other sources, I think Variables in DAX are different from Variables in research. All you explained on DAX Variables is good and I have learnt alot from it thus, you deserve an "Accept Solution". My aim is to understand the logic and concepts of DAX and you've just helped me with Variables in DAX. Thanks a million.

You will have to bear with me as I am a desprate man wanting to learn and understand DAX. Been in Power BI now for eight months, some questions from me may sound bad or difficult to understand, hence I would appreciate it if you would bear with me.

no problem, thats what we are here to do!





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




vanessafvg
Super User
Super User

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?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.