Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

How to calculate change from previous month -- but only within the same year

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.

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

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!

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

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!

CNENFRNL
Community Champion
Community Champion

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!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.