Forum Discussion
DAX Measure wrong totals
Hi All,
I have built a measure to calculate the projected values based on year selection for each employee wise.
Measure that i have written to get the Porjected Reminder Salary as below
VAR Max_Period_Year = YEAR(MAX('Payroll Wage Earnings'[Max_Period_in_data]))
VAR Month_End_Year = YEAR(MAX('HEADCOUNT'[MONTH_END_DT]))
VAR Max_Period_Month = MONTH(MAX('Payroll Wage Earnings'[Max_Period_in_data]))
VAR Month_End_Month = MONTH(MAX('HEADCOUNT'[MONTH_END_DT]))
RETURN
CALCULATE( ROUND( SUMX( FILTER( 'Payroll Wage Earnings', Max_Period_Year = (SELECTEDVALUE(MasterTable[Proxy Year]) - 1) && Month_End_Year = (SELECTEDVALUE(MasterTable[Proxy Year]) - 1) ), IF( MAX('HEADCOUNT'[EMPL_STATUS] )<> "A" && MAX('HEADCOUNT'[EMPL_STATUS] ) <> "T", [Pay_MAX_Month] * (Month_End_Month - Max_Period_Month), [Pay_MAX_Month]* (12 - Max_Period_Month) ) ), 0 ) )
hear are the three tables data that i have used to build the measure and the sample data.
PayRoll Table
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tdE9C8IwEAbgvxI6KdTk7nJpGzcXUbCDszgUVBSlQuvivzfFDpmaxg9oyYU2l4d7d7sECQBytEmarKq6PV4OqdhUTev2BMRuQYWqKwXSHMA9YlG+v5puwZxZFrkrYeDtGnhXASrou86Eq3S/EZPyXj/Ot+fU/dSXyT4dw6R/MMlnkiL7NVMHmFCghCKSqX2mDk9zuXVnTda1Wjenqk5FWd0u17GZ69yylYgjlN5N0ZkHlcORf6iMjTyoHE7cKY2RWRap/HniPKy0pFly7CzZV7LS8K3S/ENpfKUJzHL/Ag==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, #"Employee Name" = _t, Year = _t, Period_Start_Date = _t, Proxy_Year = _t, #"001S: Salary Base Pay" = _t, #"009: STD 100%" = _t, #"021: Other Paid Absence" = _t, #"032: Holiday" = _t, #"036: Holiday Personal" = _t, #"040: Vacation" = _t, #"045: Final Vacation Pay" = _t, #"201: Base Salary Expat" = _t, KEY = _t, Period = _t, period_monthvar = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee ID", type text}, {"Employee Name", type text}, {"Year", Int64.Type}, {"Period_Start_Date", type datetime}, {"Proxy_Year", Int64.Type}, {"001S: Salary Base Pay", type number}, {"009: STD 100%", Int64.Type}, {"021: Other Paid Absence", Int64.Type}, {"032: Holiday", Int64.Type}, {"036: Holiday Personal", Int64.Type}, {"040: Vacation", Int64.Type}, {"045: Final Vacation Pay", Int64.Type}, {"201: Base Salary Expat", Int64.Type}, {"KEY", type text}, {"Period", type text}, {"period_monthvar", type text}}) in #"Changed Type"
headCount -
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyMDAwN7RU0lHySMwrTs1M0VHwSSwqBvKNDIxMgZShvrGhPpBtomBoZGVgAEQKjr4QaRMk3Y5KsTrEGGekb2RJReOMqes6E31jAyKMCwIb5xYIFDA1MwAKeBalJebpKPgm5mRmK/jmZyTm5iamEBeGSKY4kmgsvrCkwFh8YUqBsfjClgJjTWnjWjPiXAtMCbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [EMPLID = _t, NAME = _t, #"Proxy Year" = _t, MONTH_END_DT = _t, KEY = _t, EMPL_STATUS = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"EMPLID", type text}, {"NAME", type text}, {"Proxy Year", Int64.Type}, {"MONTH_END_DT", type datetime}, {"KEY", type text}, {"EMPL_STATUS", type text}}) in #"Changed Type"
masterTable:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyMDAwN7RU0lHySMwrTs1M0VHwSSwqBvKNDIxMkKSBXFOoqFKsTrSSWyBQytTMACjmWZSWmKej4JuYk5mt4JufkZibm5gCVYukDMWEWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, #"Employee Name" = _t, KEY = _t, #"Proxy Year" = _t, #"Sum of Year" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee ID", type text}, {"Employee Name", type text}, {"KEY", type text}, {"Proxy Year", Int64.Type}, {"Sum of Year", Int64.Type}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Sum of Year", "Year"}}) in #"Renamed Columns"
DataModelling: -
Pay MAX Month is a calculated column which been used to get the Projected reminder salary.
Pay_MAX_Month =
Var A ='Payroll Wage Earnings'[001S: Salary Base Pay]
Var B = 'Payroll Wage Earnings'[009: STD 100%]
Var C ='Payroll Wage Earnings'[021: Other Paid Absence]
Var D = 'Payroll Wage Earnings'[032: Holiday]
Var E = 'Payroll Wage Earnings'[036: Holiday Personal]
Var F ='Payroll Wage Earnings'[040: Vacation]
Var G = 'Payroll Wage Earnings'[045: Final Vacation Pay]
Var H = 'Payroll Wage Earnings'[201: Base Salary Expat]
Var totalCount = A+B+C+D+E+F+G+H
VAR PayMaxMonth = SWITCH ( true(), 'Payroll Wage Earnings'[period_monthvar]="Monthly",totalCount, 'Payroll Wage Earnings'[period_monthvar]="Semi-Monthly", totalCount * 2)
VAR MaxPeriodindata = CALCULATE( MAX('Payroll Wage Earnings'[Period_Start_Date]),ALLEXCEPT('Payroll Wage Earnings','Payroll Wage Earnings'[Year],'Payroll Wage Earnings'[Employee ID])) RETURN IF('Payroll Wage Earnings'[Period_Start_Date] = MaxPeriodindata, PayMaxMonth )Max_Period_in_data = CALCULATE( MAX('Payroll Wage Earnings'[Period_Start_Date]),ALLEXCEPT('Payroll Wage Earnings','Payroll Wage Earnings'[Year],'Payroll Wage Earnings'[Employee ID])) //date(max( [Period Start Date])) as Max_Period_in_data
The measure which i have written gives me right results at each row of employee level but the totals are not.
Even if i filter with Employee Status slicer the data is not right.
May I know what is it if i could change here to make this calculation work as expected.
Thanks
Mohan V.
- Anonymous1 year ago
Hi,
Thanks for MFelix 's concern about the problem, and i want to offer some more informaiton for user to refer to.
hello Mohan128256 , based on your description, you can create a new measure.
Sum_peojectRemainderSalary = SUMX(VALUES(HEADCOUNT[NAME]),[_Projected Remainder Salary])Then change the _salary measure to the following.
_Salary = [_Sum Of Salary Till Date] + [Sum_peojectRemainderSalary]Tnen put measures to the visual.
Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- MFelix
Super User
Hi Mohan128256 ,
First of all I apologize but the images are very small and it's not possible to check how you are building the visualization.
On some of the aspects that I can see on your modelling is the fact that you are using bi directional filters this can cause incorrect values since the tables in your model will be filterin each other so you need to be carefull with this.
Another aspects is the calculation you are doing since you are using an if statment with MAX the context value on the final row probably is giving you the incorrect total.
Can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.
If the information is sensitive please share it trough private message.- Mohan128256
Helper IV
Hi MFelix thanks for the quick responce.
I have added the sample file here in below link.
https://drive.google.com/file/d/1p263mOD4975sR2ZPPlShErjOXG0PQhvH/view?usp=sharing
Please check and let me know if you could help me out with the requireed output.
Let me know if you need any further details.
Thanks,
Mohan V.
- MFelix
Super User