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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Maheshwari
Regular Visitor

Rearrange data using power query

I have the below sample data in excel.(Either one)

 

PartA
1name
2namee
3nameee
PartB
1value
2valuee
3valueee
4valueeee
PartC
1key
2keyy

 or 

Part123 
Anamenameenameee 
Part1234
Bvaluevalueevalueeevalueeee
Part12  
Ckeykeyy  

 

I wanna convert this into below format(Either one)

 

PartABC
1namevaluekey
2nameevalueekeyy
3nameeevalueee 
4 valueeee

 

or

Part1234
Anamenameenameee 
Bvaluevalueevalueeevalueeee
Ckeykeyy  
2 ACCEPTED SOLUTIONS
ImkeF
Community Champion
Community Champion

Hi @Maheshwari ,

you need to add a column that identifies the group and then pivot on it:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgsKlHSUXJUitWJVjIEsvISc1PBHCMoB8IzhvEgXKg2J7i2ssScUoQ+MA+hEcKF8E0QfBSjnOFGZadWwg0CsoGcWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column1" = _t, #"Column2" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "GroupIdentifier", each if [Column1] = "Part" then [Column2] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"GroupIdentifier"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Column1] <> "Part")),
    #"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[GroupIdentifier]), "GroupIdentifier", "Column2")
in
    #"Pivoted Column"

 

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

Anonymous
Not applicable

 

let
    Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgsKlHSUXJUitWJVjIEsvISc1PBHCMoB8IzhvEgXKg2J7i2ssScUoQ+MA+hEcKF8E0QfBSjnOFGZadWwg0CsoGcWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Colonna1 = _t, Colonna2 = _t]),
    posPart=List.PositionOf(Origine[Colonna1],"Part",Occurrence.All)&{List.Count(Origine[Colonna2])},
    splc2=List.Transform({0..List.Count(posPart)-2}, each List.Range(Origine[Colonna2],posPart{_},posPart{_+1}-posPart{_})),
    tfc=Table.FromColumns(splc2),
    #"Intestazioni alzate di livello" = Table.PromoteHeaders(tfc, [PromoteAllScalars=true])
in
    #"Intestazioni alzate di livello"

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

 

let
    Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgsKlHSUXJUitWJVjIEsvISc1PBHCMoB8IzhvEgXKg2J7i2ssScUoQ+MA+hEcKF8E0QfBSjnOFGZadWwg0CsoGcWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Colonna1 = _t, Colonna2 = _t]),
    grp = Table.Group(Origine, {"Colonna1"}, {{"part", each _[Colonna2]}, {"row", each _[Colonna1]}}, GroupKind.Local, (x,y)=>Number.From(y=x) ),
    prt=List.Max(grp[row],null, List.Count),
    tfc=Table.FromColumns({prt}&grp[part]),
    #"Intestazioni alzate di livello" = Table.PromoteHeaders(tfc, [PromoteAllScalars=true])
in
    #"Intestazioni alzate di livello"

 

Anonymous
Not applicable

 

let
    Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgsKlHSUXJUitWJVjIEsvISc1PBHCMoB8IzhvEgXKg2J7i2ssScUoQ+MA+hEcKF8E0QfBSjnOFGZadWwg0CsoGcWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Colonna1 = _t, Colonna2 = _t]),
    posPart=List.PositionOf(Origine[Colonna1],"Part",Occurrence.All)&{List.Count(Origine[Colonna2])},
    splc2=List.Transform({0..List.Count(posPart)-2}, each List.Range(Origine[Colonna2],posPart{_},posPart{_+1}-posPart{_})),
    tfc=Table.FromColumns(splc2),
    #"Intestazioni alzate di livello" = Table.PromoteHeaders(tfc, [PromoteAllScalars=true])
in
    #"Intestazioni alzate di livello"

 

ImkeF
Community Champion
Community Champion

Hi @Maheshwari ,

you need to add a column that identifies the group and then pivot on it:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgsKlHSUXJUitWJVjIEsvISc1PBHCMoB8IzhvEgXKg2J7i2ssScUoQ+MA+hEcKF8E0QfBSjnOFGZadWwg0CsoGcWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column1" = _t, #"Column2" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "GroupIdentifier", each if [Column1] = "Part" then [Column2] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"GroupIdentifier"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Column1] <> "Part")),
    #"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[GroupIdentifier]), "GroupIdentifier", "Column2")
in
    #"Pivoted Column"

 

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