This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
I've been slowly learning to use variables however I've run into a result that I dont understand
I have a table with Sales by Manager that is filtered by TopN 10 Managers based on sales.
I have the following measures, one just a sales total, another is two display a total that accounts for all sales not just top 10 managers.
Sum of sales =
SUM ( 'FactSales'[Sales] )
Sales Top 10 =
IF (
HASONEVALUE ( 'FactSales'[Manager] );
'FactSales'[Sum of sales];
CALCULATE ( 'FactSales'[Sum of sales]; ALL ( 'FactSales'[Manager] ) )
)
This measure displays the correct total for all sales
I tried writting the same measure with variables
Sales Top 10 =
VAR Sales =
SUM ( 'FactSales'[Sales] )
RETURN
IF (
HASONEVALUE ( 'FactSales'[Manager] );
Sales;
CALCULATE ( Sales; ALL ( 'FactSales'[Manager] ) )
)
However it only shows the total for top 10.
Whats causing this behaviour?
Solved! Go to Solution.
Hi @Credo
When a variable is defined with VAR, it is evaluated in the context where it is defined, then it is effectively a constant when used in any subsequent expressions. Currently there is no way to define a measure locally within another measure, so I would recommend sticking with Sum of Sales as a separate measure and referencing that within Sales Top 10.
To explain further, in your second example, after the variable Sales is defined as SUM ( 'FactSales'[Sales] ), the expression CALCULATE ( Sales; ALL ( 'FactSales'[Manager] ) ) gives exactly the same result as Sales, since Sales is effectively a constant, and modifying filters makes no difference to a constant.
Regards,
Owen
Hi @Credo
When a variable is defined with VAR, it is evaluated in the context where it is defined, then it is effectively a constant when used in any subsequent expressions. Currently there is no way to define a measure locally within another measure, so I would recommend sticking with Sum of Sales as a separate measure and referencing that within Sales Top 10.
To explain further, in your second example, after the variable Sales is defined as SUM ( 'FactSales'[Sales] ), the expression CALCULATE ( Sales; ALL ( 'FactSales'[Manager] ) ) gives exactly the same result as Sales, since Sales is effectively a constant, and modifying filters makes no difference to a constant.
Regards,
Owen
Check out the May 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 26 | |
| 25 | |
| 22 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 42 | |
| 41 | |
| 40 | |
| 21 | |
| 20 |