Forum Discussion

tobiasmcbride's avatar
tobiasmcbride
Icon for Helper III rankHelper III
6 years ago

Number at a particular date

Hi,

 

I have the following data on headcount.

 

NamePositionStart DateEnd DateCurrent Status
Joe BloggsdHead of Marketing21/02/2017 Established
Noah AnyoneHead of Operations21/06/201720/07/2019Left
Joe Bloggs JnrVP Marketing21/07/201820/01/2020Transfer Out

 

I want to be able to calculate the number of employees we had at a particular date.

 

This would ideally be one filter or something that enables me to select a date from and it would give me the total number of employees at that date, that includes those who are currently established, who had just started, who have since left etc. I.e. just a date filter that enables me to say - So at 31st March 2019 how many people did we have in the business, where were they and what were they doing?

 

Easy enough for those established as case of counting them but almost need a time travel ability to look back and say - on X Date we had A established, B had yet to start etc. - and need to include those who have since left but were established employees at that time.

22 Replies

    • tobiasmcbride's avatar
      tobiasmcbride
      Icon for Helper III rankHelper III

      That won't work as it needs to be able to have a particular date and then say on that date how many did we have in the firm (i.e. whose start date and end date, latter if applicable coincided with it). 

      • Anonymous's avatar
        Anonymous
        Not applicable

        ok in any case add a date dimension and add a slicer on the top with the date


        Now you have your date you want to analyze with

        CurrentDate=SELECTEDVALUE(YourDateTable[Date])

        Now your measure will be

        EmployeesAtThatDate=
        Var CurrentDate=SELECTEDVALUE(YourDateDim[Date])
        RETURN
        COUNTROWS(
        FILTER(Employees;Employees[StartDate]<=CurrentDate && Employees[EndDate]>=CurrentDate))

        As I'm writing on the fly and I don't remember you mihgt have to use

        EmployeesAtThatDate=
        Var CurrentDate=SELECTEDVALUE(YourDateDim[Date])
        RETURN
        CALCULATE(COUNTROWS(Employees);FILTER(Employees;Employees[StartDate]<=CurrentDate && Employees[EndDate]>=CurrentDate))



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

    Hi tobiasmcbride 

     

    You can add an extra table to your model that expand dates ( start to end ).

    On the attached, you will find a file that applies this concept to your sample.

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    LinkedIn


     

    • tobiasmcbride's avatar
      tobiasmcbride
      Icon for Helper III rankHelper III

      How do you expand those dates to get that as cannot see a formula anywhere in DAX for epandDates?

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

        Hi tobiasmcbride 

         

        In Query Editor you will see a function epandDates should really be expandDates (typo), this function is invoked in emplyeeDates table, please see the video.

         

        Best Regards,
        Mariusz

        If this post helps, then please consider Accepting it as the solution.

        Please feel free to connect with me.
        LinkedIn

         

  • v-easonf-msft's avatar
    v-easonf-msft
    Icon for Community Support rankCommunity Support

    Hi , tobiasmcbride 

    Follow these steps:

    1.Change the type of "Start Date" and "End Date "from "text" to "data" in "Edit queries"

     1) replace "" to null in "End Date"

    = Table.ReplaceValue(#"Changed Type","","null",Replacer.ReplaceText,{"End Date"})

     2)change type

    = Table.TransformColumnTypes(#"Replaced Value",{{"Start Date", type date}},"ar-BH")
    = Table.TransformColumnTypes(#"Changed Type1",{{"End Date", type date}},"ar-BH")

    It will show as below:

     

    2.Create calculate table "Date" and table "Current Status" to create slicer

    Date = CALENDAR(MIN('Table'[Start Date]),TODAY())
    Current Status = SUMMARIZE('Table','Table'[Current Status])

     

    3.create measure "count" in Table and apply it in card visual

    Count = CALCULATE(COUNTROWS('Table'),FILTER('Table',IF(ISBLANK([End Date]),'Table'[Start Date]<=[currentdate],'Table'[Start Date]<=[currentdate]&&'Table'[End Date]>=[currentdate])))

     

    4.create measure "visual control" and apply it in the table visual filter

    Visual Control = IF([Count]>0,1,-1)

     

     

    In the end ,it shows as below:

    Here is a  demo . 

     

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.