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

Average headcount for a given period

Hi Everyone,

 

I'm new to Power BI and DAX and was hoping to get some direction on this. I did some searching but was unable to find any solutions.

 

The goal is to be able to calculate the average headcount over any given period (month, week, year, etc). Here is the raw data I'm starting with, it tracks changes to an employees records. As you can see, Termination date is joined across all rows for a record.

 

Employment Record ID      Effective Date     Termination Date
a0N0Y00000AlUIP8/13/20188/17/2018
a0N0Y00000AQMfY8/3/20156/30/2016
a0N0Y00000AQMhr9/1/20165/2/2019
a0N0Y00000AQMhr6/1/20175/2/2019
a0N0Y00000AQMhr6/15/20175/2/2019
a0N0Y00000AQMhr6/1/20185/2/2019
a0N0Y00000AQMhz11/1/20166/2/2017
a0N0Y00000AQMi35/15/20175/30/2019
a0N0Y00000AQMi36/19/20175/30/2019
a0N0Y00000AQMi36/1/20185/30/2019
a0N0Y00000AQMiC10/23/201711/2/2018
a0N0Y00000AQMiF12/4/2017 
a0N0Y00000AQMiF6/1/2018 
a0N0Y00000AQMyT8/6/2018 
a0N0Y00000AQMyT8/24/2018 
a0N0Y00000AQMyT3/1/2019 
a0N0Y00000AQMyT10/1/2019 

 

To help facilitate my goal, I've grouped the rows by ID, created an Index column, and used it to create an end date for each row. Here is what the data looks like now:

 

Employment Record ID     Group.Effective Date     End Date
a0N0Y00000AlUIP8/13/20188/17/2018
a0N0Y00000AQMfY8/3/20156/30/2016
a0N0Y00000AQMhr9/1/20165/31/2017
a0N0Y00000AQMhr6/1/20176/14/2017
a0N0Y00000AQMhr6/15/20175/31/2018
a0N0Y00000AQMhr6/1/20185/2/2019
a0N0Y00000AQMhz11/1/20166/2/2017
a0N0Y00000AQMi35/15/20176/18/2017
a0N0Y00000AQMi36/19/20175/31/2018
a0N0Y00000AQMi36/1/20185/30/2019
a0N0Y00000AQMiC10/23/201711/2/2018
a0N0Y00000AQMiF12/4/20175/31/2018
a0N0Y00000AQMiF6/1/201810/20/2020
a0N0Y00000AQMyT8/6/20188/23/2018
a0N0Y00000AQMyT8/24/20182/28/2019
a0N0Y00000AQMyT3/1/20199/30/2019
a0N0Y00000AQMyT10/1/201910/20/2020

 

I've also created a date table with the neccessary periods that is dynamically limited to the date ranges I want available.

 

I was able to find and manipulate a suggestion that accurately gives me the total headcount in any period;

 

 

 

 

 

 

 

Total Headcount = 
CALCULATE( COUNTROWS( DISTINCT(JobHistoryReport[Employment Record ID]) ),
    FILTER( VALUES( JobHistoryReport[Group.Effective Date] ), JobHistoryReport[Group.Effective Date] <= MAX( 'Date'[Date] ) ),
    FILTER( VALUES( JobHistoryReport[End Date] ), OR( JobHistoryReport[End Date] >=MIN( 'Date'[Date] ), ISBLANK( JobHistoryReport[End Date] ) ) ) ) 

 

 

 

 

 

 

 

However, I have been unsucessful at crafting/finding a formula that would give me the average headcount for any period  (use of sumx maybe?). Here is an example of desired output;

 

Employment Record ID     Group.Effective Date     End Date
a0N0Y00000AQMhr6/1/20176/14/2017
a0N0Y00000AQMi35/15/20176/18/2017

 

Given just the two rows above, my average headcount for June 2017 would be;

 

Period            Average Headcount
June 20171.07

 

14 (from row 1) + 18 (from row 2) / 30 (days in the period) = 1.07 Average Headcount.

 

Any help would be appreciated, thank you all!

1 ACCEPTED SOLUTION

Hi Paul,

I appreciate the reply!

 

While I have found -a- solution to this issue, I wouldn't mind a better one. 🙂 This solution is "imperfect" because it relies on creating what is potentially millions of record rows. However, it does provide accurate and easy to manage calculations.

 

To summerize the issue:

 

I have a set of data that includes these relevant fields: Start Date, End Date and ID

 

Quamie_0-1603857696683.png

 

I'm attempting to count average headcount over any given period. My results might look like;

 

Quamie_2-1603858172384.png

 

 

The proper way to calculate this would be the forumula below:

 

Sum number of days each record was active in a period / Number of days in the period

                                                                    

         

 

Here is an Example: Given only the below table, If I wanted to calculate the average headcount in June 2018, I would get 2.3

 

Quamie_1-1603858030701.png

 

12+16+12+23+5 = 68

 

68/29  = 2.3

 

Where 29 is the number of days in the month of June 2018.

 

------------------------------

 

Here is my current imperfect solution:

 

- Create unique rows for every date a record is active and expand the table.

 

Quamie_3-1603858475554.png

 

- Create an Active relationship between this table and a date table

 

Quamie_4-1603858706536.png

 

From here, it is a simple measure to create a table which calculates your average headcount:

 

Quamie_5-1603858915571.png

 

 

 

 

Average Headcount = COUNTROWS(Query2) / COUNTROWS('Date')

 

 

I only ultimately worry about the number of rows this creates. I don't have a lot of experience with the platform, so I'm not sure whether its going to be able to handle a number like 10 million rows, I may have to limit my date ranges to ~2-3 years to compensate

 

Thanks for everyone's time. 🙂

 

View solution in original post

3 REPLIES 3
V-pazhen-msft
Community Support
Community Support

@Quamie 

It is difficult for us to follow your post with those information throw to us partly. Can you put those samples in a pbix, and post a question with the sample pbix file.

 

Regards
Paul

Hi Paul,

I appreciate the reply!

 

While I have found -a- solution to this issue, I wouldn't mind a better one. 🙂 This solution is "imperfect" because it relies on creating what is potentially millions of record rows. However, it does provide accurate and easy to manage calculations.

 

To summerize the issue:

 

I have a set of data that includes these relevant fields: Start Date, End Date and ID

 

Quamie_0-1603857696683.png

 

I'm attempting to count average headcount over any given period. My results might look like;

 

Quamie_2-1603858172384.png

 

 

The proper way to calculate this would be the forumula below:

 

Sum number of days each record was active in a period / Number of days in the period

                                                                    

         

 

Here is an Example: Given only the below table, If I wanted to calculate the average headcount in June 2018, I would get 2.3

 

Quamie_1-1603858030701.png

 

12+16+12+23+5 = 68

 

68/29  = 2.3

 

Where 29 is the number of days in the month of June 2018.

 

------------------------------

 

Here is my current imperfect solution:

 

- Create unique rows for every date a record is active and expand the table.

 

Quamie_3-1603858475554.png

 

- Create an Active relationship between this table and a date table

 

Quamie_4-1603858706536.png

 

From here, it is a simple measure to create a table which calculates your average headcount:

 

Quamie_5-1603858915571.png

 

 

 

 

Average Headcount = COUNTROWS(Query2) / COUNTROWS('Date')

 

 

I only ultimately worry about the number of rows this creates. I don't have a lot of experience with the platform, so I'm not sure whether its going to be able to handle a number like 10 million rows, I may have to limit my date ranges to ~2-3 years to compensate

 

Thanks for everyone's time. 🙂

 

Quamie
Frequent Visitor

🙂 Bump for any assistance.

 

I was trying out some different approaches. I was able to create an additional measure on the table itself that accurately counted the number of days in the period when a date range is selected, however the total for that measure is not correct. It may lead me to be able to calculate the average for a period when that period is selected.

 

Quamie_0-1603417378792.png

 

 

Alas, that would not yield me what I'm ultimately looking for, which are tables/charts broken down by period (month, year, week, etc) with the average count.

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.