Forum Discussion

DiepNhiep's avatar
DiepNhiep
Frequent Visitor
2 years ago
Solved

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...
  • DiepNhiep's avatar
    DiepNhiep
    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] ) )
    RETURN
            CALCULATE (
                SUM (SalesTable[SalesColumn] ),
                DATESINPERIOD ( 'Calendar'[Date], minDate - 1, - selectedDays, DAY )
            )