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

Count related table values

Hello,

Recently I've been working on HR dashboard and I am having a problem. I have 2 tables: 'Headcount' and 'Leavers' (related by ID number) + 'Calendar' table. 'Headcount' table contains all reports of subsequent months and is related to 'Calendar' by "Reporting Period". In 'Leavers' table I have "Leave Period" column. I need to count number of employees who left the company. It'd be easy if I could filter for people which Headcount[Reporting Period] = Leavers[Leave Period], problem is that if certain person's last day worked was at last day of month, we count that this employee left company in the following month. This results in fact that this person won't be appearing in 'Headcount' table anymore, so last reporting period will always be smaller than leave period and I can't find proper solution on my own here. How can I count number of leavers so the amount is both in compliance with Date filters and maintain all dependencies from Headcount table (for exmaple filtering visualizations by team, gender, manager name etc.). Currently I've tried adding relation between Calendar[Date] and Leavers[Leave Period], but as already mentioned I am losing all other filter dependencies besides correctly working date. Anyone could help me here?

JLip_1-1651592998190.png

JLip_2-1651593696785.png

 

 

1 ACCEPTED SOLUTION

@amitchandak Thanks for your answer. This measure is not exactly what I've been looking for. 

Meanwhile I've came with my own solution. I've created calculated column in table 'Headcount'.

Leave Period =
IF(Headcount[Last Day Worked] = EOMONTH(Headcount[Last Day Worked],0),EOMONTH(Headcount[Last Day Worked],1),EOMONTH(Headcount[Last Day Worked],0))

And then used a measure:
Leavers =IF(ISBLANK(CALCULATE(DISTINCTCOUNT(Headcount[ROKID],USERELATIONSHIP('Calendar'[Date],
Headcount[Leave Period]))),0,CALCULATE(DISTINCTCOUNT(Headcount[ROKID]),USERELATIONSHIP('Calendar'[Date],Headcount[Leave Period])))

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@JLip , Try a measure like

Cumm Sales = CALCULATE(Count(Headcount[Emolyeee]),filter(allselected(date),date[date] <=max(date[Date]))) -CALCULATE(Count(leavers[Emolyeee]),filter(allselected(date),date[date] <=max(date[Date])))

@amitchandak Thanks for your answer. This measure is not exactly what I've been looking for. 

Meanwhile I've came with my own solution. I've created calculated column in table 'Headcount'.

Leave Period =
IF(Headcount[Last Day Worked] = EOMONTH(Headcount[Last Day Worked],0),EOMONTH(Headcount[Last Day Worked],1),EOMONTH(Headcount[Last Day Worked],0))

And then used a measure:
Leavers =IF(ISBLANK(CALCULATE(DISTINCTCOUNT(Headcount[ROKID],USERELATIONSHIP('Calendar'[Date],
Headcount[Leave Period]))),0,CALCULATE(DISTINCTCOUNT(Headcount[ROKID]),USERELATIONSHIP('Calendar'[Date],Headcount[Leave Period])))

@JLip , Kudos to you. 2 from my side. 😀

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.