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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Jrose
Frequent Visitor

Rolling average for only one group

Hi,

I've looked through many similar posts and can't quite get to what I need.

So far there is a calculated column to convert the year to a numeric year

Year4 = value(right(Table_1[Year],4))

 

Then a measure that calculates a three year moving average

m3YrAvg =
CALCULATE(
AVERAGEX(

SUMMARIZE('Table_1','Table_1'[Year4],"Tot_AY_Ct", CALCULATE(COUNT('Table_1'[person_id])))
,[Tot_AY_Ct]),
FILTER(ALL('Table_1'[Year4]),
'Table_1'[Year4] <= MAX('Table_1'[Year4]) &&
'Table_1'[Year4] > (MAX('Table_1'[Year4])-3)
)
)

 

This works fine, but I would like it to work for only Group A.  I can use the filter pane, but it seems cumbersome on some visuals and I would rather it be filtered at the calculation.  I've tried adding it in the FILTER statement, but can't get it to work without error.  Haven't used DAX much, so just can't seem to come up with the right placement or syntax I guess.

Any suggestion is appreciated.

 

Jrose_0-1628188992858.png

 

2 REPLIES 2
amitchandak
Super User
Super User

@Jrose , Try with help from two measures

 

Avg1= AVERAGEX( values('Table_1'[Year4]), CALCULATE(COUNT('Table_1'[person_id])))


m3YrAvg =calculate([Avg1],
FILTER(ALL('Table_1'[Year4]),
'Table_1'[Year4] <= MAX('Table_1'[Year4]) &&
'Table_1'[Year4] > (MAX('Table_1'[Year4])-3) && 'Table_1'[group] = MAX('Table_1'[group])
) )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks for the suggestion.  Unfortunately, it's not working.

The first calculation for average is giving numbers way too low and I can't tell what it is trying to average across. 

 

I tried the second calculation anyway, and it won't recognize the table columns.  The list that pops up as I enter the table name only shows the calculated fields and measures.  I typed it anyway and get an error that says "A single value for column "group" cannot be determined.  I used MAX to see if it would at least clear the error, which it didn't, but it doesn't make sense in this context anyway  I need to be able to say something like

where group = "A".

 

The original calculation I have works, I would just like to be able to add what is in the filter pane to the calculation instead as I anticipate needing it for other metrics in the future.

I guess I'm not understanding why it insists on an aggregate rather than being able to filter (select) only records of a certain value.  And why in this calculation it doesn't want to recognize regular data columns.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.