Power BI DAX Variables
What Are Variables?
A variable stores the result of an expression under a name.
You can then use that name in the rest of the formula.
This page uses the Poke Mart model described in DAX Introduction, with the Total Sales measure from DAX Measures.
Variables use two keywords, VAR and RETURN:
Syntax
Measure Name =
VAR name1 = expression1
VAR name2 = expression2
RETURN
result
| Keyword | Meaning |
|---|---|
| VAR | Defines a variable: a name, an equal sign and an expression. You can have as many as you need. A variable can use the variables above it. |
| RETURN | The final expression. Its value is the result of the measure. |
A First Example
What share of the sales comes from big orders, the orders with a quantity of 10 or more?
You need the sales of the big orders, the sales of all orders, and then a division:
Example
Big Order % =
VAR BigOrderSales = CALCULATE([Total Sales], Sales[Quantity] >= 10)
VAR AllSales = [Total Sales]
RETURN
DIVIDE(BigOrderSales, AllSales)
Format the measure as Percentage with 2 decimal places, and put it in a matrix by Category:
| Category | Total Sales | Big Order % |
|---|---|---|
| Balls | 4,447,200 | 61.32% |
| Medicine | 4,413,600 | 33.85% |
| Status Healers | 556,000 | 23.58% |
| Total | 9,416,800 | 46.22% |
The variable names tell the reader what each part is.
The RETURN line reads almost like a sentence: divide the big order sales by all sales.
The big order sales come from the same simple filter as on the FILTER page: 4,352,100 of 9,416,800 in total.
Write a Formula on Several Lines
In the formula bar, press Shift+Enter or Alt+Enter to start a new line.
Press Enter when the formula is done.
To get more room, select the arrow at the right end of the formula bar to make it bigger.
Do not press Esc to close the suggestion list while you type.
Esc cancels the whole measure, not only the list.

Rules for Variable Names
- Use letters and digits. Do not start with a digit.
- No spaces: write
BigOrderSales, not Big Order Sales. - Do not use the name of a table. A variable cannot be called
Sales, because the model has a Sales table. - Do not use DAX keywords, like VAR or RETURN.
Year-over-Year Growth with Variables
Year-over-year growth (YoY) compares sales with the same period one year earlier:
(this year - last year) / last year
Last year's sales come from a time intelligence function that you will learn on the next page, SAMEPERIODLASTYEAR.
For now, you only need to know what this expression returns:
CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date]))
It returns the sales of the same period, one year earlier.
In a visual filtered to 2025, it returns the sales of 2024: 4,393,200.
Without variables, the growth formula needs this expression twice:
DIVIDE(
[Total Sales] - CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date])),
CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date]))
)
It works, but it is long, and the same calculation is written twice.
With variables, each part is written once, and gets a name:
Example
Sales YoY % VAR =
VAR CurrentSales = [Total Sales]
VAR LastYearSales = CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date]))
RETURN
DIVIDE(CurrentSales - LastYearSales, LastYearSales)
Format it as Percentage with 2 decimal places.
Make a matrix with Region in Rows, and Total Sales and Sales YoY % VAR in Values.
Add a slicer with Year.
A slicer on a number column like Year starts as a Between slider, so go to Format visual > Visual > Slicer settings > Options and set Style to Vertical list. Then select 2025:
| Region (2025) | Total Sales | Sales YoY % VAR |
|---|---|---|
| Hoenn | 1,647,300 | 24.35% |
| Johto | 1,751,200 | 8.60% |
| Kanto | 1,625,100 | 11.61% |
| Total | 5,023,600 | 14.35% |
Hoenn grew the most, from 1,324,700 in 2024 to 1,647,300 in 2025. That is (1,647,300 - 1,324,700) / 1,324,700 = 24.35%.
If you select 2024 in the slicer, the measure is blank.
The data starts in 2024, so there is no last year to compare with.
The next page explains this.
On the next page, you create a separate Sales LY measure for last year's sales, and a Sales YoY % measure that uses it.
It gives the same results as Sales YoY % VAR.
A variable can also hold a measure, for example VAR LastYearSales = [Sales LY].
Why Use Variables?
| Benefit | Why |
|---|---|
| Readability | Names like CurrentSales and LastYearSales explain each step. The RETURN line is short. |
| Speed | A variable is calculated only once, even if you use it several times in the formula. |
| Easier testing | To check one part, change the RETURN line to return that variable, for example RETURN LastYearSales. Look at the result in a visual, then change it back. |
A Variable Does Not Change
A variable is calculated where it is defined, in the filter context of the visual.
After that, its value does not change.
Even CALCULATE cannot change it:
Example
Variable Trap =
VAR AllSales = [Total Sales]
RETURN
CALCULATE(AllSales, Stores[Region] = "Kanto")
In a card, this measure shows the grand total, 9,416,800 (shortened on the card), not the Kanto sales (3,081,150).
AllSales was already calculated before CALCULATE added the Kanto filter.
To filter a calculation, put the measure itself inside CALCULATE: CALCULATE([Total Sales], Stores[Region] = "Kanto").
What You Learned
- VAR stores the result of an expression under a name, and RETURN gives the result of the measure.
- Variables make long formulas easier to read, test and calculate.
- Variable names have no spaces and cannot be the name of a table.
- A variable is calculated once, and CALCULATE cannot change its value.