The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
What should be difference
Dax1 =
Solved! Go to Solution.
Hi @RajCZ ,
The difference between the two DAX formulas lies in how they handle the year filtering, and the behavior of Dax2 can lead to unintended results.
You can modify your formula like below, it can get the same result:
Dax1 =
VAR Yr = MAX('Date'[Year]) - 1
RETURN CALCULATE(SUM(Sales[Sale]), 'Date'[Year] = Yr)
Dax2 =
CALCULATE(
SUM(Sales[Sale]),
'Date'[Year] = MAX('Date'[Year]) - 1
)
Best Regards,
Adamk Kong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Yes, I know I can update like that, but I am just wondering what is value that I see in DAX2, may be I can find a sceanrio in future where that type of calculation be useful.
Thanks
Hi @RajCZ ,
In DAX2, you directly use CALCULATE to filter the SUM(Sales[Sale]) measure where the 'Date' table's year is equal to the maximum year in your 'Date' table minus 1. This means it's trying to filter for the year Yr - 1 where Yr is the maximum year in your 'Date' table.
CALCULATE(SUM(Sales[Sale]), 'Date'[Year] - 1)
Implicit Context in DAX2: DAX2 subtracts 1 from the 'Date'[Year] column without specifying a condition for CALCULATE. It filters for the year that is one less than the maximum year in the entire 'Date' table, not the year before the maximum year in context.
In short, there are very few scenarios in which dax2 would be written in such a way that it would produce unexpected results
Best Regards,
Adamk Kong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @RajCZ ,
The difference between the two DAX formulas lies in how they handle the year filtering, and the behavior of Dax2 can lead to unintended results.
You can modify your formula like below, it can get the same result:
Dax1 =
VAR Yr = MAX('Date'[Year]) - 1
RETURN CALCULATE(SUM(Sales[Sale]), 'Date'[Year] = Yr)
Dax2 =
CALCULATE(
SUM(Sales[Sale]),
'Date'[Year] = MAX('Date'[Year]) - 1
)
Best Regards,
Adamk Kong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
38 | |
25 | |
22 | |
20 | |
19 |
User | Count |
---|---|
75 | |
39 | |
29 | |
29 | |
17 |