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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Cumulative Average Months from join date

Hi,

I need to get the average numbers of month from Report date based on selected date filter.

EmployeeReport date
Emp11/1/2020
Emp21/1/2020
Emp32/1/2020
Emp43/1/2020
Emp54/1/2020


Now what i need is to get the datediff from report date vs date on the slicer and then average it.

 

For example, i filter Feb2020:

Headcount is 3, but my average month is 1.33 - because month diff from Feb2020 of Emp1 and Emp2 is both 2, while Emp3 is 0.
Average of 2,2,0 is 1.33

 

Now if i filter date to Apr2020:

Headcount is 5, then my average month is 2.22 - because month diff from Apr2020 of Emp1 and Emp2 is both 4, Emp3 is 2, Emp4 is 1, and Emp5 is 0.
Average of 4,4,2,1,0 is 2.22

 

Here's the output im trying to get

Headcount YTD234555
Cumulative Ave month11.331.752.23.24.2
MonthJan-20Feb-20Mar-20Apr-20May-20Jun-20
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi @Anonymous ,

Actually I‘m a little confused about your issue...
What does Headcount mean? Is the 4 you described in this "because month diff from Apr2020 of Emp1 and Emp2 is both 4" maybe 3= 2020/4 -2020/1 ?
If you want to cumulative Average Months , you could create measure(diff) about Month interval, then use divide calculate average. the following formula to create a measure :

step 1: Add Measure (diff )

diff =
VAR _maxdate =
    CALCULATE ( MAX ( [Report date] ), ALLSELECTED ( 'Date' ) )
RETURN
    DATEDIFF ( MAX ( 'Date'[Report date] ), _maxdate, MONTH )

v-yalanwu-msft_2-1618304836609.png

 

step 2: Add measure(Average )

Average = DIVIDE(SUMX('Date',[diff]),COUNTROWS('Date'))


The final output is shown below:

v-yalanwu-msft_0-1618304819409.pngv-yalanwu-msft_1-1618304825873.png

 

 


Or could you please share more detail information to help us clarify your scenario?

Best Regards,
Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi @Anonymous ,

Actually I‘m a little confused about your issue...
What does Headcount mean? Is the 4 you described in this "because month diff from Apr2020 of Emp1 and Emp2 is both 4" maybe 3= 2020/4 -2020/1 ?
If you want to cumulative Average Months , you could create measure(diff) about Month interval, then use divide calculate average. the following formula to create a measure :

step 1: Add Measure (diff )

diff =
VAR _maxdate =
    CALCULATE ( MAX ( [Report date] ), ALLSELECTED ( 'Date' ) )
RETURN
    DATEDIFF ( MAX ( 'Date'[Report date] ), _maxdate, MONTH )

v-yalanwu-msft_2-1618304836609.png

 

step 2: Add measure(Average )

Average = DIVIDE(SUMX('Date',[diff]),COUNTROWS('Date'))


The final output is shown below:

v-yalanwu-msft_0-1618304819409.pngv-yalanwu-msft_1-1618304825873.png

 

 


Or could you please share more detail information to help us clarify your scenario?

Best Regards,
Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Amazing! this is the one. Sorry to confuse you, but you got it! 🙂


Is there a way to use this solution in a trend visual, like bar chart?

amitchandak
Super User
Super User

@Anonymous , Try a measure like

divide(sumx(values(table[employee]), datediff( eomonth(maxx(date[date]),-1)+1,min([Report date]), day)), count(Table[Employee]))

 

or with a selected date

measure =
var _max = maxx(allselected(Date), Date[Date]) //slicer date
return
divide(sumx(table, datediff([Report date], _max, day)), count(Table[Employee]))

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
Anonymous
Not applicable

thanks for quick help.

However the result seems decreasing and the value is too high.
image1.PNG

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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