Concept Breakdown
DAX variables (declared using the `VAR` keyword) allow you to store the result of an expression and reuse it multiple times within a single measure or calculated column. This significantly enhances formula readability, makes debugging easier, and can sometimes improve performance by avoiding redundant calculations. Variables are evaluated once for their scope and hold their value for the remainder of that scope.
What You Will Learn
Understand when to use VAR, SUM, DIVIDE in a Power BI model.
Practice the concept inside a real PBIX report rather than only reading syntax.
Complete a beginner-level task and verify the result with a hidden answer check.
Practice in Power BI
The starter PBIX link has not been attached yet. The student workflow is ready for the admin to connect the file.
Open the provided Power BI file.
Create a new measure and name it "Win ratio".
Within this measure, declare a variable named `Nominations` that holds the total sum of all nominations for the current filter context.
Declare a second variable named `Wins` that holds the total sum of all wins for the current filter context.
The measure should then return the value of the `Wins` variable divided by the `Nominations` variable.
Ensure your division handles potential divide-by-zero errors (e.g., for categories with no nominations) by returning a suitable default value like 0 in such cases.
Optionally, experiment by commenting out parts of your formula and returning different variables to display only the number of nominations or the number of wins for debugging or understanding.
Save your Power BI file.
Starter DAX
Win ratio =
VAR
Nominations = -- Your calculation for nominations
VAR
Wins = -- Your calculation for wins
RETURN
-- Your division calculation using Nominations and WinsExpected Outcome
A measure named 'Win ratio' that displays the ratio of total wins to total nominations for films, handling divide-by-zero errors gracefully. For example, if a film received 2 wins out of 10 nominations, the ratio would be 0.2.