Forum Discussion
Merge Date/Time tables with ranges
Little stuck on this project here.
I have two tables. One is a Hours Worked Table (shown at the top) and another is an Absence Table (shown second).
Then you see the expected result at the bottom.
Basically what i am trying to do is merge the hours worked table with the absence table to be able to account for the hours used while on the clock. The problem is the Absence table is in a range so i cant just join on dates since you see in the top example the manager entered the absence for 2 days.
It is just the range that is throwing me off and hoping someone can help.
- Anonymous3 years ago
Hi modxplus ,
According to your description, here are my steps you can follow as a solution.
(1) My test data is the same as yours.
(2) We can create two calculated columns .
Absence hours = var a= LOOKUPVALUE('Absence Table'[End],'Absence Table'[Name],[Name]) var b=LOOKUPVALUE('Absence Table'[Start],'Absence Table'[Name],[Name]) return SWITCH(TRUE(),[Date]=DATEVALUE(b)&&[Date]<DATEVALUE(a),HOUR([End Date/Time]-b),[Date]>DATEVALUE(b)&&[Date]<DATEVALUE(a),[Total Hours Worked],[Date]=DATEVALUE(a)&&[Date]=DATEVALUE(b),HOUR(a-b),[Date]=DATEVALUE(a)&&[Date]>DATEVALUE(b),HOUR(a-[Start Date/Time]),0)Absence Type = var a=LOOKUPVALUE('Absence Table'[Type],[Name],[Name]) return IF([Absence hours]<>0,a)(3) We can create a table.
Table = SUMMARIZE('Hours Worked Table',[Name],[Date],[Total Hours Worked],'Hours Worked Table'[Absence hours],[Absence Type])(4)Then the result is as follows.
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- AnonymousNot applicable
Hi modxplus ,
According to your description, here are my steps you can follow as a solution.
(1) My test data is the same as yours.
(2) We can create two calculated columns .
Absence hours = var a= LOOKUPVALUE('Absence Table'[End],'Absence Table'[Name],[Name]) var b=LOOKUPVALUE('Absence Table'[Start],'Absence Table'[Name],[Name]) return SWITCH(TRUE(),[Date]=DATEVALUE(b)&&[Date]<DATEVALUE(a),HOUR([End Date/Time]-b),[Date]>DATEVALUE(b)&&[Date]<DATEVALUE(a),[Total Hours Worked],[Date]=DATEVALUE(a)&&[Date]=DATEVALUE(b),HOUR(a-b),[Date]=DATEVALUE(a)&&[Date]>DATEVALUE(b),HOUR(a-[Start Date/Time]),0)Absence Type = var a=LOOKUPVALUE('Absence Table'[Type],[Name],[Name]) return IF([Absence hours]<>0,a)(3) We can create a table.
Table = SUMMARIZE('Hours Worked Table',[Name],[Date],[Total Hours Worked],'Hours Worked Table'[Absence hours],[Absence Type])(4)Then the result is as follows.
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AdoraiswamyRegular Visitor
I have two set of tables (Hour Start) (Hour End) that has data collected in every 30 minutes duration. Using Power Query How do I merge them to Hourly data.I have zero knowledge on DAX but exploring other transformation tools. Your help is highly appreciated. Thanks