Forum Discussion
Assign Department from Audit Table
- 6 years ago
Hi, pedanticpad
Based on your data, you may create two calculated columns in 'Clock' table as follows.
COSTCODE = CALCULATE ( MAX ( 'Audit'[NewValue] ), FILTER ( 'Audit', 'Audit'[UserID] = 'Clock'[UserID] && 'Audit'[ChangeType] = "COSTCODE" && 'Audit'[ChangeDate] = CALCULATE ( MAX ( 'Audit'[ChangeDate] ), FILTER ( 'Audit', 'Audit'[ChangeDate] <= 'Clock'[Date] && 'Audit'[UserID] = 'Clock'[UserID] ) ) ) ) DEPARTMENT = CALCULATE ( MAX ( 'Audit'[NewValue] ), FILTER ( 'Audit', 'Audit'[UserID] = 'Clock'[UserID] && 'Audit'[ChangeType] = "DEPARTMENT" && 'Audit'[ChangeDate] = CALCULATE ( MAX ( 'Audit'[ChangeDate] ), FILTER ( 'Audit', 'Audit'[ChangeDate] <= 'Clock'[Date] && 'Audit'[UserID] = 'Clock'[UserID] ) ) ) )Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, pedanticpad
Based on your description, I assumed that two more rows for 5/1/2019 are needed and I created data as follows.
Employee data:
Department and CostCode:
You may duplicate query 'Employee data' and rename it as 'ResultTable'. Then you can go to 'Home' ribbon, click 'Merge Queries', configure as follows.
Then you need to expand the last column, remove the unrelated columns and rename other columns.
Finally you may make 'ChangeType' column selected, go to 'Transform' ribbon, click 'Pivot Column' and configure as below. You will get the result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- pedanticpad6 years agoHelper II
Hi v-alq-msft,
When I perform the pivot I get the below error;
There are alot of NULL values in the CHANGETYPE and NEWVALUE fields. I think the merge is only pulling in the data for an exact match and the other dates for each user is left as NULL.
I need to apply the department and cost code to every clock date so that for every clock before 05/01/2019 Department = Stores and CostCode = Store1, then for every clock from 02/25/2020 Department =Shipping and CostCode = Dock1. Any advice?
Thanks!
- v-alq-msft6 years agoCommunity Support
Hi, pedanticpad
I wonder the result of the last step before pivotting. Here is my result before pivotting.
If you have null in one column, you can click 'more options', choose what you want to filter.
Best Regards
Allan
- pedanticpad6 years agoHelper II
Hi v-alq-msft ,
See below step before the pivot;
I tried to filter out the null values but I got the below after pivoting;
Error;
Is the issue maybe that I am trying to do this against all employees not just one like in the example I gave?