Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Dynamic year on year calculation

Hi all,

 

I am trying to figure out how to calculate a dynamic year on year calculation. I am using the following calculation options:

  • Total Sales SamePeriodLastYear =
    CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR( ( 'Date'[Date] ) ))
    To calculate sales based on a period (month/quarter/year)
  • Total Sales PY =
    CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -364, DAY ) )
    To calculate sales based on the same day in the same ISO week (tuesday 08-06-2021 vs tuesday 09-06-2020)

These calculations are indeed dynamic, a user can select a different period by using a slicer which is a dropdown. Here the user can select another year, week or whatever they want. But the problem is that it is always a 1 year comparison.

 

I want to create another dropdown slicer where the user can select a year which then the calculations use for the comparison. So for example:

  • User selects Year 2021 in slicer A which the user wants to see the data from.
  • User selects Year 2017 in slicer B where the comparison will be made. 
  • Result = Year 2021 will be compared with Year 2017 for all measures which uses the above.

I have seen this article which is really usefull and does a bit of what I want to create: Dax Pattersn | Comparing different time periods . But I also want to use the date (year/month/week) on the x axis. Which is not possible with this solution. I have the exact same setup as which is shown in the article.

 

Please could someone help me out with this? If you need more information please let me know.

   

2 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi amitchandak ,

      Thanks for your reply. I am sorry but I forgot to mention that, in my fact table, I only use a DateKey which has many to one connection with the Date table.

       

      Is it then also possible to use the solutions displayed in the YouTube video?