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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to do distinct employee count by distinct ID

I have 2 formulas that make up this chart:

1.PNG

 

And they are:
1.PNG
1.PNG

The 'Employee Range Size' is being used as the Legend and the values are a distinct count on the company ID. I also have this same information separated into tables such as:

1.PNG

So the 124 is doing a distinct count on the company ID which is what I want. My issue is the Employee Count column. My total at the bottom for that column is a bit skewed because as you can see for company ID 0340, it is listed twice because it has a payroll service and a cbiz ems service, so instead of just counting 214 once, it is doubling it to 428. How can I set this up to only count 214 one time? For whatever reason when I remove the 'Service' Column from the table, the grand total goes up almost 20,000 for some reason I don't understand, so that is not the solution. If there is a better way to set all of this up, I am open to any suggestions Smiley Happy.

4 REPLIES 4
v-xjiin-msft
Solution Sage
Solution Sage

@Anonymous

 

In your scenario, there exists duplicated Employee Count for each Company ID because of the Service. When you put Employee Count field in the Values of a Pie Chart, the duplicated has been summed automatically. And you don’t want the duplicated be summed. Right?

 

First, your expressions for Employee Counts and Employee Range Size are both right. The reason for your issue is that charts cannot distinguish if the values are duplicated. By default it will sum them all automatically. To modify this, you just need to change the aggregate function for Employee Count from Sum to Max.

 

1111.png2222.png

Thanks,
Xi Jin.

Anonymous
Not applicable

Mine doesn't look like it's set up the same way. My 'Employee Counts' is a measure I created specifically for counting the number of times an employee id appears for a company id. I do not have the option to change this to Maximum. On my chart My Legend is "Employee Range Size" and I'm just using a distinct count on the company ID as my values to capture how many companies fall within each range. Here are the pieces:

1.PNG

 

Then for the corresponding tables, these are the attached pieces:
1.PNG

 

So the 'Employee Count' column you see on each table is just the ID field from the Employees table and is doing a Count on that column:

1.PNG

 

And I have filters on each table referencing my 'Employee Counts' measure I created so it returns the same values represented on my graph:

1.PNG

1.PNG

Greg_Deckler
Super User
Super User

You have a classic "My Measure Total is Wrong" situation:

 

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you smoupre! However, I am still unsure of how to apply that logic to my situation. Is there any way to have the table read all the company ID's within that table and count the Employee Count for the given Company ID just once?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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