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
PeteDTG
Frequent Visitor

DAX - Average of a Distinct Count

Hello,

 

Looking for some help with a DAX formula.  If you see the image below I am taking the distinct count of the employee_code field to obtain the number of employees per month.  However, I also need to show the last trailing 12 months as an average of the distinct counts.  How would I go about doing this in DAX? 

 

I can get a distinct count for the last 12 months using the formula below, but it needs to be an average and not a count.

 

Head Count LTM = CALCULATE(DISTINCTCOUNT(PaycomHours[Employee_Code]),DATESINPERIOD ('edw dimDate'[Date],MAX ( 'edw dimDate'[Date]),-12,MONTH))

 

Thank you!!

PeteDTG_1-1629325871886.png

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@PeteDTG , Try a measure like

 

CALCULATE(averageX(values('edw dimDate'[month year]), calculate(DISTINCTCOUNT(PaycomHours[Employee_Code]))),DATESINPERIOD ('edw dimDate'[Date],MAX ( 'edw dimDate'[Date]),-12,MONTH))

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

View solution in original post

community_pinki
Helper II
Helper II

Hey @PeteDTG ,


Please try using this :-

 

Avg of Head Count LTM = CALCULATE(AVERAGEX(PaycomHours,DISTINCTCOUNT(PaycomHours[Employee_Code])),DATESINPERIOD
('edw dimDate'[Date],MAX ( 'edw dimDate'[Date]),-12,MONTH))

View solution in original post

4 REPLIES 4
community_pinki
Helper II
Helper II

Hey @PeteDTG ,


Please try using this :-

 

Avg of Head Count LTM = CALCULATE(AVERAGEX(PaycomHours,DISTINCTCOUNT(PaycomHours[Employee_Code])),DATESINPERIOD
('edw dimDate'[Date],MAX ( 'edw dimDate'[Date]),-12,MONTH))

You are awesome, thank you so much! Didn't think to use AVERAGEX! 🙂 

amitchandak
Super User
Super User

@PeteDTG , Try a measure like

 

CALCULATE(averageX(values('edw dimDate'[month year]), calculate(DISTINCTCOUNT(PaycomHours[Employee_Code]))),DATESINPERIOD ('edw dimDate'[Date],MAX ( 'edw dimDate'[Date]),-12,MONTH))

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

Thank you so much!! 😁

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.