Forum Discussion

iansimpson888's avatar
iansimpson888
Regular Visitor
3 years ago
Solved

creating a rolling average

Hi, i have a table displaying the weekly average attendance of a student:

 

 

It is calculated using a 'rolling' average, so:

week 1 actual (05/09/2022) = 100%

week 1 rolling (05/09/2022) = 100%

week 2 actual (12/09/2022) = 90%

week 2 rolling (12/09/2022) = 95% (100+90 = 190, /2  = 95%)

week 3 actual (19/09/2022) = 100%

week 3 rolling (19/09/2022) = 96.67% (100+90+100= 290, /3  = 96.67%)

 

The DAX for this measure is:

 

Weekly % Attendance (Rolling) =

AVERAGEX(

    FILTER( ALLSELECTED( 'powerbi_attendance_weekly_average' ),

        'powerbi_attendance_weekly_average'[Mark Date (Weeks DD/MM/YY)] <= MAX (powerbi_attendance_weekly_average[Mark Date (Weeks DD/MM/YY)])),            'powerbi_attendance_weekly_average'[Weekly % Attendance])

 

This seems to work fine in a PBI table when the table is filtered to a single student, as above, but when I try to display multiple students, this is the result:

 

 

I suspect the value is a combined value for all students. These are fictitious names, I should add.

Hope somebody can give me some pointers with this, many thanks

 

 

 

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi iansimpson888 ,

     

    I suggest you to try ALL() and add [Full Name] column into filter code part.

    Weekly % Attendance (Rolling) =
    AVERAGEX (
        FILTER (
            ALL ( 'powerbi_attendance_weekly_average' ),
            'powerbi_attendance_weekly_average'[Mark Date (Weeks DD/MM/YY)]
                <= MAX ( powerbi_attendance_weekly_average[Mark Date (Weeks DD/MM/YY)] )
                && 'powerbi_attendance_weekly_average'[Full Name]
                    = MAX ( 'powerbi_attendance_weekly_average'[Full Name] )
        ),
        'powerbi_attendance_weekly_average'[Weekly % Attendance]
    )

     

    Best Regards,
    Rico Zhou

     

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

     

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi iansimpson888 ,

     

    I suggest you to try ALL() and add [Full Name] column into filter code part.

    Weekly % Attendance (Rolling) =
    AVERAGEX (
        FILTER (
            ALL ( 'powerbi_attendance_weekly_average' ),
            'powerbi_attendance_weekly_average'[Mark Date (Weeks DD/MM/YY)]
                <= MAX ( powerbi_attendance_weekly_average[Mark Date (Weeks DD/MM/YY)] )
                && 'powerbi_attendance_weekly_average'[Full Name]
                    = MAX ( 'powerbi_attendance_weekly_average'[Full Name] )
        ),
        'powerbi_attendance_weekly_average'[Weekly % Attendance]
    )

     

    Best Regards,
    Rico Zhou

     

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