Forum Discussion

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

Compare with previous year

Sorry for posting 2 questions in 1 day.

I'm looking to create something that looks like this...

SettingSelected year attendance %Previous Year's quarter attendance %Difference %
Place A90.5%94.5%-4.0%
Place B93.0%95.9%-2.9%
Place C92.4%94.4%-2.0%
Place D91.8%93.3%-1.6%


The data I have looks something like this...

SettingQuarterYearPossible AttendanceActual Attendance
Place AQ1202120641962
Place AQ1202222982198
Place AQ1202326252352
Place BQ1202112921250
Place BQ1202213321204
Place BQ1202320731944
Place CQ1202128122675
Place CQ1202228322698
Place CQ1202327882594
Place DQ1202169556748
Place DQ1202270686690
Place DQ1202369406658


It goes on to Quarters 2, 3 & 4 too.
I need year & quarter to be selectable.  So if 2022 Q1 is selected, then "Previous Year attendance %" would show 2021 data for Q1 & give the difference.

Any ideas?


  • BassG , Try following measure

    % Attend = DIVIDE(SUM(Data[Actual Attendance]), sum(Data[Possible Attendance]))
    Last Year = CALCULATE([% Attend], OFFSET(-4, all(Data[Year], Data[Quarter],Data[Setting]), ORDERBY(Data[Year],asc, Data[Quarter],asc)))

     

    file is attached

  • Hi BassG ,

     

    Add a custom column with the Quarter end date then just use that column to make the calculations you need.

     

    Code for the column is the following

    Date.EndOfQuarter (#date([Year],Number.FromText (Text.End([Quarter],1)) - 1 * 3 + 3,1))

     

     

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi BassG ,

    You can add two tables to create slicers:

    And there is no relationship between tables:

    Use these DAXs to create measures:

    Selected year attendance % = 
    VAR Y = SELECTEDVALUE(Slicer[Year])
    VAR Q = SELECTEDVALUE(Slicer2[Quarter])
    VAR ACTUAL = SUMX(FILTER('Table', 'Table'[Year] = Y && 'Table'[Quarter] = Q), 'Table'[Actual Attendance])
    VAR POSSIBLE = SUMX(FILTER('Table', 'Table'[Year] = Y && 'Table'[Quarter] = Q), 'Table'[Possible Attendance])
    RETURN
    DIVIDE(ACTUAL, POSSIBLE)
    Previous Year's quarter attendance % = 
    VAR Y = SELECTEDVALUE(Slicer[Year])
    VAR Q = SELECTEDVALUE(Slicer2[Quarter])
    VAR ACTUAL = SUMX(FILTER('Table', 'Table'[Year] = Y - 1 && 'Table'[Quarter] = Q), 'Table'[Actual Attendance])
    VAR POSSIBLE = SUMX(FILTER('Table', 'Table'[Year] = Y - 1 && 'Table'[Quarter] = Q), 'Table'[Possible Attendance])
    RETURN
    DIVIDE(ACTUAL, POSSIBLE)
    Difference % = [Selected year attendance %] - [Previous Year's quarter attendance %]

    The final output is as below:


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

3 Replies

  • BassG , Try following measure

    % Attend = DIVIDE(SUM(Data[Actual Attendance]), sum(Data[Possible Attendance]))
    Last Year = CALCULATE([% Attend], OFFSET(-4, all(Data[Year], Data[Quarter],Data[Setting]), ORDERBY(Data[Year],asc, Data[Quarter],asc)))

     

    file is attached

  • Hi BassG ,

     

    Add a custom column with the Quarter end date then just use that column to make the calculations you need.

     

    Code for the column is the following

    Date.EndOfQuarter (#date([Year],Number.FromText (Text.End([Quarter],1)) - 1 * 3 + 3,1))

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi BassG ,

    You can add two tables to create slicers:

    And there is no relationship between tables:

    Use these DAXs to create measures:

    Selected year attendance % = 
    VAR Y = SELECTEDVALUE(Slicer[Year])
    VAR Q = SELECTEDVALUE(Slicer2[Quarter])
    VAR ACTUAL = SUMX(FILTER('Table', 'Table'[Year] = Y && 'Table'[Quarter] = Q), 'Table'[Actual Attendance])
    VAR POSSIBLE = SUMX(FILTER('Table', 'Table'[Year] = Y && 'Table'[Quarter] = Q), 'Table'[Possible Attendance])
    RETURN
    DIVIDE(ACTUAL, POSSIBLE)
    Previous Year's quarter attendance % = 
    VAR Y = SELECTEDVALUE(Slicer[Year])
    VAR Q = SELECTEDVALUE(Slicer2[Quarter])
    VAR ACTUAL = SUMX(FILTER('Table', 'Table'[Year] = Y - 1 && 'Table'[Quarter] = Q), 'Table'[Actual Attendance])
    VAR POSSIBLE = SUMX(FILTER('Table', 'Table'[Year] = Y - 1 && 'Table'[Quarter] = Q), 'Table'[Possible Attendance])
    RETURN
    DIVIDE(ACTUAL, POSSIBLE)
    Difference % = [Selected year attendance %] - [Previous Year's quarter attendance %]

    The final output is as below:


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