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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
EL4BI
Frequent Visitor

Rolling Average for count of unique ID by non date

Hello,

 

I want to create a new measure so that I can put in a 3 yr rolling/moving average count on a chart that I have plotted as count of unique ID vs Sale Yr. (see chart).  For example there would be a dot for 3.6 on 2021 that is the average of [3 (2019)+5(2020)+3(2021)]/3 = 3.6

 

Note that the "Sale Yr" is of whole number Data type.  Here is the chart and table.  

 

SaleChart.jpgsales.jpg

 

Thanks

1 ACCEPTED SOLUTION
EL4BI
Frequent Visitor

I figured it out:  It should be: 

 

3YrRollingAvgCT =
VAR Lastyear = Max(Sales[Sale Yr])
VAR PerYr = 2
Var CTSum = CALCULATE(
    counta(Sales[ID #]),
    FILTER(all(Sales),Sales[Sale Yr]>=Lastyear-PerYr && Sales[Sale Yr]<=Lastyear))
RETURN
CTSum/(PerYr+1)

View solution in original post

3 REPLIES 3
MAwwad
Solution Sage
Solution Sage

 

To create a measure for a 3-year rolling average count, you can use the following DAX formula:

 

 
3 Year Rolling Avg Count = VAR SelectedYear = MAX('sales'[Sale Yr]) RETURN AVERAGEX( FILTER( VALUES('sales'[ID]), 'sales'[Sale Yr] >= SelectedYear - 2 && 'sales'[Sale Yr] <= SelectedYear ), CALCULATE(DISTINCTCOUNT('sales'[ID])) )
 

This measure calculates the average count of unique IDs for the selected year and the two previous years.

EL4BI
Frequent Visitor

Thanks for such quick reply.  I get the following error: error.jpg

 

thanks

EL4BI
Frequent Visitor

I figured it out:  It should be: 

 

3YrRollingAvgCT =
VAR Lastyear = Max(Sales[Sale Yr])
VAR PerYr = 2
Var CTSum = CALCULATE(
    counta(Sales[ID #]),
    FILTER(all(Sales),Sales[Sale Yr]>=Lastyear-PerYr && Sales[Sale Yr]<=Lastyear))
RETURN
CTSum/(PerYr+1)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors