Forum Discussion

Vinothsusai's avatar
Vinothsusai
Helper III
6 years ago
Solved

Splitting row as another row by sequentially

Hi

I have the tables below. 

Vendor Table

 

CompanyMaintAccountIntercomVendorAccountVendor Amount
F00811111ICV00019000
F00922222ICV00028000
F01022223ICV00037000
F01122224ICV00046000
F01222225ICV00055000
F01322226ICV00064000
F01422227ICV00073000

 

Customer Table

CompanyMaintAccountIntercomVendorAccountCustomer Amount
F00111111ICC00011000
F00222222ICC00022001
F00322223ICC00033000
F00422224ICC00044000
F00522225ICC00055000
F00622226ICC00066000
F00722227ICC00077000

 

Mapping Table (The customer table company,accountnumber is mapped to Vendor table company,accountnumber)

 

CUSTOMERCOMPANYIDCUSTOMERACCOUNTNUMBERVENDORCOMPANYIDVENDORACCOUNTNUMBERISTRADINGPARTNERSHIPACTIVE
F001ICC0001F008ICV0001Yes
F002ICC0002F009ICV0002Yes
F003ICC0003F010ICV0003Yes
F004ICC0004F011ICV0004Yes
F005ICC0005F012ICV0005Yes
F006ICC0006F013ICV0006Yes
F007ICC0007F014ICV0007Yes

 

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:

 

CompanyMainAccountIntercomAccountCompanyAmount
F00111111ICC0001F0089000 -> Vend Amt
F00811111ICV0001F0011000->Cust Amt
F00222222ICC0002F0098000-> Vend Amt
F00922222ICV0002F0022001->Cust Amt
F00322223ICC0003F0107000-> Vend Amt
F01022223ICV0003F0033000->Cust Amt
F00422224ICC0004F0116000-> Vend Amt
F01122224ICV0004F0044000->Cust Amt

 

Could you please advise.

 

Thanks

Vinoth SUSAINATHAN

 

 

  • Hi Vinothsusai ,

    We can implement it in Query Editor.  You can try the following steps.

    1. append the Vendor table and Customer table 
    2. create a new column to combine the Vendor Amount column and Customer Amount column.
    3. 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-msft's avatar
    v-xuding-msft
    Community Support

    Hi Vinothsusai ,

    We can implement it in Query Editor.  You can try the following steps.

    1. append the Vendor table and Customer table 
    2. create a new column to combine the Vendor Amount column and Customer Amount column.
    3. 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.