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
MStark
Helper III
Helper III

Average Active EEs for Date Range

Hi,

 

I have a tableof employees with Hire, Termination and Rehire Dates. I also have a date table
Im trying to get the average amount of active employees for whatever date range is selected on the date table. Should be the  amount of active employees on the first date selected + active EEs of last day /2

Active Employee= Employee whos hire date is before selected date and termination date is blank or after selected date + employees with rehire date which is before selected date and status is Active

In Excel I have countifs formulas giving me the correct information

Can anyone help me out with getting this in BI? 

 

Sample Data:

Company NameEmployee NumberFull NameDefault CC1 DescriptionEmployee StatusHire DateRehire DateTermination Date
ABC10611933Employee, o24NursingActive04/13/2009  
ABC10611936Employee, o27NursingActive10/30/2009  
ABC10611938Employee, o29NursingActive12/01/2010  
ABC10611939Employee, o30NursingTerminated12/01/2010 01/31/2022
ABC10611935Employee, o26NursingActive06/29/2012  
ABC10611917Employee, o8AdministrationActive07/14/2014  
ABC10611918Employee, o9AdministrationActive02/20/2017  
ABC10611931Employee, o22NursingActive05/22/2017  
ABC10611914Employee, o5NursingActive05/21/2018  
ABC10611916Employee, o7ActivitiesActive07/15/2019  
ABC10611910Employee, o1ActivitiesTerminated12/29/2020 06/11/2021
ABC10611911Employee, o2ActivitiesTerminated12/29/2020 04/08/2021
ABC10611912Employee, o3ActivitiesTerminated12/29/2020 07/12/2021
ABC10611919Employee, o10HousekeepingActive12/29/2020  
ABC10611941Employee, o32AdministrationActive02/24/202104/28/202203/27/2022
ABC10611920Employee, o11HousekeepingActive03/24/2021  
ABC10611921Employee, o12HousekeepingTerminated05/05/2021 04/29/2022
ABC10611934Employee, o25AdministrationActive06/02/2021  
ABC10611922Employee, o13HousekeepingTerminated06/16/2021 08/20/2022
ABC10611930Employee, o21HousekeepingTerminated06/30/2021 07/16/2022
ABC10611928Employee, o19HousekeepingTerminated08/25/202103/21/202201/03/2022
ABC10611923Employee, o14NursingTerminated10/20/2021 03/29/2022
ABC10611924Employee, o15NursingTerminated10/20/2021 06/11/2022
ABC10611925Employee, o16NursingTerminated12/01/2021 03/27/2022
ABC10611929Employee, o20HousekeepingTerminated12/15/2021 12/28/2021
ABC10611927Employee, o18HousekeepingActive02/09/2022  
ABC10611932Employee, o23NursingTerminated04/06/2022 05/20/2022
ABC10611940Employee, o31AdministrationTerminated06/15/2022 07/28/2022

 

Thanks in advance!

1 ACCEPTED SOLUTION

I created the measure below and it works for now! Thanks so much for all your help!!

MStark_0-1663857244213.png

 

View solution in original post

10 REPLIES 10
v-yiruan-msft
Community Support
Community Support

Hi @MStark ,

You can create a measure as below to get it, please find the details in the attachment.

Active Employee = 
VAR _seldate =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Employee'[Full Name] ),
        FILTER (
            'Employee',
            (
                'Employee'[Hire Date] <= _seldate
                    && (
                        ISBLANK ( 'Employee'[Termination Date] )
                            || 'Employee'[Termination Date] > _seldate
                    )
            )
                || ( 'Employee'[Rehire Date] <= _seldate
                && 'Employee'[Employee Status] = "Active" )
        )
    )

yingyinr_0-1663729346530.png

Best Regards

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

Thanks for taking the time to look into this! I see it works in the test file you attached but when I copied the formula to the BI with real data, Im getting the same number for all months. Is there anything that needs to be updated?

MStark_1-1663774428246.png

 

 

Hi @MStark ,

Please try to update the formula of measure [Active Employee] as below and check if it can return the correct result...

Active Employee = 
VAR _selyear =
    SELECTEDVALUE ( 'Calendar'[Date].[Year] )
VAR _selmonth =
    SELECTEDVALUE ( 'Calendar'[Date].[MonthNo] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'EE Info'[Full Name] ),
        FILTER (
            'EE Info',
            (
                VALUE (
                    YEAR ( 'EE Info'[Hire Date] )
                        & IF (
                            MONTH ( 'EE Info'[Hire Date] ) < 10,
                            "0" & MONTH ( 'EE Info'[Hire Date] ),
                            MONTH ( 'EE Info'[Hire Date] )
                        )
                )
                    <= VALUE ( _selyear & IF ( _selmonth < 10, "0" & _selmonth, _selmonth ) )
                    && (
                        ISBLANK ( 'EE Info'[Termination Date] )
                            || VALUE (
                                YEAR ( 'EE Info'[Termination Date] )
                                    & IF (
                                        MONTH ( 'EE Info'[Termination Date] ) < 10,
                                        "0" & MONTH ( 'EE Info'[Termination Date] ),
                                        MONTH ( 'EE Info'[Termination Date] )
                                    )
                            )
                                > VALUE ( _selyear & IF ( _selmonth < 10, "0" & _selmonth, _selmonth ) )
                    )
            )
                || (
                    VALUE (
                        YEAR ( 'EE Info'[Rehire Date] )
                            & IF (
                                MONTH ( 'EE Info'[Rehire Date] ) < 10,
                                "0" & MONTH ( 'EE Info'[Rehire Date] ),
                                MONTH ( 'EE Info'[Rehire Date] )
                            )
                    )
                        <= VALUE ( _selyear & IF ( _selmonth < 10, "0" & _selmonth, _selmonth ) )
                        && 'EE Info'[Employee Status] = "Active"
                )
        )
    )

yingyinr_0-1663833079342.png

Best Regards

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

Still doesnt seem to work... does a relationship between the calendar and EE info table need to be active? I played around with measure Greg_Deckler provided and its working for now

Thanks so much for your time and assistance!

Greg_Deckler
Super User
Super User

@MStark Maybe:

Measure =
  VAR __Min = MIN('Dates'[Date])
  VAR __Max = MAX('Dates'[Date])
  VAR __Table = FILTER('Table',[Hire Date] <= __Min && ( [Termination Date] = BLANK() || [Termination Date] < __Min) )
  VAR __Table1 = FILTER('Table', [Hire Date] <= __Max && ( [Termination Date] = BLANK() || NOT([Termination Date] > __Min && [Termination Date] < __Max) )
RETURN
  DIVIDE(COUNTROWS(__Table) + COUNTROWS(__Table1),2)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler This seems to work though it doesnt include Rehires. Employee should also be counted as an active employee if has a rehire date before the selected date and status is Active or if terminated the termination date is after date selected
Thanks for your time!

@MStark Yeah, I considered rehires but I wasn't sure how that worked in your system. Does the employee get an additional row? Does the employee ID stay the same? If both of those are "yes" then you could potentially solve it using a SUMMARIZE and make sure you grab the MAX start date and then essentially lookup the corresponding termination date for each row. Messy.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Employee # stays the same but an additional row is not added. Theres a separate column named Rehire Date (see sample data on original post)

I was thinking of adding 2 more Var for Rehires on first day selected and rehires on last day selected. Then to add it to the average. Did something like this but its not working. Think maybe the issue is that its counting employees who dont have a rehire date instead of only rehires <= Max or Min dates

MStark_0-1663782900810.png

Any advise on what Im doing wrong or a different way to get this done?

 

Thanks for taking the time to look into this!

@MStark Maybe tank your __RF and __RL variables and in your __F and __L variables where you refer to [Hire Date] replace that column reference with MAX([Hire Date, [Rehire Date])


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I created the measure below and it works for now! Thanks so much for all your help!!

MStark_0-1663857244213.png

 

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.