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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
andra2
Helper I
Helper I

Transform table structure

Hi, 

 

I have this Table 1 structure and I need to convert it to the Table 2  structure, mainly the values for the same ID to appear on a single row, separated by ;. Do you know how this can be achieved in Power Query?

Many thanks in advance for your support!

Table 1

IDValue
1a
1b
1c
2x
2y
2z

Table 2

IDValue
1a;b;c
2x;y;z
2 ACCEPTED SOLUTIONS
smpa01
Super User
Super User

@andra2 

let
    Source = Web.BrowserContents("https://community.powerbi.com/t5/Desktop/Transform-table-structure/m-p/2250024#M818814"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE:nth-child(6) > * > TR > :nth-child(1)"}, {"Column2", "TABLE:nth-child(6) > * > TR > :nth-child(2)"}}, [RowSelector="TABLE:nth-child(6) > * > TR"]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"Value", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"ad", each _, type table [ID=nullable number, Value=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each let x=[ad],
    y=x[Value]
    in Text.Combine(y,":")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"ad"})
in
    #"Removed Columns"
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

bcdobbs
Community Champion
Community Champion

1) Group by ID (leave it on count as we will change later)

bcdobbs_2-1640093162341.png

 

Results in:

bcdobbs_3-1640093199554.png

 

2) Go into the advanced editor and change the line:

 

    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Count", each Table.RowCount(_), Int64.Type}})

 

to 

#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Combined", each Text.Combine([Value], "; "), type text}})


Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

4 REPLIES 4
bcdobbs
Community Champion
Community Champion

1) Group by ID (leave it on count as we will change later)

bcdobbs_2-1640093162341.png

 

Results in:

bcdobbs_3-1640093199554.png

 

2) Go into the advanced editor and change the line:

 

    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Count", each Table.RowCount(_), Int64.Type}})

 

to 

#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Combined", each Text.Combine([Value], "; "), type text}})


Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Pragati11
Super User
Super User

HI @andra2 ,

 

You can create a calculated column as follows:

Column =
CONCATENATEX (
    FILTER (
        SUMMARIZE ( Table2, Table2[ID], Table2[Value] ),
        Table2[ID] = EARLIER ( Table2[ID] )
    ),
    Table2[Value],
    ";"
)

This gives you required result:

Pragati11_0-1640093504765.png

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Hi @smpa01 ,

 

Curious to know if my solution is not right.

Just want to understand what stopped you from accepting it as a solution? 🙂

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

smpa01
Super User
Super User

@andra2 

let
    Source = Web.BrowserContents("https://community.powerbi.com/t5/Desktop/Transform-table-structure/m-p/2250024#M818814"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE:nth-child(6) > * > TR > :nth-child(1)"}, {"Column2", "TABLE:nth-child(6) > * > TR > :nth-child(2)"}}, [RowSelector="TABLE:nth-child(6) > * > TR"]),
    #"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"Value", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"ad", each _, type table [ID=nullable number, Value=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each let x=[ad],
    y=x[Value]
    in Text.Combine(y,":")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"ad"})
in
    #"Removed Columns"
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.