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
robstewart89
Advocate IV
Advocate IV

Measure for calculating colleague leavers vs. no. of employees

Hi,

 

I have a table of everyone in our company currently combined with the everyone who has left the company since Jan-2015. The two relevant columns i'm working with are joining date (for all existing and leavers) and a leaving date (only for leavers).

 

I basically need to find out the percentage of people who left the company by month. So leavers in Jan-2015 vs total employees in Jan-2015 and so on. I obviously have the leavers by month but i'm finding difficulty a) finding the total employees per month and b) being able to drill down by month, type of employee,region etc.

 

I was able to use the CALCULATE function to calculate how many employees were there per month but this was more of a manual measure by month:

 

2015-01 = CALCULATE(COUNTA(Sheet1[JoiningMonth]),Sheet1[JoiningMonth]<="2015-01")-CALCULATE(COUNTA(Sheet1[LeavingMonth]),Sheet1[LeavingMonth]<="2015-01",Sheet1[LeavingMonth]>"0")

 

Do i need to create some calculated columns/additional measures to make this work?

 

Any help/thoughts appreciated.

 

Thanks,

8 REPLIES 8
Greg_Deckler
Super User
Super User

@robstewart89 - Can you post some sample data?


@ 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...

@Greg_Deckler the table below shows an example of my data.

 

Person Ref	JoiningMonth	LeavingMonth
1001	          2005-02	
1002	          2008-01	  2015-01
1003	          2016-02	
1004	          2004-03	
1005	          2007-01	
1006	          2013-08	  2015-01
1007	          2015-11	  2016-03
1008	          2014-09	  2015-04
1009	          1997-06	  2015-05
1010	          1975-06	  2015-12

 

So in this example there would be:

 

2 leavers in "Jan-2015",

4 people who joined before Jan-2015 and are still here 

3 people who left after Jan-2015

1 person (1007) who joined and left after Jan-2015.

 

So this would be 2 leavers / 7 existing in Jan 2015 = turnover of 28.5%

 

And then replicate that for all months thereafter Smiley Surprised

 

 

I bet i'm overlooking something really simple here but i've been round the houses with it!

 

Thanks,

Robert

 

 

Anonymous
Not applicable

Create another column:

 

eg. LeavingMonthMark = IF(LeavingMonth <> 0 , 1 , 0)

 

Then create a measure:

 

eg. YourPreferredMeasureName = DIVIDE(SUM(LeavingMonthMark) , COUNTROWS(TableName))

 

Put this in a visualization and it should work with any given month.

@Anonymous that's great, it gives me an overall % but as i have two differing date columns (joining and leaving) the only way i can see to get the % figure for February 2015 for example, is to filter joining month on February 2015 or before and the leaving month after Feb 2015. 

 

Unless there is a way to achieve this through a measure?

Anonymous
Not applicable

The best approach might be to build yourself a date table (as you're only concerned with months then a row per month would do instead) and then make use of these DAX Patterns.

 

The method we usually use to get the number of current employees would be to build a sum joining to date and a sum of leaving to date and then subtract the two (ammend the year to date pattern so that it's not limited to summing over the current year).

I suspect there's a more elegant way of doing it in a single DAX query, this is adapting from how we've done the same in MDX in our cubes.

I had looked into creating a date table (with just months as you said) and creating a relationship between that and my Master table. The problem I found was that as I have two date columns (joining and leaving) I couldn't link the date table to both columns - unless i'm missing some obvious workaround!

 

Thanks for the link on DAX Patterns Barney!

Anonymous
Not applicable

 


@robstewart89 wrote:

I had looked into creating a date table (with just months as you said) and creating a relationship between that and my Master table. The problem I found was that as I have two date columns (joining and leaving) I couldn't link the date table to both columns - unless i'm missing some obvious workaround!

 

Thanks for the link on DAX Patterns Barney!


A good point about the multiple dates. In the case of there being two date columns in Power BI you'll need two copies of your date table, one to join to each column.

 

I tend to forget about these things because I'm more used to Analysis Services Multidimensional where you can join the same table multiple times under different aliases. Sadly that doesn't exist yet for Power BI\Tabular Models to my knowledge.

I think this is an example of a Slowly Changing Dimension.  Have you read through this blog post?

 

Slowly Changing Dimension

 

I

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.