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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

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
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.