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
adeeln
Post Patron
Post Patron

Need help in writing DAX to calculate HR - Productivity Saving


Hi Everyone,
Need your help in writing DAX,
I'm using Direct Query Mode, this is nessary for project. For sample test attached Power BI is in Import mode.
I'm facing issue in order to calculate Productivity Saving (given below formula) for each employees using measures. Expected output is attached in SQL query form. That i want to acheive in
Power BI.

Could not getting why DAX returning wrong sum output for Productity Savings.
so scenario is
ProdGain | HourlyRate | Savings
10 x 20 = 200
15 x 10 = 150
------------------------------------
ExpectedResult for ProdSaving= 200 + 150 = 350

DAX calculating correct results on table row wise but wrong at total and card.
DAX help will be appreciated.

 

Formulas:

HC = total no of active employees before selected period
Hires = total no of employees hired on selected period
Termination = total no of employees terminated in selected period

Productivity Lose = YTD SUM (Leave[Hours]) -> for all HC employees

Productivity Gain = sum(Total X-Allocated Leaves * 8 ) - Productivity Loss

Productivity Index = 1 - (Productivity Loss (for selected Period) / (Total HC For upto selected Period * AverageMonthlyWorkHours))

Productity Savings = Productity Gain * (current Annual salary/Average Yearly Working Hours (calculated at the Period Level)


Attachments:
Power BI File (PBIX)

Power BI output

Wrong DAX output.png

 

Expected Output row wise from SQL

SQL Server PS.png

 

Expected Output sum from SQL

SQL Server Expected Output PS.png

 

Thanks

2 REPLIES 2
edhans
Super User
Super User

I'm having a little trouble following the formulas because it bounces between calculated columns and measures, but I don't understand what your MAXDATE is doing. Your formula total is wrong because it seems to be adding up all of the hourly rates and multiplying that by the hours (gross oversimplification) because at the total row, there is no filter context on what the rate is. It is not iterating through the hours.

 

This measure, on the otherhand, does.

Measure =
VAR MaxDate = MAX(DimDate[Date])
VAR Total =
SUMX(
    FILTER(
        HR,
        RELATED(DimDate[Date]) <= MaxDate
    ),
    [Productivity Gain(hrs)] * (HR[IndividualHourlyRate] - [terminated IndividualHourlyRate Measure])
)
RETURN
    Total

 

However, so does this one, and It ignores your maxdate logic.

Measure 2 = 
VAR Total =
SUMX(
    HR,
    [Productivity Gain(hrs)] * (HR[IndividualHourlyRate] - [terminated IndividualHourlyRate Measure])
)
RETURN
    Total

 

Again, I am 100% certian I am not following your logic all the way through, but if you can tell me what the maxdate is needed for, I might be able to help further. The max date in your date table is Dec 2020, so why aren't you just using ALL() if you need to remove the filters, or just let the date slicers do their work?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thanks @edhans 
I really appriciate your help, actually i dont know the purpose of MAX date.

I'v experience with Excel formulas so i'm little aware of DAX context.

I was just picked measures from internet. You can remove mine and apply your logic to get exact statistics.

Thanks. 

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.