Forum Discussion
DiepNhiep
2 years agoFrequent Visitor
Dynamic previous Period comparison
Hi all, I would like to get help on the dynamic date comparison. The example is as follow: I have a Sales table with date, item name, and Sales. Suppose the Date slicer to be set as 1 Sep 2023 to...
- 2 years ago
Thank you, I found the solution by scrolling one of the previous questions in the community. It goes like this solving the problem for me:
LastPeriod =VAR selectedDays =CALCULATE ( COUNT ( Calendar[Date] ), ALLSELECTED ( Calendar[Date] ) )VAR minDate =CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )RETURNCALCULATE (SUM (SalesTable[SalesColumn] ),DATESINPERIOD ( 'Calendar'[Date], minDate - 1, - selectedDays, DAY ))
Ashish_Mathur
2 years agoSuper User
Hi,
1 Sep - 1 Oct 2023 is 31 days. Therefore shouldn't the previous period be 31 Jul - 31 Aug? Why have you mentioned 1 Aug - 31 Aug?
DiepNhiep
2 years agoFrequent Visitor
That is true, I was in a hurry so it is like a miscalculations.