radonwilson
Board Regular
- Joined
- Jun 23, 2021
- Messages
- 50
- Office Version
- 2019
- Platform
- Windows
- I want to split each row in Order Table into 2 separate rows where the quantity does not match the quantity given in Refund Table and further mark them as "Partial Order" and "Partial Return".
- With the help of the unitary method, I want to split their values as well. (refer to the result table).
- I want to add a column named Refund_Com to add values of [Referral]/1.18 column of Refund_Table with [Referral] column of Order Table where the Tag is mentioned as "Partial_Return".
- If there is an OrderID that is present in both the tables and where the order quantity matches, then It should be tagged as "Full_Refund". And If an order id is present only in the order's table then it should be marked as "Order".
Here is my M CODE:-
Power Query:
let
Source = Excel.CurrentWorkbook(){[Name="Order"]}[Content],
Tags = Table.AddColumn(Source, "Tags", each
let
MyList = List.PositionOf(Refund[OrderID],[OrderID])
in
if MyList = -1 then {"Order"}
else if Refund[Qty]{MyList} = [Qty] then {"Full Refund"}
else if Refund[Qty]{MyList} <> [Qty] then {"Partial_Order","Partial_Return"}
else null),
Expanded_Tags = Table.ExpandListColumn(Tags, "Tags")
in
Expanded_Tags
Orders Table
OrderID | SKU | Qty | Base_Amount | O_Tax | TCS | Referral | Closing | I_Tax | Total |
407-4389736 | FDR0028 | 2 | 1,158.92 | 139.08 | -11.58 | -201.2 | -60 | -47.016 | 978.2 |
407-4389778 | FDR0056 | 2 | 1,069.64 | 128.36 | -10.7 | -119.8 | -60 | -32.364 | 975.1 |
407-4389665 | FDR0056 | 5 | 2,674.10 | 320.9 | -26.75 | -299.5 | -150 | -80.91 | 2437.8 |
407-4389224 | FDR0012 | 1 | 592.37 | 106.63 | -5.9237 | -69.9 | -30 | -17.98 | 575.2 |
407-4389758 | FDR0085 | 2 | 1,069.64 | 128.36 | -10.7 | -119.8 | -60 | -32.364 | 975.14 |
Refund Table
OrderID | SKU | Qty | Base_Amount | Tax | TCS | Referral | Closing | Total |
407-4389736 | FDR0028 | 1 | -579.46 | -69.54 | 5.79 | 6.61 | 35.4 | -601.2 |
407-4389778 | FDR0056 | 1 | -534.82 | -64.18 | 5.35 | -41.49 | 35.4 | -593.35 |
407-4389665 | FDR0056 | 2 | -1,069.64 | -128.36 | 10.7 | -82.98 | 70.8 | -1,199.48 |
407-4389224 | FDR0012 | 1 | -592.37 | -106.63 | 5.92 | -29.618 | 35.4 | -682.78 |
Modified/Result_Order Table
OrderID | SKU | Qty | Base_Amount | O_Tax | TCS | Referral | Closing | I_Tax | Total | Refund_Com | Tag |
407-4389736 | FDR0028 | 1 | 579.46 | 69.54 | -5.79 | -100.6 | -30 | -23.51 | 489.1 | Partial Order | |
407-4389736 | FDR0028 | 1 | 579.46 | 69.54 | -5.79 | -100.6 | -30 | -23.51 | 489.1 | -95 | Partial Return |
407-4389778 | FDR0056 | 1 | 534.82 | 64.18 | -5.35 | -59.9 | -30 | -16.182 | 487.6 | Partial Order | |
407-4389778 | FDR0056 | 1 | 534.82 | 64.18 | -5.35 | -59.9 | -30 | -16.182 | 487.6 | -95 | Partial Return |
407-4389665 | FDR0056 | 3 | 1,604.46 | 192.54 | -16.05 | -179.7 | -90 | -48.546 | 1462.7 | Partial Order | |
407-4389665 | FDR0056 | 2 | 1,069.64 | 128.36 | -10.7 | -119.8 | -60 | -32.364 | 975.1 | -190 | Partial Return |
407-4389224 | FDR0012 | 1 | 592.37 | 106.63 | -5.9237 | -69.9 | -30 | -17.98 | 575.2 | Full Return | |
407-4389758 | FDR0085 | 2 | 1,069.64 | 128.36 | -10.7 | -119.8 | -60 | -32.364 | 975.14 | Order |