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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
machineReadable
Regular Visitor

Having Trouble Creating a Rolling Aggregated Average

I feel like this should be simple, but my brain just isn't working today.

In the image below, I have a pivot table with the Headcount measure (which itself is a Countrows() within a Calculate()) aggregated by the Month-Year field in my date table. The Headcount | Average is a mockup of what I want the result to be, basically a rolling average of all of the months before it (i.e. Feb-19 is the average of 122 and 125, Mar-19 is the average of 122, 125 and 120, etc.), but I can't seem to figure it out.

PBIRolling.PNG

This is my current formula:

=
AVERAGEX ( VALUES ( DimDate[Month-Year] ), [Headcount] )

At this point, wrapping [Headcount] in a Calculate() does nothing. The formula works in the grand total row, but in each month row I just get the same value as Headcount, so I'm pretty sure it's about removing the row context somehow, But my attempts so far have been unsuccessful. Note that the Headcount measure is a rollup of unique 'heads' that may exist in multiple aggregations, so I can't do a simple sum and divide by the number of months.

Thanks!

3 REPLIES 3
RudyL
Helper I
Helper I

Hi,

I suppose you have a table with a column for NAMES and for a MONTH. Let's call that table PEOPLE.
You probably have Headcount = CALCULATE(count(People[NAMES])) which will return the number of names per month.

Now try to make measure .... (this will count the running total for all headcount up till a certain month)

RunTotHeadcount = calculate(
count(People[NAMES]);
filter(
ALL(People);
People[month]<=max(People[month])
)
)
 
and measure.... (this will return a running total of months passed)
 
RunTotMonth = calculate(
DISTINCTCOUNT(People[month]);
filter(
ALL(People);
People[month]<=max(People[month])
)
)
 
And finally this will add up to the measure with the answer you need:
avgHeadcountYTD = [RunTotHeadcount]/[RunTotMonth]

Maybe there is an average function that does all this in one step, but I like to break it down 🙂

Stachu
Community Champion
Community Champion

Can you add sample tables (in format that can be copied to PowerBI) from your model with anonymised data? Like this (just copy and paste into the post window).

Column1Column2
A1
B2.5

Also, what is the syntax for [Headcount]?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Headcount = COUNTROWS ( SUMMARIZE ( FactEmployment, FactEmployment[Employee Key] ) )

FactEmployment is a factless fact table that has a row for each employee, for each date they have been employed, and the role they are in, team they are on, etc. This way in my pivot table, I can group the headcount by those dimensions, and it reacts to any date range I select.

In this case I'm just doing a simple count, but using a table like this has been helpful in the past to create measures and use the entire table as a filter in the measure, although it is very resource intensive, so I'm looking for alternatives.

PBIRolling0.PNG

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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