Forum Discussion
Power Query Editor: custom column based on another table
- 3 years ago
I found a solution. In the SupplierTbl, I can add rows for dates between start and end dates.
(following instructions I found here: https://natechamberlain.com/2018/08/08/how-to-add-rows-for-dates-between-start-and-end-dates-in-power-bi-date-range-data/)
That way, I can merge by matching MaterialNbr, Plant code, and Date.
Can you provide some sample data from both tables?
I haven't found a way to upload a file, so here are some screenshots.
- Syk3 years agoResident Rockstar
1. Go to your transaction table and click merge queries.
2. Select your material number and Plant code for both tables you want to join (hold ctrl for mutli select)3. You will now have a new column that says "Table" in every row. Click the little arrows that go opposite ways in the column title (see screenshot below).
4. Expand the columns you need for your transaction date logic.
5. Your table should look like this (with a few more fields, I didn't add all your columns)
6. Then go to Add Column > Custom Column> paste this (adjust column names as needed)
if [Transaction Date] >= [Contract Start Date] and [Contract End Date]=null then [Preferred Supplier] else if [Transaction Date] >= [Contract Start Date] and[Transaction Date] <= [Contract End Date] then [Preferred Supplier] else null7. Remove the columns you're using to calculate the new column and your table should look like this!
- lyderic3 years agoRegular Visitor
You've been very helpful, thank you! That works well, expect for one thing: I now have some duplicate row here and there. That seems to happen for a Material number that has 2 row or more in the SupplierTbl.
I need to hide these duplicate rows because I will later sum up the Cost and I don't want to double count. I'm working on it but if you have any suggestion in the meantime, I'll take it.- Syk3 years agoResident Rockstar
If your supplier table has duplicate records you can go to that table, select the fields that would make up a primary key and right click > deduplicate