Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hi everyone,
I’m trying to understand a behavior in DAX and would appreciate your help.
Here are my measures:
When I use [Overall Average Price] inside the High Ticket Orders measure (instead of [Average Retail Price]), the measure works as expected.
However, when I use [Average Retail Price], the High Ticket Orders measure returns blank in a Matrix visual — even though the Matrix has no rows or columns (only the measure in Values).
My question is:
Why does using [Average Retail Price] cause the measure to return blank, while using [Overall Average Price] works correctly?
What is happening in terms of filter context that explains this behavior?
Thank you in advance for your help!
Solved! Go to Solution.
HI @EfratY
Here are the main points explaining what's going on:
CALCULATE.[Average Retail Price] is treated as CALCULATE ( [Average Retail Price] ).CALCULATE function within a row context causes context transition, where the row context is transformed into an equivalent filter context before evaluating the first argument of CALCULATE.High Ticket Orders measure, the FILTER function is an iterator which iterates over 'Product Lookup', evaluating the 2nd argument expression Product Lookup'[ProductPrice] > [Average Retail Price] within a row context corresponding to each row of 'Product Lookup'.'Product Lookup' in the "current row", including 'Product Lookup'[ProductPrice], are added as filters when evaluating [Average Retail Price]. This means [Average Retail Price] will return the average of just the single price on the current row iterated by FILTER. In other words [Average Retail Price] will return the same value as 'Product Lookup'[ProductPrice] for any given row of 'Product Lookup' iterated by FILTER.'Product Lookup'[ProductPrice] > [Average Retail Price] is logically equivalent to 'Product Lookup'[ProductPrice] > 'Product Lookup'[ProductPrice], which is always false (a value is never greater than itself).[Average Retail Price] with [Overall Average Price], context transition still happens, but [Overall Average Price] removes filters on 'Product Lookup' via ALL ( 'Product Lookup' ) so the filters due to context transition are ignored. The value returned by [Overall Average Price] would however ignore any existing filters on 'Product Lookup' so would not change due to any existing filters on 'Product Lookup'.[Average Retail Price] in a variable before calling FILTER. This avoids the whole context transition complication and should return the intended value. I would also recommend changing FILTER ( ... ) to a boolean condition within KEEPFILTERS. See below:High Ticket Orders improved v1 =
VAR AveragePrice = [Average Retail Price]
RETURN
CALCULATE (
[Total Orders],
FILTER (
'Product Lookup',
'Product Lookup'[ProductPrice] > AveragePrice
)
)High Ticket Orders improved v2 =
VAR AveragePrice = [Average Retail Price]
RETURN
CALCULATE (
[Total Orders],
KEEPFILTERS ( 'Product Lookup'[ProductPrice] > AveragePrice )
)
Some good reading on this topic:
https://www.sqlbi.com/articles/understanding-context-transition-in-dax/
High Ticket Orders =
VAR GlobalAvgPrice = [Average Retail Price]
VAR HighTicketProducts =
FILTER(
'Product Lookup',
'Product Lookup'[ProductPrice] > GlobalAvgPrice
)
RETURN
CALCULATE(
[Total Orders],
HighTicketProducts
)if this solves your problem, please mark this as solved.
Hi @EfratY ,
May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.
Thank you
Thankyou @OwenAuger and @pcoley for your responses.
Hi @EfratY
We appreciate your inquiry through the Microsoft Fabric Community Forum.
We would like to inquire whether have you got the chance to check the solutions provided by @OwenAuger and @pcoley to resolve the issue. We hope the information provided helps to clear the query. Should you have any further queries, kindly feel free to contact the Microsoft Fabric community.
Thank you.
HI @EfratY
Here are the main points explaining what's going on:
CALCULATE.[Average Retail Price] is treated as CALCULATE ( [Average Retail Price] ).CALCULATE function within a row context causes context transition, where the row context is transformed into an equivalent filter context before evaluating the first argument of CALCULATE.High Ticket Orders measure, the FILTER function is an iterator which iterates over 'Product Lookup', evaluating the 2nd argument expression Product Lookup'[ProductPrice] > [Average Retail Price] within a row context corresponding to each row of 'Product Lookup'.'Product Lookup' in the "current row", including 'Product Lookup'[ProductPrice], are added as filters when evaluating [Average Retail Price]. This means [Average Retail Price] will return the average of just the single price on the current row iterated by FILTER. In other words [Average Retail Price] will return the same value as 'Product Lookup'[ProductPrice] for any given row of 'Product Lookup' iterated by FILTER.'Product Lookup'[ProductPrice] > [Average Retail Price] is logically equivalent to 'Product Lookup'[ProductPrice] > 'Product Lookup'[ProductPrice], which is always false (a value is never greater than itself).[Average Retail Price] with [Overall Average Price], context transition still happens, but [Overall Average Price] removes filters on 'Product Lookup' via ALL ( 'Product Lookup' ) so the filters due to context transition are ignored. The value returned by [Overall Average Price] would however ignore any existing filters on 'Product Lookup' so would not change due to any existing filters on 'Product Lookup'.[Average Retail Price] in a variable before calling FILTER. This avoids the whole context transition complication and should return the intended value. I would also recommend changing FILTER ( ... ) to a boolean condition within KEEPFILTERS. See below:High Ticket Orders improved v1 =
VAR AveragePrice = [Average Retail Price]
RETURN
CALCULATE (
[Total Orders],
FILTER (
'Product Lookup',
'Product Lookup'[ProductPrice] > AveragePrice
)
)High Ticket Orders improved v2 =
VAR AveragePrice = [Average Retail Price]
RETURN
CALCULATE (
[Total Orders],
KEEPFILTERS ( 'Product Lookup'[ProductPrice] > AveragePrice )
)
Some good reading on this topic:
https://www.sqlbi.com/articles/understanding-context-transition-in-dax/
The key difference comes down to filter context (and how row context from the FILTER iterator interacts with it) during evaluation of the condition inside High Ticket Orders.
Your High Ticket Orders measure builds a filtered version of the 'Product Lookup' table and then uses that as a table filter argument inside CALCULATE. The FILTER function iterates row-by-row over 'Product Lookup' (in whatever outer filter context exists—in your empty Matrix visual, that's the full/unfiltered model). For each row, it evaluates the boolean condition:
'Product Lookup'[ProductPrice] > [Some Average Measure]
Here's where the behavior diverges:
This happens even in your empty Matrix (grand-total context with no slicers/row/column fields), because the per-row evaluation inside FILTER is what introduces the restrictive context.
The grand-total context (no dimensions) means the outer filter context is the same for both versions. But the internal evaluation inside FILTER(...) is what matters—and that's where the simple aggregator vs. the CALCULATE(... ALL ...) version behaves differently.
Don't reference the measure directly in the FILTER predicate when it aggregates the iterated table. Instead, capture the scalar value once (outside the iterator) with a variable:
High Ticket Orders = VAR AvgPrice = [Average Retail Price] // or [Overall Average Price] — either works now RETURN CALCULATE( [Total Orders], FILTER( 'Product Lookup', 'Product Lookup'[ProductPrice] > AvgPrice ) )
(You could also hard-code the comparison with CALCULATE([Average Retail Price], ALL('Product Lookup')) directly in the VAR, or use AVERAGEX(ALL('Product Lookup'), 'Product Lookup'[ProductPrice]).)
I hope this helps. if so please mark it as a solution. kudos are welcome.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 3 | |
| 2 | |
| 1 |
| User | Count |
|---|---|
| 21 | |
| 14 | |
| 9 | |
| 5 | |
| 5 |