Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

View all the Fabric Data Days sessions on demand. View schedule

Reply
minnielahoti
Microsoft Employee
Microsoft Employee

Taking average of last 4 rows in a dataset

I am trying to take the average of the "Total Cores" for the latest 4 weeks. The table on the left shows the date field as numeric, which is what I used in the calculation for creating a Measure to calculate the average. However, it returns the the most recent Core value and not the average of the last 4 week total core values. Can someone please help me figure out my mistake? Thank you!

 

 

minnielahoti_0-1655919120543.png

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @minnielahoti ,

 

According to your statement, I know you want to calcualte the average in the latest 4 weeks. However, you filter from the max [Date_num] and [Date_num]  - 4 (20220617 to 20220613). I think it is incorrect. We only have 20220617 in range, so it returns the the most recent Core value.

Please try my code as below.

4_weeks_Avg = 
VAR _4WEEKEND =
    MAXX ( ALL ( CoresByDate ), 'CoresByDate'[Date] )
VAR _4WEEKSTART = _4WEEKEND - 4 * 7
RETURN
    CALCULATE (
        AVERAGE ( CoresByDate[TotalCores] ),
        FILTER (
            ALL ( CoresByDate ),
            CoresByDate[Date] <= _4WEEKEND
                && CoresByDate[Date] > _4WEEKSTART
        )
    )

Result is as below.

RicoZhou_0-1656298687077.png

 

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.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @minnielahoti ,

 

According to your statement, I know you want to calcualte the average in the latest 4 weeks. However, you filter from the max [Date_num] and [Date_num]  - 4 (20220617 to 20220613). I think it is incorrect. We only have 20220617 in range, so it returns the the most recent Core value.

Please try my code as below.

4_weeks_Avg = 
VAR _4WEEKEND =
    MAXX ( ALL ( CoresByDate ), 'CoresByDate'[Date] )
VAR _4WEEKSTART = _4WEEKEND - 4 * 7
RETURN
    CALCULATE (
        AVERAGE ( CoresByDate[TotalCores] ),
        FILTER (
            ALL ( CoresByDate ),
            CoresByDate[Date] <= _4WEEKEND
                && CoresByDate[Date] > _4WEEKSTART
        )
    )

Result is as below.

RicoZhou_0-1656298687077.png

 

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.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors