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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
dnimand
Regular Visitor

Counting highest number of employees on the same date (distinct count problem)

Hi!

 

Looking for help creating a measure to calculate the highest number of employees at the same time.

My data consists of a table of with employees and information connected to the employee. There is a line for each date for each employee. This is in order to track different employment data regarding employees over time.

I need to calculate the highest number of employees employed at any given date in a time period (year, quarter, month etc.) – at the same time!

I’m trying to use a simple distinct count function on the employee ID, but that counts the total unique employee ID’s in my table and doesn’t take into consideration that employee ID has to be present on the same date.

Also tried using the formula below but it doesn’t work either.

CALCULATE ( DISTINCTCOUNTNOBLANK ('Table'[EMP_KEY]) , GROUPBY (DATES , DATES[DATE] ) )

 

Example of data:

 

Date             EMP_KEY     Distinct count per date (not in table)

01-01-2021  1          

01-01-2021  2          

01-01-2021  3                 3 (01-01-2021)

02-01-2021  3          

02-01-2021  4

02-01-2021  5

02-01-2021  6

02-01-2021  7

02-01-2021  8                 6 (02-01-2021)

03-01-2021  9

03-01-2021  10               2 (03-01-2021)

 

The result I’m looking for in above example is 6 employees (since the highest distinct count is 6 on 02-01-2021), but in my report the result I get is 10 (since there are 10 distinct EMP_KEY’s in the table).

 

Any help is appreciated.

 

 

1 ACCEPTED SOLUTION

Hi

This could be solved in a few ways but I think the simplest is to use the MAXX function, this will loop over all dates in your selection and calculate the unique number of employees per date then return the highest value.

 

Max Number of employees =
MAXX (
    VALUES ( 'Emp'[Date] ),
    CALCULATE (
        DISTINCTCOUNT ( 'Emp'[EMP_KEY] )
    )
)

View solution in original post

2 REPLIES 2

Hi

This could be solved in a few ways but I think the simplest is to use the MAXX function, this will loop over all dates in your selection and calculate the unique number of employees per date then return the highest value.

 

Max Number of employees =
MAXX (
    VALUES ( 'Emp'[Date] ),
    CALCULATE (
        DISTINCTCOUNT ( 'Emp'[EMP_KEY] )
    )
)

THANK YOU! Have been searching all day for a solution.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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