Forum Discussion

Oros's avatar
Oros
Icon for Post Prodigy rankPost Prodigy
2 years ago
Solved

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]))
 

 

 
  • 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.

3 Replies

  • 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.