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
alicewang96
Helper I
Helper I

DAX for calculating YOY % change does not work

DAX.pngI'm trying to calculate year-over-year % change. I've created three measures to do this: Total, PY Total2, % Change.

The formulas I've used are as follows:

 

1. Total:

Total = SUM(data[Monetary Amount])
2. PY Total2:
PY Total2 = calculate(sum(data[Monetary Amount]),sameperiodlastyear(data[Posting Date]),all(data))
3. % Change:
% Change = divide([Total]-[PY Total2],[PY Total2],0)
 
All the values are being calculated correctly, with the exception of the two rows highlighted in the photo above (Total 2018, PYTotal2 2019).  Can anyone tell me where I've gone wrong? Thank you in advance!
 

 

4 REPLIES 4
Anonymous
Not applicable

This depends on how your dataset is, but you could do something like this

 

PY Total2 = 
VAR cYear = IF(HASONEVALUE(data[Posting Year]),VALUES(data[Posting Year]))

RETURN
IF(
  NOT(ISBLANK(cYear)),
  CALCULATE(
    [Total],
    data[Posting Year] = (cYear - 1),
    all(data)
  )
)

 

 

Anonymous
Not applicable

I would guess that in the Total 2018 you have the full year and in the PY Total (2019), you only have Jan-Sep 2018 since within 2019 you do not have dates for the full year. Hence, sameperiodlastyear will shift the dates from Jan-Sep 2019 to Jan-Sep 2018 and that is what you are seeing in PY Total for 2019.

 

Regards,

Kristjan

Thanks for your response! Do you know how I can fix this formula to be accurate if we don't have all of our 2019 date yet?

Greg_Deckler
Community Champion
Community Champion

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

That being said, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.