The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I'm looking for the DAX code to write a Power BI measure to calculate the change in value from the previous month. But I don't want January to show the change since December; instead, I want January to show the difference from the budget amount. I'm going to use the measure in a waterfall graph.
I used the Quick Measure to generate the code to calculate the change in value:
LE Difference =
VAR __Prev_Month = CALCULATE([Monthly LE], DATEADD('Date'[Date].[Date], -1, MONTH))
RETURN
[Monthly LE] - __Prev_Month
But since I want the January value to be the change from the Budget (instead of from last December's Latest Estimate), my plan is to test for the Month Number and change the formula accordingly. I tried inserting
VAR This_month = month('Date'[Date].[Date])
but this gives me the error: A single value for variation 'Date' for column 'Date' in table 'Date' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
And I suspected that this would happen, but I don't remember how to work around it.
Solved! Go to Solution.
Hi, @Anonymous , from syntax's perspective, you might want to try,
VAR this_month = MONTH( MAX('Date'[Date].[Date]) )
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Yes, that worked, as did
This_month = max('Date'[Date].[Month])
though I'm not sure why the max month is able to change for each iteration.
As a matter of fact, MAX('Date'[Date].[Month]) is a syntactic sugar for MAXX('Date', 'Date'[Date].[Month]); here 'Date' table is subject to changes of filter context. During iteration, filter context changes; MAX() changes accordingly.
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Hi, @Anonymous , from syntax's perspective, you might want to try,
VAR this_month = MONTH( MAX('Date'[Date].[Date]) )
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
User | Count |
---|---|
27 | |
12 | |
8 | |
8 | |
5 |
User | Count |
---|---|
31 | |
15 | |
12 | |
7 | |
7 |