I have a staff total salary data with staff Start Date and End Date spanning multiple years.
What I would like to achieve is to break down this total salary into individual years in multiple rows, then calculate the daily rate and apply the salary for each year accordingly.
As I have large data with more than 3000 staff and complex start and end dates, I wonder if this can be done in Query Editor? If so could someone please suggest a solution? I attach here the excel file for your reference. Salary Yearly Breakdown.xlsx (11.7 KB)
I used a combination of Power Query and then a calculated column. When want to do look ups like a range of dates, PQ is just slow.
Steps:
Created a DimStaff table with a StaffKey. Merged that withe SalaryData table and your fact table. Wanted to get rid of the names themselves
Then in the Salary data table, you can get the daily rate by using the following calculated column [Total Salary] / Duration.Days([End Date] - [Start Date])
In the Fact Table you can write the following calculated column which will go into the salary data table and pull out the correct average daily rate for the period in the fact table and multiple that rate by the “no of days” column in your fact table
Thanks for quick reply Nick.
The key thing in this exercise is the fact table. So you suggest to manually build the fact table with the year breakdown? Is there a way to do this automatically (Table 3 in your returned file)?
@kbi,
Sorry about that, this should be what you are after. Everything happens in the SalaryData table now (though I left the DimStaff table since would want to use that). You can click through the applied steps, but quickly:
Create a list of dates from the start and end date
Expand that out, then create a new column for start of year and end of year based on that column
Create a new column for Start Date to use. If the current start date > start of year, use the current start date, else use the Start of Year. Just the opposite for End date
Remove the other columns and only keep StaffKey, Start Use, End Date use, Total Salary and Daily Rate
Highlight StaffKey, Start Use, and End Date Use and remove duplicates
Subtract the EndDate Use and Start Use columns to get the No of Days
Multiply No of Days by Daily Rate, and this gives you the Total Yearly Salary
Remove columns you dont want and be sure to set data types