Concept Breakdown
DAX variables (declared with `VAR` and returned with `RETURN`) allow you to store the result of an expression in a named variable. These variables can then be reused multiple times within the same measure or iterated function. This practice significantly improves formula readability, simplifies debugging by isolating calculation steps, and can sometimes optimize performance by preventing redundant calculations.
What You Will Learn
Understand when to use VAR, RETURN, DIVIDE, SUM, CALCULATE, ISBLANK in a Power BI model.
Practice the concept inside a real PBIX report rather than only reading syntax.
Complete a intermediate-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.
Download and unzip the 'Music Tours - Variables.pbix' file and open it in Power BI Desktop.
In the existing table visual, create a new measure.
Inside this measure, define three variables: `TotalTicketsSold`, `TotalTicketsAvailable`, and `UnsoldTickets`.
Initialize `TotalTicketsSold` to calculate the sum of 'Show'[Tickets sold].
Initialize `TotalTicketsAvailable` to calculate the sum of 'Show'[Tickets available].
Initialize `UnsoldTickets` as the difference between `TotalTicketsAvailable` and `TotalTicketsSold`.
Add a `RETURN` statement to the measure that divides `UnsoldTickets` by `TotalTicketsAvailable`.
Apply appropriate formatting (e.g., percentage) to the new measure and add it to the table visual.
Observe the discrepancy for artists with negative unsold tickets. Modify the definitions of `TotalTicketsSold` and `TotalTicketsAvailable` variables to only include rows where both 'Show'[Tickets sold] and 'Show'[Tickets available] fields are not blank, using `CALCULATE` with appropriate filters.
Starter DAX
```dax
Unsold Tickets Percentage =
```