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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register 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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.