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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kadoc
New Member

merge different rows in the same (according to a commun attribute)

Hello,

 

I would like to merge some rows in one (considering the same attribute) separated with semicolons

 

from this:

A r

A t

A g

A j

B f

B t
B g

C u

C i

 

To this:

A r; t; g; j

B f; t; g

C u; i

 

Can you help me please ?

Paul

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@kadoc,

This code should give you the expected result:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclQoUorVAdElUDodSmeBaSeFNChdAqUh8s4KpVA6Uyk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Column.1", "Column.2"}),
    #"Grouped Rows" = Table.Group(#"Split Column by Delimiter", {"Column.1"}, {{"AllData", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [AllData][Column.2]),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), "; "), type text}),
    #"Added Custom1" = Table.AddColumn(#"Extracted Values", "Result", each [Column.1] & " " & [Custom]),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"Result"})
in
    #"Removed Other Columns"

View solution in original post

1 REPLY 1
Anonymous
Not applicable

@kadoc,

This code should give you the expected result:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclQoUorVAdElUDodSmeBaSeFNChdAqUh8s4KpVA6Uyk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Column.1", "Column.2"}),
    #"Grouped Rows" = Table.Group(#"Split Column by Delimiter", {"Column.1"}, {{"AllData", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [AllData][Column.2]),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), "; "), type text}),
    #"Added Custom1" = Table.AddColumn(#"Extracted Values", "Result", each [Column.1] & " " & [Custom]),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"Result"})
in
    #"Removed Other Columns"

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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