Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Count by Date Range - Looking for Help

Hi Everyone, 

 

I have encountered yet another problem that I'm looking to solve. 

 

I have a table with employee names that also contain their start-dates and roll-off dates.

Example:

 

Name // Start Date // Roll-Off Date 

Kris // 01-Sep-2018 // 12-Dec-2020

Alice // 01-Jun-2019 // 01-Oct-2019

Mark // 17-Jan-2018 // 10-Aug-2018

Karen // 03-May-2019 // 17-Oct-2018

Lisa // 27-Mar-2019 // 11-Sep-2020

 

 

What I'm looking for is a measure that will count the rows and return an "Active" Headcount, based on the data range.

 

For example, I want to know how many "Active" employees we have in October 2019. Measure then looks at the start date & end date of the employee and only returns Active head count number for people who's roll-off date is not in the past. For example using the table above, the total active headcount returned should be = 2, since only Kris and Lisa have Roll-off dates in the future. 

I then would like to create a slicer so I can go back to other month's and see how many Active people I had in May or June, or September and so on.

 

I'm fairly new to Power BI and I'm learning a lot. but this is something I can't yet figure out how to do. 

Your help is much appreciated. 

 

Best Regards,

Kris

  • AlB's avatar
    AlB
    6 years ago

     

    Measure =
    VAR CutOffDate_ =
        MAX ( CalendarTable[Date] )
    RETURN
        COUNTROWS ( FILTER ( Table1, Table1[Roll-Off Date] > CutOffDate_  || ISBLANK( Table1[Roll-Off Date] ) ) )

     

    Please mark the question solved when done and consider giving kudos if posts are helpful.

    Cheers  Datanaut

3 Replies

  • AlB's avatar
    AlB
    Community Champion

    Hi Anonymous 

    1. Create a standard calendar table (no relationships to the table you show). Place month and year in a slicer.

    2.  Place this measure in a card visual (assumes only one row per employee in the table you show (Table1))

    Measure =
    VAR CutOffDate_ =
        MAX ( CalendarTable[Date] )
    RETURN
        COUNTROWS ( FILTER ( Table1, Table1[Roll-Off Date] > CutOffDate_ ) )

     

    Please mark the question solved when done and consider giving kudos if posts are helpful.

    Cheers  Datanaut

        

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi AlB ,

       

      Thanks for the Suggestion. 

      I already had a rolling-calendar created, There is no relationship between the Employe Table and calendar. 

       

       

      What if the Roll-off date contains a lot of "Null" values as the people who are not yet rolled-off will not have the date in there. 

      is it possible to amend the formula so that it also counts the null values too please?

       

      BR,

      Kris

      • AlB's avatar
        AlB
        Community Champion

         

        Measure =
        VAR CutOffDate_ =
            MAX ( CalendarTable[Date] )
        RETURN
            COUNTROWS ( FILTER ( Table1, Table1[Roll-Off Date] > CutOffDate_  || ISBLANK( Table1[Roll-Off Date] ) ) )

         

        Please mark the question solved when done and consider giving kudos if posts are helpful.

        Cheers  Datanaut