Forum Discussion

RobKay12's avatar
RobKay12
Icon for Helper I rankHelper I
2 years ago
Solved

Comparing YTD to Previous Year

Hello,   I am looking for a way to see data collected for the same time period the previous year. For example I have data from Jan 1 to May 31, 2024 (as seen below) and I want to look up in my tabl...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi RobKay12 ,

     

    Based on your description, I created these data.

     

     

    Create MEASURE.

    MEASURE = 
    VAR _max_date =
        CALCULATE ( MAX ( '2024'[date] ), ALL ( '2024' ) )
    VAR _min_date =
        CALCULATE ( MIN ( '2024'[date] ), ALL ( '2024' ) )
    VAR _last_year_start =
        DATE ( YEAR ( _min_date ) - 1, MONTH ( _min_date ), DAY ( _min_date ) )
    VAR _last_year_end =
        DATE ( YEAR ( _max_date ) - 1, MONTH ( _max_date ), DAY ( _max_date ) )
    VAR _sum =
        CALCULATE (
            SUM ( '2023'[event] ),
            FILTER (
                ALL ( '2023' ),
                '2023'[date] >= _last_year_start
                    && '2023'[date] <= _last_year_end
                    && '2023'[site] = MAX ( '2024'[site] )
            )
        )
    RETURN
        _sum

     

    If your Current Period does not refer to this, please clarify in a follow-up reply.

     

    Best Regards,

    Clara Gong

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.