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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.