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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Boycie92
Resolver I
Resolver I

Distinct Headcount Calculated Column

 

Hi,

 

I was wondering if someone can help me.

 

I am trying to create a calculated column that will count the distinct values of my Person ID column.

To explain my model. CSV Reports are ran every month and dropped into a folder. I have used Power BI to merge all files into one query using the: connect to Folder function.

 

In order to filter the reports by date each file has a date column added to it. For Example Date: 1 November 2016. This appears on every record for that report.

 

I essentially need a formula that will count the distinct headcount for each month. However there may be multiple references of a single person ID in each month. I need the formula to count the first one but ignore the rest.

 

I was able to use this formula for positions and it works. Positions = CALCULATE (DISTINCTCOUNT ('Reports'[Position ID]))

 

However this is because every position has a UNIQUE ID. Is there a way to adapt it in order to deal with duplicated values for Person ID?

 

Thanks,

 

1 ACCEPTED SOLUTION

Hi @v-sihou-msft

 

Thank for your reply.

 

Your solution provides the same result as my Position ID calculation.

 

However this is incorrect. There are more positions than there are people. This is because of employees that have multiple positions.

 

I needed a solution that was flexible enough to identify the duplicate PersonID by labelling the first instance as 1 and then any other entries within that month were marked as 0.

 

I have found a solution that works. However I was wondering why it works? and if the solution can be simplified into less steps.

 

Steps:

 

1) Add index column in Power Query –Unique Row Identifier

 

2) Add Calculated Column in Power Pivot that merged together PersonID and Date:

 

Unique ID = 'Reports'[PersonID] & "-" & 'Reports'[Date].[Date]

 

3) Identified the duplicates of PersonID within each month

 

DupsID = IF(Reports'[Index]=MAXX(FILTER('Reports','Reports'[Unique ID]=EARLIER('Reports'[Unique ID])),'Reports'[Index]),"No","Yes")

 

4) Created calculated column that counts headcount

 

Headcount = CALCULATE(DISTINCTCOUNT('Reports'[PersonID]),'Reports'[DupsID]="No")

 

Thanks for the help,

View solution in original post

2 REPLIES 2
v-sihou-msft
Microsoft Employee
Microsoft Employee

@Boycie92

 

Based on your description, no matter you want to distinct count Person ID or Position ID, you can always use ALLEXCEPT() to make your calculation group on "Month". The formula can be like:

 

= CALCULATE (DISTINCTCOUNT ('Reports'[Position ID]),ALLEXCEPT('Reports','Reports'[Month]))

Regards,

 

Hi @v-sihou-msft

 

Thank for your reply.

 

Your solution provides the same result as my Position ID calculation.

 

However this is incorrect. There are more positions than there are people. This is because of employees that have multiple positions.

 

I needed a solution that was flexible enough to identify the duplicate PersonID by labelling the first instance as 1 and then any other entries within that month were marked as 0.

 

I have found a solution that works. However I was wondering why it works? and if the solution can be simplified into less steps.

 

Steps:

 

1) Add index column in Power Query –Unique Row Identifier

 

2) Add Calculated Column in Power Pivot that merged together PersonID and Date:

 

Unique ID = 'Reports'[PersonID] & "-" & 'Reports'[Date].[Date]

 

3) Identified the duplicates of PersonID within each month

 

DupsID = IF(Reports'[Index]=MAXX(FILTER('Reports','Reports'[Unique ID]=EARLIER('Reports'[Unique ID])),'Reports'[Index]),"No","Yes")

 

4) Created calculated column that counts headcount

 

Headcount = CALCULATE(DISTINCTCOUNT('Reports'[PersonID]),'Reports'[DupsID]="No")

 

Thanks for the help,

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.