Forum Discussion

lozg's avatar
lozg
Regular Visitor
4 years ago
Solved

Visualisations with slicers determined by specific date range - active employees

Hi there,

I'm a pretty advanced Excel user, though very new to Power BI.
I've got some employee data and am trying to create an admin user overview dashboard to show the number of joiners, leavers, and currently active employees.

I've put a table, with an example of the raw data, below - which is updated each month (new hires added to the list and termination dates included for people who have left).

I've started creating the basic dashboard layout (see screenshot below).

All is ok, so far, however, I can't get things to work correcytly for the date ranges defined in the Date Slicer.

What I'm trying to achieve is to have the data update by any date range specificed to consider:

Card 1: Active Employees (Headcount) = Anyone with a hire date prior to the end of the date range specified in the Date slicer, less anyone who has a termination date prior to the start date of that same date range (this may be different from the 'Employee Status' column in the raw data, as that is just the static position today).

Card 2: Terminations In Period = Anyone who has a termination date in the date range specified in the Date slicer. 

Card 3: Terminations Year To Date = Anyone who has a termination date in the current year (using TODAY() to define the year).
Card 4: Terminations In Prior 12 Months = Anyone who has a termination date in the 12 months priod to today. 
Card 5: Joiners In Period = Anyone who has a hire date in the date range specified in the Date slicer.
Card 6 = Joiners Year To Date = Anyone who has a hire date in the current year (using TODAY() to define the year).
Card 7 = Joiners In Prior 12 Months = Anyone who has a hire date in the 12 months prior to today.

At the same time, I want the other slicers (Company, Gender, Country and Department) to work with Date slicer.

In summary, I would like the Date slicer to be the master filter - if a specific date range is specified, then all other filters apply to these dates and if no specific date filter is applied then it's all time.

I've spent about 6 hours yesterday looking at various different forum posts (many of them on here) and YouTube videos.
I've managed to take a few handy scripts and adapt them to perform part of the solution - however, I can't get the right measure to correctly filter the data as above.
I've got a Calendar with all the dates from the earliest to the latest date, for referencing. I just can't find the right combination of CALCULATE and DISTINCTCOUNT to make the above cards work correctly.

I would really greatly appreciate any help I can get on this.
Thank you so much!
LozG

 

 

Position IDNameHire DateTermination DateEmployee StatusCompanyDepartmentLeave ReasonGenderCountry
1Employee 114/12/2021 ActiveCompany ASales FemaleUK
2Employee 223/04/2021 ActiveCompany BAdmin FemaleUK
3Employee 315/07/2021 ActiveCompany CSales FemaleUK
4Employee 404/11/202101/01/2022TerminatedCompany DSalesVoluntaryFemaleUK
5Employee 516/11/2021 ActiveCompany AMarkeing MaleUK
6Employee 617/11/2021 ActiveCompany AMarkeing MaleUK
7Employee 723/04/2021 ActiveCompany AMarkeing FemaleFrance
8Employee 802/08/2021 ActiveCompany AMarkeing FemaleFrance
9Employee 901/09/2021 ActiveCompany AMarkeing Female

Spain

10Employee 1022/09/2021 ActiveCompany BFinance FemaleSpain
11Employee 1106/10/202131/07/2022TerminatedCompany BFinance FemaleSpain
12Employee 1221/10/2021 ActiveCompany BFinance FemaleUK
13Employee 1322/10/2021 ActiveCompany BSales MaleUK
14Employee 1427/10/2021 ActiveCompany AAdmin FemaleUK
15Employee 1513/11/2021 ActiveCompany ASales FemaleItaly
16Employee 1616/11/2021 ActiveCompany ASales FemaleItaly
17Employee 1730/11/2021 ActiveCompany CMarkeing FemaleItaly
18Employee 1805/10/2021 ActiveCompany CMarkeing FemaleItaly
19Employee 1901/12/2021 ActiveCompany CMarkeing FemaleUK
20Employee 2002/12/2021 ActiveCompany CMarkeing FemaleUSA
21Employee 2115/08/201730/04/2022TerminatedCompany CMarkeingVoluntaryFemaleUSA
22Employee 2209/10/2021 ActiveCompany AFinance FemaleUSA
23Employee 2313/12/2021 ActiveCompany DFinance FemaleUSA
24Employee 2413/09/2021 ActiveCompany ASales FemaleUSA
25Employee 2504/10/2021 ActiveCompany ASales FemaleUSA
26Employee 2606/12/2021 ActiveCompany DSales MaleUSA
27Employee 2718/12/2021 ActiveCompany DSales FemaleUSA
28Employee 2826/10/2020 ActiveCompany DMarkeing FemaleUSA
29Employee 2928/01/201931/12/2020TerminatedCompany DFinanceInvoluntaryFemaleUSA
30Employee 3002/09/2021 ActiveCompany AFinance FemaleItaly
31Employee 3114/07/2021 ActiveCompany AFinance FemaleUK
32Employee 3227/03/2017 ActiveCompany DAdmin FemaleFrance
33Employee 3301/10/2021 ActiveCompany CAdmin MaleSpain
34Employee 3401/06/2020 ActiveCompany BSales FemaleSpain
35Employee 3512/11/2017 ActiveCompany AMarkeing FemaleUSA

 

  • I have created one example for you see attached.

     

    As you have more than one relationship on the date, you need a primary and inactive relationship, termination date is the inactive and you will see for the measure i use the userelationship function.    I used countrows(employee) to count but you can just as well use distinctcount(employeeid) or whatever it is.

3 Replies

  • vanessafvg's avatar
    vanessafvg
    Icon for Community Champion rankCommunity Champion

    I have created one example for you see attached.

     

    As you have more than one relationship on the date, you need a primary and inactive relationship, termination date is the inactive and you will see for the measure i use the userelationship function.    I used countrows(employee) to count but you can just as well use distinctcount(employeeid) or whatever it is.

    • lozg's avatar
      lozg
      Regular Visitor

      Thank you so much for this, Vanessa!
      Very helpful to guide in the right direction.
      I've managed to use this as the basis to make some of the other cards.
      The one I'm struggling to make is the 'Voluntary' terminations the current year.
      I tried adpating the Measure to:

      var mindate = DATE(YEAR(TODAY()),1,1)
      var maxdate = DATE(YEAR(TODAY()),12,31)
      var cnt  =  CALCULATE(COUNTROWS(Data),Filter(Data,Data[Leave Reason]="Voluntary") , DATESBETWEEN('Calendar'[Date], mindate, maxdate), USERELATIONSHIP('Calendar'[Date], Data[Termination Date]))
      return cnt
      This works perfectly for terminations without specifying the reason. However, when trying to specifiy the 'Voluntary' leavers in this way (specifically the Filter(Data,Data[Leave Reason]="Voluntary") element) it comes back
       blank.
      Could you please help correct what I did wrong when trying to add a condition of 'Leave Reason' to the measure?
      • vanessafvg's avatar
        vanessafvg
        Icon for Community Champion rankCommunity Champion

        will have a look at bit later and get back to you.