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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
EllePi
New Member

Count rehired employees

Hi there,

i'm strugling with this problem:

i have a table with "CF employees", "hiring date", "termination date"

CF employeeshiring datetermination date
rrrrr01/01/201931/12/2020
wwww

01/01/2020

 
ttttt01/02/202231/03/2022
ttttt01/03/2023 
zzzzz01/11/2023 

i've created wih DAX some new measures:

"Hired Employees" = CALCULATE(COUNT(TURNOVER[CF]),USERELATIONSHIP(TURNOVER[HIRINGdata],'Calendar'[Date]) )

"TerminetedEmployees"  =  CALCULATE(COUNT(TURNOVER[CF]),USERELATIONSHIP(TURNOVER[TERMdate],'Calendar'[Date]),not(ISBLANK(TURNOVER[TERMdate])))

both measure counts in the right way all hired and terminated employees

the i have a grafic with the result of the 2 measures, and i'm able to filter the graphic by YEAR of hiring and termination havig the right number for the filtered year.

 


Now i need a new measure: i need to count how many employees has been REHIRED, that new measure has to be sensible to the hiring YEAR filter of the graphic; 

i'm only able to count all employees rehierd but that number is the total count and not sensible to the YEAR filter of the graphic.

"Rehired" = CALCULATE(COUNTROWS(TURNOVER), ALLEXCEPT(TURNOVER, TURNOVER[CF]), FILTER(VALUES(TURNOVER[CF]),

        CALCULATE(COUNTROWS(TURNOVER), ALLEXCEPT(TURNOVER, TURNOVER[CF]),TURNOVER[CF] = EARLIER(TURNOVER[CF]))>1))

the result of that one is the total count of all rehired employees although I've filtered the hiring year in the graphic;

 

if i filter by year in the graphic:
- i have the correct count of Hired for that year (correct)
- i have the correct count of Terminated for thar year (correct)
- i have the the all count of the Rehired of all the years (uncorrect)


Thanks for any tip to find a simple solution, i know it's simple but i'm not so skilles in dax!

1 ACCEPTED SOLUTION
speedramps
Super User
Super User

Try this ...

Click here to download PBIX from OneDrive 

 

How it works ...

 

Create a calanader table with Year column and data relationship to your fact table

speedramps_0-1706712425612.png

 

Create measure to detemine is row is a rehire

Rehire = 
var mydate = SELECTEDVALUE(yourdata[hiring date])
var myemployee= SELECTEDVALUE(yourdata[CF employees])
RETURN
CALCULATE(
    INT(NOT(ISEMPTY(yourdata))),
    ALL(),
    yourdata[CF employees] = myemployee,
    yourdata[hiring date] < mydate
)

 

speedramps_1-1706712509285.png

 

The wrap the measure in a SUMX so you can get the rehired total for a year

Rehired = 
SUMX(VALUES(yourdata[CF employees]),[Rehire])

 

speedramps_2-1706712583920.png

Thanks for the clear description of the problem with example data. I wish everyone did that!

Remember we are unpaid volunteers, and you have got free expert help which took a lot of effort,
This solution works and does exactly what you asked.
So please quickly click the [accept as solution] and the thumbs up button to leave kudos. 

One question per ticket please. If you need to change or extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 

If you quote @speedramps in your next tickets then I will then receive an automatic notification, and will be delighted to help you again.

Please now click the [accept as solution] and the thumbs up button.  Thank you.

View solution in original post

3 REPLIES 3
speedramps
Super User
Super User

Try this ...

Click here to download PBIX from OneDrive 

 

How it works ...

 

Create a calanader table with Year column and data relationship to your fact table

speedramps_0-1706712425612.png

 

Create measure to detemine is row is a rehire

Rehire = 
var mydate = SELECTEDVALUE(yourdata[hiring date])
var myemployee= SELECTEDVALUE(yourdata[CF employees])
RETURN
CALCULATE(
    INT(NOT(ISEMPTY(yourdata))),
    ALL(),
    yourdata[CF employees] = myemployee,
    yourdata[hiring date] < mydate
)

 

speedramps_1-1706712509285.png

 

The wrap the measure in a SUMX so you can get the rehired total for a year

Rehired = 
SUMX(VALUES(yourdata[CF employees]),[Rehire])

 

speedramps_2-1706712583920.png

Thanks for the clear description of the problem with example data. I wish everyone did that!

Remember we are unpaid volunteers, and you have got free expert help which took a lot of effort,
This solution works and does exactly what you asked.
So please quickly click the [accept as solution] and the thumbs up button to leave kudos. 

One question per ticket please. If you need to change or extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 

If you quote @speedramps in your next tickets then I will then receive an automatic notification, and will be delighted to help you again.

Please now click the [accept as solution] and the thumbs up button.  Thank you.

amustafa
Super User
Super User

Based on your sample dataset, do you consider new hire if the hiring date is greater than termination date? what is the rule to identify new hire?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks amustafa,

my data set it really simple:

HIRED ->  i count every hired employees, i filter the year in the graphic and the result is the number of hired in that year considering the hiring date; for this measure it's not important if the employess has got a termination date

TERMINATED -> i count every terminated employees, i filter the year in the graphic and the result is the number of terminated in that year considering if term date in not blank

 

now i'm trying to have as result the employees "duplicated": they've 2 o more hiring date and 2 or more termination date; i'd to filter the graphic by date and have in return the number of rehired employees in that year.

 

Hope i've been able to explain in the right way.
Thanks

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.