Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Dear BI Community, I have a challanging problem that I would love to get some help with.
I have a table called Salaries with the salaries of each employee at the company with columns indicating the start date and termination date of each employment.
Employee | Monthly Salary | Start Date | End Date |
Employee 1 | 40000 | 2019-01-01 | 2019-12-31 |
Employee 2 | 35000 | 2019-08-19 | 2020-05-27 |
The salary is to be payed the same month (On the 25th) as the Employee has worked. This is what I would like to simulate.
Employee 1
The first employee will get payed in full 2019-01-25 (First payment) as well as 2019-12-15 (Last payment).
This is the result I'm looking for:
Employee | Monthly Salary | Date |
Employee 1 | 40000 | 2019-01-25 |
Employee 1 | 40000 | 2019-02-25 |
... | ... | ... |
Employee 1 | 40000 | 2019-12-25 |
Employee 2
The second employee is a a lot trickier since he has only worked 10 days of the total of 22 working days of August 2019 (10/22 = 45,5%, 35000 * 0,455 = 15925).
The same logic applies to the last payment (19/21 = 90,5%, 35000 * 0,905 = 31667).
Employee | Monthly Salary | Date |
Employee 2 | 15925 | 2019-01-25 |
Employee 2 | 35000 | 2019-09-25 |
... | ... | ... |
Employee 2 | 31667 | 2020-05-25 |
I've tried List.Dates which only allows me to put the duration in days and doesn't even get me close to a solution, at least to my knowledge.
Is this possible to achive in Power Query?
Any help would be hugely appreciated.
Hi @Anonymous ,
By my test, you could create a new table and then merge it with table1. However, if you have a lot of data, the method will be complicated.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs0tyMmvTE1V0lHyzc8rycipVAhOzEksqgQKBJckFpUouCSWgGRd81IgzFgdhC4FQ6CMiQEQAGkjA0NLXQNDIIJxDI10jQ1RNRgB5YxNkTVY6BpagjlGBroGprpG5kqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}}), #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]), #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Employee", type text}, {"Monthly Salary", Int64.Type}, {"Start Date", type date}, {"End Date", type date}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Employee", "Monthly Salary"}, "Attribute", "Value") in #"Unpivoted Other Columns"
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3MtU3MjC0VNIBsg0hzFidaCUjrBKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, #"Start Date" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type date}, {"Start Date", type date}}), #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Start Date"}, Table, {"Value"}, "Table", JoinKind.LeftOuter), #"Expanded Table" = Table.ExpandTableColumn(#"Merged Queries", "Table", {"Employee"}, {"Table.Employee"}) in #"Expanded Table"
Tips: If you have a lot of data, the method will be complicated. I suggest you to calculate Monthly Salary directly without the column of Salary Date.
If you want to calculate the monthly salary with DAX, please post a dummy file that easier to help.
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.