Forum Discussion
Splitting row as another row by sequentially
Hi
I have the tables below.
Vendor Table
| Company | MaintAccount | IntercomVendorAccount | Vendor Amount |
| F008 | 11111 | ICV0001 | 9000 |
| F009 | 22222 | ICV0002 | 8000 |
| F010 | 22223 | ICV0003 | 7000 |
| F011 | 22224 | ICV0004 | 6000 |
| F012 | 22225 | ICV0005 | 5000 |
| F013 | 22226 | ICV0006 | 4000 |
| F014 | 22227 | ICV0007 | 3000 |
Customer Table
| Company | MaintAccount | IntercomVendorAccount | Customer Amount |
| F001 | 11111 | ICC0001 | 1000 |
| F002 | 22222 | ICC0002 | 2001 |
| F003 | 22223 | ICC0003 | 3000 |
| F004 | 22224 | ICC0004 | 4000 |
| F005 | 22225 | ICC0005 | 5000 |
| F006 | 22226 | ICC0006 | 6000 |
| F007 | 22227 | ICC0007 | 7000 |
Mapping Table (The customer table company,accountnumber is mapped to Vendor table company,accountnumber)
| CUSTOMERCOMPANYID | CUSTOMERACCOUNTNUMBER | VENDORCOMPANYID | VENDORACCOUNTNUMBER | ISTRADINGPARTNERSHIPACTIVE |
| F001 | ICC0001 | F008 | ICV0001 | Yes |
| F002 | ICC0002 | F009 | ICV0002 | Yes |
| F003 | ICC0003 | F010 | ICV0003 | Yes |
| F004 | ICC0004 | F011 | ICV0004 | Yes |
| F005 | ICC0005 | F012 | ICV0005 | Yes |
| F006 | ICC0006 | F013 | ICV0006 | Yes |
| F007 | ICC0007 | F014 | ICV0007 | Yes |
I set the relation in power bi below
After set the relation, I created a table in power bi. The results looks like below,
I would like to split the rows as sequentially like customer record after vendor record because the data contains transactions of customer to vendors and vendors to customers.
Expected result:
| Company | MainAccount | IntercomAccount | Company | Amount |
| F001 | 11111 | ICC0001 | F008 | 9000 -> Vend Amt |
| F008 | 11111 | ICV0001 | F001 | 1000->Cust Amt |
| F002 | 22222 | ICC0002 | F009 | 8000-> Vend Amt |
| F009 | 22222 | ICV0002 | F002 | 2001->Cust Amt |
| F003 | 22223 | ICC0003 | F010 | 7000-> Vend Amt |
| F010 | 22223 | ICV0003 | F003 | 3000->Cust Amt |
| F004 | 22224 | ICC0004 | F011 | 6000-> Vend Amt |
| F011 | 22224 | ICV0004 | F004 | 4000->Cust Amt |
Could you please advise.
Thanks
Vinoth SUSAINATHAN
Hi Vinothsusai ,
We can implement it in Query Editor. You can try the following steps.
- append the Vendor table and Customer table
- create a new column to combine the Vendor Amount column and Customer Amount column.
- remove the two Amount column.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tcu7DsMgDEDRX6mYM5hAXmMUqVKHrllQhohm6ICpIjr074tT18EL13BwTk0xvFb8qErd1yem0fv4xpTXG6Zt9zHMGz7ift7/9ssYjn2pnLoC9PlB09DHaQYAqiGffzHkvaYRQdWfQgMLI4KqK4RmYUVQtYWoWTQiqJpCGBatCCpbCMuiE0FlDrF8AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}}), #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]), #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Company", type text}, {"MaintAccount", Int64.Type}, {"IntercomVendorAccount", type text}, {"Vendor Amount", Int64.Type}}), #"Appended Query" = Table.Combine({#"Changed Type1", Customer}), #"Added Custom" = Table.AddColumn(#"Appended Query", "Custom", each if [Customer Amount] = null then [Vendor Amount] else [Customer Amount]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Vendor Amount", "Customer Amount"}), #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"MaintAccount", Order.Ascending}}) in #"Sorted Rows"I attached my sample that you can download.
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Kudos are nice too.
1 Reply
- v-xuding-msftCommunity Support
Hi Vinothsusai ,
We can implement it in Query Editor. You can try the following steps.
- append the Vendor table and Customer table
- create a new column to combine the Vendor Amount column and Customer Amount column.
- remove the two Amount column.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tcu7DsMgDEDRX6mYM5hAXmMUqVKHrllQhohm6ICpIjr074tT18EL13BwTk0xvFb8qErd1yem0fv4xpTXG6Zt9zHMGz7ift7/9ssYjn2pnLoC9PlB09DHaQYAqiGffzHkvaYRQdWfQgMLI4KqK4RmYUVQtYWoWTQiqJpCGBatCCpbCMuiE0FlDrF8AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}}), #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]), #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Company", type text}, {"MaintAccount", Int64.Type}, {"IntercomVendorAccount", type text}, {"Vendor Amount", Int64.Type}}), #"Appended Query" = Table.Combine({#"Changed Type1", Customer}), #"Added Custom" = Table.AddColumn(#"Appended Query", "Custom", each if [Customer Amount] = null then [Vendor Amount] else [Customer Amount]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Vendor Amount", "Customer Amount"}), #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"MaintAccount", Order.Ascending}}) in #"Sorted Rows"I attached my sample that you can download.
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Kudos are nice too.