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
scowans
Frequent Visitor

Monthly Headcount and Salary Based on Start and End Dates

Hello,

I have a requirement to show active headcount and prorated salary by month based on the hire and termination dates for employees including future months from a forecasting perspective (see sample dataset below).  I also need to calculate a cumulative running total for the prorated monthly salary.

 

Employee IDEmployee NameDepartmentHire DateTermination DateSalarySalaryMonthly
E101Emp Name 1Dept A9/15/202311/5/202312000010000
E102Emp Name 2Dept B11/25/2023 12000010000
E103Emp Name 3Dept A10/1/2023 12000010000
E104Emp Name 4Dept B10/20/202312/15/202312000010000

 

I was able to acheive the 1st part of the requirement for Active Headcount by creating the following 3 measures below:

 

 

 

 

# Hired = CALCULATE(COUNT('Employee'[Employee ID]),USERELATIONSHIP('Employee'[Hire Date],'Date'[Date]) )
 
# Exits = CALCULATE(COUNT('Employee'[Employee ID]),USERELATIONSHIP('Employee'[Termination Date Alt],'Date'[Date]),not(ISBLANK('Employee'[Termination Date Alt])))
 
# Active HC = CALCULATE(COUNTX(
    FILTER('Employee','Employee'[Hire Date]<=max('Date'[Date])
    && (ISBLANK('Employee'[Termination Date Alt]) || 'Employee'[Termination Date Alt]>max('Date'[Date]))),
    ('Employee'[Employee ID])),
    CROSSFILTER('Employee'[Hire Date],'Date'[Date],None))

 

 

 

 

Which gives me the below desired results:

 

scowans_0-1706721901473.png

 

The part I'm struggling w/ is how to create the measures to dynamically calculate the monthly salary amounts (prorated for the hire and termination months based on the hire and termination dates and how to show a cumulative running total for the monthly salary.  I have researched this and I have found some solutions that get me close to what i'm looking for but they did not address all of the requirements specifically for my use case.  I created the following table below manually to illustrate the desired results that I'm looking for and I used the below calculations to prorate the month salary:

 

Hire Month Proration: Monthly Salary / 30 * (Month End Date - Hire Date) 

Termination Month Proration: Monthly Salary / 30 * (Term Date - Month Start Date) 

 

Employee IDDepartmentHire DateTerm DateMonth StartMonth EndSalaryMonthlyCumulativeSalaryMonthly
E101Dept A9/15/202311/5/20239/1/20239/30/202350005000
E101Dept A9/15/202311/5/202310/1/202310/31/20231000015000
E101Dept A9/15/202311/5/202311/1/202311/30/20231333.33333316333.33333
E101Dept A9/15/202311/5/202312/1/202312/31/2023 16333.33333
E101Dept A9/15/202311/5/20231/1/20241/31/2024 16333.33333
E101Dept A9/15/202311/5/20232/1/20242/29/2024 16333.33333
E102Dept B11/25/2023 9/1/20239/30/2023  
E102Dept B11/25/2023 10/1/202310/31/2023  
E102Dept B11/25/2023 11/1/202311/30/20231666.6666671666.666667
E102Dept B11/25/2023 12/1/202312/31/20231000011666.66667
E102Dept B11/25/2023 1/1/20241/31/20241000021666.66667
E102Dept B11/25/2023 2/1/20242/29/20241000031666.66667
E103Dept A10/1/2023 9/1/20239/30/2023  
E103Dept A10/1/2023 10/1/202310/31/20231000010000
E103Dept A10/1/2023 11/1/202311/30/20231000020000
E103Dept A10/1/2023 12/1/202312/31/20231000030000
E103Dept A10/1/2023 1/1/20241/31/20241000040000
E103Dept A10/1/2023 2/1/20242/29/20241000050000
E104Dept B10/20/202312/15/20239/1/20239/30/2023  
E104Dept B10/20/202312/15/202310/1/202310/31/20233666.6666673666.666667
E104Dept B10/20/202312/15/202311/1/202311/30/20231000013666.66667
E104Dept B10/20/202312/15/202312/1/202312/31/20234666.66666718333.33333
E104Dept B10/20/202312/15/20231/1/20241/31/2024 18333.33333
E104Dept B10/20/202312/15/20232/1/20242/29/2024 18333.33333

 

Below is the the summary view of the above table that I'm trying to incorporate into my pbix model.

 

 9/1/202310/1/202311/1/202312/1/20231/1/20242/1/2024Total
Dept A       
Monthly Salary$5,000$20,000$11,333$10,000$10,000$10,000$66,333
**bleep** Monthly Salary$5,000$25,000$36,333$46,333$56,333$66,333 
Dept B       
Monthly Salary $3,667$11,667$14,667$10,000$10,000$50,000
**bleep** Monthly Salary $3,667$15,333$30,000$40,000$50,000 
 
Any guidance here would be much appreciated.  😁  P.S. I'm also attaching a link to the pbix file.
 
 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@scowans , Check the file attached , use sum salary  

 

# Salary = CALCULATE( Sumx(
    FILTER('Employee','Employee'[Hire Date]<=max('Date'[Date]) 
    && (ISBLANK('Employee'[Termination Date Alt]) || 'Employee'[Termination Date Alt]>max('Date'[Date]))),
    Employee[SalaryMonthly]),
    CROSSFILTER('Employee'[Hire Date],'Date'[Date],None))


Sum Salary = CALCULATE( Sumx(values( 'Date'[Month (Calendar)]),CALCULATE(Sumx(
    FILTER('Employee','Employee'[Hire Date]<=max('Date'[Date]) 
    && (ISBLANK('Employee'[Termination Date Alt]) || 'Employee'[Termination Date Alt]>max('Date'[Date]))),
    ([# Salary])))),
    CROSSFILTER('Employee'[Hire Date],'Date'[Date],None))

 

 

View solution in original post

2 REPLIES 2
scowans
Frequent Visitor

@amitchandak , Thanks so much for the feedback , the # Salary measure works nicely for the monthly salary , it looks like the Sum Salary measure isn't showing the accurate cumulative monthly salary totals month over month by Department , possible to provide any other recommendation(s) for the cumulative monthly salary.

 

scowans_0-1706790701317.png

 

 

amitchandak
Super User
Super User

@scowans , Check the file attached , use sum salary  

 

# Salary = CALCULATE( Sumx(
    FILTER('Employee','Employee'[Hire Date]<=max('Date'[Date]) 
    && (ISBLANK('Employee'[Termination Date Alt]) || 'Employee'[Termination Date Alt]>max('Date'[Date]))),
    Employee[SalaryMonthly]),
    CROSSFILTER('Employee'[Hire Date],'Date'[Date],None))


Sum Salary = CALCULATE( Sumx(values( 'Date'[Month (Calendar)]),CALCULATE(Sumx(
    FILTER('Employee','Employee'[Hire Date]<=max('Date'[Date]) 
    && (ISBLANK('Employee'[Termination Date Alt]) || 'Employee'[Termination Date Alt]>max('Date'[Date]))),
    ([# Salary])))),
    CROSSFILTER('Employee'[Hire Date],'Date'[Date],None))

 

 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.