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
Anonymous
Not applicable

Calculate salary running total based on employment start and end date

Hi all,

 

I have this data below and a Date table. Mark was promoted to different roles hence the change in his salary. I'd like to calculate his monthly salary and prorated salary based on his start and end dates

 

EmployeeStart DateEnd Date Annual  Monthly Increase
Mark Lopez5/17/2021  1,200,000.00 100,000.00 
Mark Lopez7/1/2021  1,500,000.00 125,000.00300,000
Mark Lopez9/1/20219/15/2021 2,000,000.00 166,667.00500,000

 

My calculations:

Increase =
VAR PreviousDate_ =
CALCULATE (
MAX ( Employee[Start Date] ),
Employee[Start Date] < EARLIER ( Employee[Start Date] ),
ALLEXCEPT ( Employee, Employee[Employee__Id] )
)
VAR PreviousValue_ =
CALCULATE (
DISTINCT ( Employee[Annual] ),
Employee[Start Date] = PreviousDate_,
ALLEXCEPT ( Employee, Employee[Employee__Id] )
)
VAR CurrentValue_ = Employee[Annual]
RETURN
IF (
NOT ISBLANK ( CurrentValue_ ) && NOT ISBLANK ( PreviousValue_ ),
CurrentValue_ - PreviousValue_
)
Original Salary = CALCULATE(SUM(Employee[Annual]), Employee[Increase] =BLANK())
CUMULATIVE =
CALCULATE(([Original Salary]+ SUM(Employee[Increase]))/12,
FILTER(ALLSELECTED('Date'[Date]),
'Date'[Date]<=MAX('Date'[Date])))
Running Total (SALARY)  =
VAR MaxDate =
MAX ( 'Date'[Date] )
RETURN
CALCULATE ([CUMULATIVE],
Employee[Start Date] <= MaxDate,
OR(ISBLANK(Employee[End Date]),
Employee[End Date] > MaxDate)
)

Result:

cvld_11-1633616615100.png

I computed the prorated salary as

  Days Worked DATEDIFF(Employee[Start Date], ENDOFMONTH('Date'[Date].[Date]),DAY) +1

  Prorated Salary =( Days Worked*Monthly)/30

But it did not return what I was looking for

cvld_12-1633617747135.png

Im looking to have:

EmployeeStart Date Annual Salary  Monthly  Paid 
Mark Lopez5/17/2021 $   1,200,000.00 ₱  100,000.00 ₱    50,000.00
Mark Lopez6/1/2021 $   1,200,000.00 ₱  100,000.00 ₱  100,000.00
Mark Lopez7/1/2021 $   1,500,000.00 ₱  125,000.00 ₱  125,000.00
Mark Lopez8/1/2021 $   1,500,000.00 ₱  125,000.00 ₱  125,000.00
Mark Lopez9/1/2021 $   2,000,000.00 ₱  166,667.00 ₱    83,333.00

cvld_1-1633618453799.png

Appreciate your help on this one!

 

3 ACCEPTED SOLUTIONS
AlexisOlson
Super User
Super User

Getting the number of days employed in a particular month is the hardest part, IMO.

 

Here's my attempt:

 

MonthlyPaid =
VAR MonthEnd = MAX ( 'Date'[Date] )
VAR MonthStart = MIN ( 'Date'[Date] )
VAR StartDate = CALCULATE ( MAX ( Employee[Start Date] ), Employee[Start Date] < MonthEnd )
VAR EndDate =   CALCULATE ( MIN ( Employee[End Date] ),   Employee[End Date] > StartDate  )
VAR MonthlySalary =
    CALCULATE (
        SELECTEDVALUE ( Employee[Monthly] ),
        Employee[Start Date] = StartDate
    )
VAR DaysEmployed =
    DATEDIFF (
        MAX ( StartDate, MonthStart ),
        MIN ( EndDate, MonthEnd ),
        DAY
    ) + 1
VAR DaysInMonth = DAY ( MonthEnd )
RETURN
    IF ( DaysEmployed > 0, MonthlySalary * DaysEmployed / DaysInMonth )

 

AlexisOlson_0-1633624335529.png

 

View solution in original post

You might just need to handle null for EndDate. See if it helps to replace

MIN ( EndDate, MonthEnd )

with 

IF ( ISBLANK ( EndDate ), MonthEnd, MIN ( EndDate, MonthEnd ) )

 

View solution in original post

The measure is looking up a single salary. For multiple employees, you'll probably need to wrap the measure with SUMX to iterate through separate employees.

SumMonthlyPaid =
SUMX ( VALUES ( Employee[Employee_Id] ), [MonthlyPaid] )

View solution in original post

8 REPLIES 8
AlexisOlson
Super User
Super User

Getting the number of days employed in a particular month is the hardest part, IMO.

 

Here's my attempt:

 

MonthlyPaid =
VAR MonthEnd = MAX ( 'Date'[Date] )
VAR MonthStart = MIN ( 'Date'[Date] )
VAR StartDate = CALCULATE ( MAX ( Employee[Start Date] ), Employee[Start Date] < MonthEnd )
VAR EndDate =   CALCULATE ( MIN ( Employee[End Date] ),   Employee[End Date] > StartDate  )
VAR MonthlySalary =
    CALCULATE (
        SELECTEDVALUE ( Employee[Monthly] ),
        Employee[Start Date] = StartDate
    )
VAR DaysEmployed =
    DATEDIFF (
        MAX ( StartDate, MonthStart ),
        MIN ( EndDate, MonthEnd ),
        DAY
    ) + 1
VAR DaysInMonth = DAY ( MonthEnd )
RETURN
    IF ( DaysEmployed > 0, MonthlySalary * DaysEmployed / DaysInMonth )

 

AlexisOlson_0-1633624335529.png

 

Anonymous
Not applicable

Hi @AlexisOlson thank you for taking the time to work on this. I used your formula to recreate the same visual in your solution but the May month is not showing on my end. What am i missing? I used Date table as x-axis

cvld_0-1633628444420.png

Thanks!

I'm not sure. Do you have any table relationships doing unintended filtering?

Maybe try debugging the measure by returning each of the VARs until you find the one not working as expected?

Anonymous
Not applicable

Hi @AlexisOlson i've found what i was missing! The formula works perfectly for inactive employees. If you would be so kind, how can I make it work for active employees (employees with no employment end dates)?

You might just need to handle null for EndDate. See if it helps to replace

MIN ( EndDate, MonthEnd )

with 

IF ( ISBLANK ( EndDate ), MonthEnd, MIN ( EndDate, MonthEnd ) )

 

Anonymous
Not applicable

@AlexisOlson follow up question - (pls excuse my little knowledge in dax)

when selecting 2 or more employees to see the cumulative salaries, why is it showing like this? I would like them to add up. 

cvld_0-1633706749089.png

 

The measure is looking up a single salary. For multiple employees, you'll probably need to wrap the measure with SUMX to iterate through separate employees.

SumMonthlyPaid =
SUMX ( VALUES ( Employee[Employee_Id] ), [MonthlyPaid] )
Anonymous
Not applicable

@AlexisOlson perfect!!! thank you so much! I really appreciate  your help!

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.