Forum Discussion
Add values into a different table
- 4 years ago
You can use Power Query to do this as you need to add new rows when employee 1002 doesn't have car category with some period and country IDs. Click "Transform data" to open Power Query Editor to transform tables.
Here are my steps to transform both tables:
Salary Table:
1. Filter "Employee ID" column to only have rows that Employee ID = 1001;
2. Replace "1001" with "1002" in "Employee ID" column;
3. Add a custom column whose value is "Car", column name is "Category";
4. Rename "Salary" column to "Expenses".
Now you will have below table, which has five columns whose names are totally consistent with those in Expenses Table. This is Employee 1002's Car expenses in every period and country.
Expenses Table:
5. Append above transformed Salary Table to Expenses Table;
6. Group rows by four columns and perform Sum on "Expenses" column;
7. Sort Rows.
Then you will have the following result. ( * In your sample data, Employee 1001 has country ID 2 and 1002 has country ID 3, which cannot be matched. So I changed both to country ID 2 to test it. )
In the following image, I have highlighted most features used to transform tables in above steps. Sample pbix is at bottom.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
You can use Power Query to do this as you need to add new rows when employee 1002 doesn't have car category with some period and country IDs. Click "Transform data" to open Power Query Editor to transform tables.
Here are my steps to transform both tables:
Salary Table:
1. Filter "Employee ID" column to only have rows that Employee ID = 1001;
2. Replace "1001" with "1002" in "Employee ID" column;
3. Add a custom column whose value is "Car", column name is "Category";
4. Rename "Salary" column to "Expenses".
Now you will have below table, which has five columns whose names are totally consistent with those in Expenses Table. This is Employee 1002's Car expenses in every period and country.
Expenses Table:
5. Append above transformed Salary Table to Expenses Table;
6. Group rows by four columns and perform Sum on "Expenses" column;
7. Sort Rows.
Then you will have the following result. ( * In your sample data, Employee 1001 has country ID 2 and 1002 has country ID 3, which cannot be matched. So I changed both to country ID 2 to test it. )
In the following image, I have highlighted most features used to transform tables in above steps. Sample pbix is at bottom.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Thank you very very much.
This is really complex. I need to test it and come back to you.
So sorry for the late reply. I didn't get a notice for your post.
Thank you very much again!