Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

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!

 

2 ACCEPTED SOLUTIONS
BITomS
Responsive Resident
Responsive Resident

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:

 

BITomS_0-1720542638360.png

Hope this helps!

View solution in original post

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:

 

vlinhuizhmsft_0-1720579472833.png

 

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!

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

This is perfect - thank you!

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:

 

vlinhuizhmsft_0-1720579472833.png

 

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
Not applicable

This worked - thank you so much!

BITomS
Responsive Resident
Responsive Resident

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:

 

BITomS_0-1720542638360.png

Hope this helps!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors