Forum Discussion
Merge 2 tables with Power BI Desktop
Hi All,
I am trying to merge two tables within Power BI; however, I am not getting the correct result.
First data set has the total time spent by an agent on a particular activity during the day and the second data set is a breakup of that time spent per application during that period.
So, the first table has around 10k rows, and the second table has 60k rows.
Ex - Table 1 is:
| Employee ID | Employee | Activity | Date | Start Time | End Time |
| 123 | Jeff | Call | 12-12-2020 | 10:00 AM | 10:15 AM |
| 123 | Jeff | Break | 12-12-2020 | 10:15 AM | 10:30 AM |
| 234 | Eric | Call | 12-12-2020 | 10:15 AM | 10:30 AM |
| 234 | Eric | Call | 12-12-2020 | 10:30 AM | 11:00 AM |
| 345 | Michael | Call | 12-12-2020 | 10:00 AM | 10:45 AM |
| 345 | Michael | Break | 12-12-2020 | 10:45 AM | 11:15 AM |
Ex – Table 2:
| Employee ID | Employee | Application | Date | Start Time | End Time |
| 123 | Jeff | Chrome | 12-12-2020 | 10:00 AM | 10:03 AM |
| 123 | Jeff | Outlook | 12-12-2020 | 10:04 AM | 10:09 AM |
| 123 | Jeff | Teams | 12-12-2020 | 10:10 AM | 10:15 AM |
| 123 | Jeff | Excel | 12-12-2020 | 10:16 AM | 10:25 AM |
| 123 | Jeff | Outlook | 12-12-2020 | 10:26 AM | 10:30 AM |
| 234 | Eric | Outlook | 12-12-2020 | 10:15 AM | 10:20 AM |
| 234 | Eric | Chrome | 12-12-2020 | 10:21 AM | 10:30 AM |
| 234 | Eric | Excel | 12-12-2020 | 10:31 AM | 10:40 AM |
| 234 | Eric | Teams | 12-12-2020 | 10:41 AM | 11:00 AM |
| 345 | Michael | Chrome | 12-12-2020 | 10:00 AM | 10:10 AM |
| 345 | Michael | Teams | 12-12-2020 | 10:11 AM | 10:20 AM |
| 345 | Michael | Outlook | 12-12-2020 | 10:21 AM | 10:30 AM |
| 345 | Michael | Excel | 12-12-2020 | 10:31 AM | 10:45 AM |
| 345 | Michael | Chrome | 12-12-2020 | 10:46 AM | 10:55 AM |
| 345 | Michael | Teams | 12-12-2020 | 10:56 AM | 11:05 AM |
| 345 | Michael | Outlook | 12-12-2020 | 11:06 AM | 11:15 AM |
Final Output should look like :
| Employee ID | Employee | Activity | Date | Start Time | End Time | Employee ID | Employee | Application | Date | Start Time | End Time |
| 123 | Jeff | Call | 12-12-2020 | 10:00 AM | 10:15 AM | 123 | Jeff | Chrome | 12-12-2020 | 10:00 AM | 10:03 AM |
| 123 | Jeff | Call | 12-12-2020 | 10:00 AM | 10:15 AM | 123 | Jeff | Outlook | 12-12-2020 | 10:04 AM | 10:09 AM |
| 123 | Jeff | Call | 12-12-2020 | 10:00 AM | 10:15 AM | 123 | Jeff | Teams | 12-12-2020 | 10:10 AM | 10:15 AM |
| 123 | Jeff | Break | 12-12-2020 | 10:15 AM | 10:30 AM | 123 | Jeff | Excel | 12-12-2020 | 10:16 AM | 10:25 AM |
| 123 | Jeff | Break | 12-12-2020 | 10:15 AM | 10:30 AM | 123 | Jeff | Outlook | 12-12-2020 | 10:26 AM | 10:30 AM |
| 234 | Eric | Call | 12-12-2020 | 10:15 AM | 10:30 AM | 234 | Eric | Outlook | 12-12-2020 | 10:15 AM | 10:20 AM |
| 234 | Eric | Call | 12-12-2020 | 10:15 AM | 10:30 AM | 234 | Eric | Chrome | 12-12-2020 | 10:21 AM | 10:30 AM |
| 234 | Eric | Call | 12-12-2020 | 10:30 AM | 11:00 AM | 234 | Eric | Excel | 12-12-2020 | 10:31 AM | 10:40 AM |
| 234 | Eric | Call | 12-12-2020 | 10:30 AM | 11:00 AM | 234 | Eric | Teams | 12-12-2020 | 10:41 AM | 11:00 AM |
| 345 | Michael | Call | 12-12-2020 | 10:00 AM | 10:45 AM | 345 | Michael | Chrome | 12-12-2020 | 10:00 AM | 10:10 AM |
| 345 | Michael | Call | 12-12-2020 | 10:00 AM | 10:45 AM | 345 | Michael | Teams | 12-12-2020 | 10:11 AM | 10:20 AM |
Would any of you have any ideas to do it please?
6 Replies
- AnonymousNot applicable
Hi ShreySharma
You can add a custom column in Table 1 in power query
Table.SelectRows(#"Table 2",(x)=>x[Employee ID]=[Employee ID] and x[Start Time]>=[Start Time] and x[End Time]<=[End Time])Then expanded the column
Output
You can also refer to the attachment.
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- ShreySharmaFrequent Visitor
Thanks for this Anonymous. I used the formula to create a new column, however, when I try and expand the column to get the columns from Table 2, I always get an error "No columns were found"
- AnonymousNot applicable
Hi ShreySharma
Did your table name is the same as i provided? the step i proveded, its table name is 'Table 2' .
Table.SelectRows(#"Table 2"(it should be your table name of the second table),(x)=>x[Employee ID]=[Employee ID] and x[Start Time]>=[Start Time] and x[End Time]<=[End Time])the did you add the custom column in table1? can you provide the step you created, the code can work in my sample, or your colum name is the same as i provided?
Best Regards!
Yolo Zhu
- ShreySharmaFrequent Visitor
Thanks for the quick response Anonymous . Yes, I am using the same column headers, however, still getting the same error. Here is the link to the .pbix file. https://1drv.ms/u/s!Agm6iBywR0VNjkzUwH-gqcl7xkoO?e=IxPeUD