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 ))
v-zhangti
2 years agoCommunity Support
Hi, DiepNhiep
Can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures or Excel. I look forward to your response.
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
DiepNhiep
2 years agoFrequent Visitor
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] ) )
RETURN
CALCULATE (
SUM (SalesTable[SalesColumn] ),
DATESINPERIOD ( 'Calendar'[Date], minDate - 1, - selectedDays, DAY )
)