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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
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 Kudoed Authors