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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Grouping data and then merging cells

Hi all,

 

I'm facing a problem which Im struggling to find a solution for and hope I can get some help here:

 

I have a table with cat1, cat2, action name and action date.  What I want to do is group by cat1 & cat 2 and then merge the contents of the action name into a single cell (same applies to action date).

 

E.g:

 

Cat1 | Cat2 | ActionName | Date

A          AA          Hello            01/01/2018

A          AA          World           02/01/2018

 

Should transform to:

 

Cat1 | Cat2 | ActionName | Date

A          AA    Hello World   01/01/2018 02/01/2018

 

Thanks in advance!

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Please paste the following code into the advanced editor and follow the steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXIEER6pOTn5QNrAUB+IjAwMLZRidZDkw/OLclJA8kYI+VgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Cat1 = _t, Cat2 = _t, ActionName = _t, Date = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Cat1", "Cat2"}, {{"All", each _, type table}}),
    ActionName = Table.AddColumn(#"Grouped Rows", "ActionName", each Text.Combine([All][ActionName], " ")),
    Date = Table.AddColumn(ActionName, "Date", each Text.Combine([All][Date], " "))
in
    Date

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

1 REPLY 1
ImkeF
Community Champion
Community Champion

Please paste the following code into the advanced editor and follow the steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXIEER6pOTn5QNrAUB+IjAwMLZRidZDkw/OLclJA8kYI+VgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Cat1 = _t, Cat2 = _t, ActionName = _t, Date = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Cat1", "Cat2"}, {{"All", each _, type table}}),
    ActionName = Table.AddColumn(#"Grouped Rows", "ActionName", each Text.Combine([All][ActionName], " ")),
    Date = Table.AddColumn(ActionName, "Date", each Text.Combine([All][Date], " "))
in
    Date

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors