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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Oros
Post Prodigy
Post Prodigy

Compare to last year

Hello,

 

I would like to compare last year's sales based on the date selection.  For example,  if the date selected is April 1-15, 2024, the previous year column should show the sales for April 1-15, 2023.

 

I created 2 sample measures based on SAMEPERIODLASTYEAR and DATEADD but it seems that I am missing something.  The PREVIOUS YEARS show the same as the current year (selected date range). Thanks.

 

PREVIOUS YEAR (1) = CALCULATE(SUM('Sheet1'[SALES]), dateadd('Sheet1'[DATE].[Date],-1,YEAR))
PREVIOUS YEAR (2) = CALCULATE(SUM(Sheet1[SALES]), SAMEPERIODLASTYEAR(Sheet1[DATE].[date]))
 
Oros_0-1718048562669.png

 

 
1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with a relationship (Many to One and Single) from the Date column of sheet1 to the Date column of the Calendar Table.  To your visual/slicer/filter, drag Date from the Calendar Table.  Write these measures:

Total = SUM('Sheet1'[SALES])

Total in SPLY = CALCULATE(SUM('Sheet1'[SALES]), sameperiodlastyear(calendar[date]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with a relationship (Many to One and Single) from the Date column of sheet1 to the Date column of the Calendar Table.  To your visual/slicer/filter, drag Date from the Calendar Table.  Write these measures:

Total = SUM('Sheet1'[SALES])

Total in SPLY = CALCULATE(SUM('Sheet1'[SALES]), sameperiodlastyear(calendar[date]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur ,

 

As always, you never hesitate to help and share your knowledge!  Thanks!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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