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

Simulate monthly payments using List.Dates

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.

EmployeeMonthly SalaryStart DateEnd Date
Employee 1400002019-01-012019-12-31
Employee 2350002019-08-192020-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:

EmployeeMonthly SalaryDate
Employee 1400002019-01-25
Employee 1400002019-02-25
.........
Employee 1400002019-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).

EmployeeMonthly SalaryDate
Employee 2159252019-01-25
Employee 2350002019-09-25
.........
Employee 2316672020-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.

1 REPLY 1
v-xuding-msft
Community Support
Community Support

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"
  • Unpivot other columns.

4.PNG

  • create a new table manually

5.PNG

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"
  • Merge queries

6.PNG

 

8.PNG

 

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.

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.

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.