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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Naveeduddin
Frequent Visitor

YoY Date Comparison

Hi All,

 

I'm trying to do a YoY Comparison for 2021 and 2020, so when I use the sameperiodlastyear it compares the exact same date last year but I want it to calculate one day ahead

 

For Ex: My date range is 19 Dec 2021 to 25 Dec 2021, it should compare 20 Dec 2020 to 26 Dec 2020

 

Kindly help!

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Naveeduddin , Try a measure like

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-364,DAY))

View solution in original post

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

All measures are in the attached pbix file.

If I may suggest other than the below, if you have calendar table with week number column, you can compare it by utilizing the same week number last year.

 

Picture1.png

Sales: =
SUM(Data[Sales])

 

 

Sales previous year expected result: =
VAR mindate =
CALCULATE ( MIN ( 'Calendar'[Date] ), SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) ) + 1
VAR maxdate =
CALCULATE ( MAX ( 'Calendar'[Date] ), SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) ) + 1
RETURN
CALCULATE ( [Sales:], DATESBETWEEN ( 'Calendar'[Date], mindate, maxdate ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

6 REPLIES 6
Naveeduddin
Frequent Visitor

Thank you! This was helpful 

Naveeduddin
Frequent Visitor

Wow, Amazing! This worked. Thanks a lot

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

All measures are in the attached pbix file.

If I may suggest other than the below, if you have calendar table with week number column, you can compare it by utilizing the same week number last year.

 

Picture1.png

Sales: =
SUM(Data[Sales])

 

 

Sales previous year expected result: =
VAR mindate =
CALCULATE ( MIN ( 'Calendar'[Date] ), SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) ) + 1
VAR maxdate =
CALCULATE ( MAX ( 'Calendar'[Date] ), SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) ) + 1
RETURN
CALCULATE ( [Sales:], DATESBETWEEN ( 'Calendar'[Date], mindate, maxdate ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


I was trying to get there. But you did faster! @Jihwan_Kim 

bcdobbs
Super User
Super User

Not by a computer however SAMEPERIODLASTYEAR returns a table of dates. I think you should just be able to wrap it in DATEADD.

 

Can flesh that out later if you need?



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
amitchandak
Super User
Super User

@Naveeduddin , Try a measure like

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-364,DAY))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors