Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Merge multiple rows with alternating null values in Power BI

Hello,

 

This is the data I have currently. I am trying to merge every 3 rows for each customer order. Because all cell values are the same for each order's aa to ee, I would like the data to be cleaned in a way that displays one order per row. 

aabbccddee202020212022
a1b1Customer 1d1e11nullnull
a1b1Customer 1d1e1null1null
a1b1Customer 1d1e1nullnull1
a2b2Customer 2d2e22nullnull
a2b2Customer 2d2e2null2null
a2b2Customer 2d2e2nullnull2
a3b3Customer 3d3e33nullnull
a3b3Customer 3d3e3null3null
a3b3Customer 3d3e3nullnull3
a4b4Customer 4d4e44nullnull
a4b4Customer 4d4e4null4null
a4b4Customer 4d4e4nullnull4

 

This is the output I'm looking for:

aabbccddee202020212022
a1b1Customer 1d1e1111
a2b2Customer 2d2e2222
a3b3Customer 3d3e3333
a4b4Customer 4d4e4444

 

How can I do this? Really appreciate your help!

 

  • Hi Anonymous ,

     

    You can use the Group By functionality. You can find this either on the transform tab of Power Query, or right click on a column header and select 'Group By' from the list.

     

    You will then need to select 'Advanced' and use your aa to ee columns as the groupings, and create aggregations for your years columns (I think SUM operation is appropriate for your use case). For example:

     

    Hope this helps!

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

     

    Your solution is great, BITomS . Here I have another idea in mind, and I would like to share it for reference.

     

    You can create a new table and use the DAX code as follows:

     

    CalculatedTable =
    SUMMARIZE(
        OriginalTable,
        OriginalTable[cc],
        "aa", MAX(OriginalTable[aa]),
        "bb", MAX(OriginalTable[bb]),
        "dd", MAX(OriginalTable[dd]),
        "ee", MAX(OriginalTable[ee]),
        "2020", MAX(OriginalTable[2020]),
        "2021", MAX(OriginalTable[2021]),
        "2022", MAX(OriginalTable[2022])
    )

     

    A new table CalculatedTable is created, and the result is as follows:

     

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Zhu
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Your solution is great, BITomS . Here I have another idea in mind, and I would like to share it for reference.

     

    You can create a new table and use the DAX code as follows:

     

    CalculatedTable =
    SUMMARIZE(
        OriginalTable,
        OriginalTable[cc],
        "aa", MAX(OriginalTable[aa]),
        "bb", MAX(OriginalTable[bb]),
        "dd", MAX(OriginalTable[dd]),
        "ee", MAX(OriginalTable[ee]),
        "2020", MAX(OriginalTable[2020]),
        "2021", MAX(OriginalTable[2021]),
        "2022", MAX(OriginalTable[2022])
    )

     

    A new table CalculatedTable is created, and the result is as follows:

     

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Zhu
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    • Anonymous's avatar
      Anonymous
      Not applicable

      This worked - thank you so much!

  • BITomS's avatar
    BITomS
    Icon for Solution Supplier rankSolution Supplier

    Hi Anonymous ,

     

    You can use the Group By functionality. You can find this either on the transform tab of Power Query, or right click on a column header and select 'Group By' from the list.

     

    You will then need to select 'Advanced' and use your aa to ee columns as the groupings, and create aggregations for your years columns (I think SUM operation is appropriate for your use case). For example:

     

    Hope this helps!

  • Anonymous's avatar
    Anonymous
    Not applicable

    This is perfect - thank you!