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
ngct1112
Post Patron
Post Patron

Pivot columns with error

Hi All,

 

I am trying to pivot the the "column" but it shows error as "Expression.Error: There were too many elements in the enumeration to complete the operation.",

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIE4ZhSAwMj82KFsMSc0lSlWB2IlBMQG6HwjME8I9zajKAKDS3BXGMcKmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Column = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Column", type text}, {"Value", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Column]), "Column", "Value")
in
    #"Pivoted Column"

 

 

Source:

IDColumnValue
1AA's Value
1B2
1B3
2AA's Value
2B19
3AA's Value

 

Desired Output:

IDABB2
1A's Value23
2A's Value19 
3A's Value  

 

Appreciated if any idea!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@ngct1112 

You cannot Pivot as you have a duplicate of B for ID 1. You need to do some additional steps before performing Pivot.
Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes given below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nRR0lFyzs8pzc0DMsISc0pTlWJ1opUMgTxHEI4pNTAwMi9WQJVyAmIjFJ4xmGeEW5sRVKGhJZhrjENlLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"Column", type text}, {"Value", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"ID", "Column"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"All", each _, type table [ID=nullable number, Column=nullable text, Value=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([All],"Index",1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"ID", "Column", "Value", "Index"}, {"ID", "Column", "Value", "Index"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom", each if [Index] = 1 then [Column] else [Column] & Number.ToText([Index] )),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Column", "Index"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom]), "Custom", "Value")
in
    #"Pivoted Column"

Fowmy_0-1635751800317.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@ngct1112 

You cannot Pivot as you have a duplicate of B for ID 1. You need to do some additional steps before performing Pivot.
Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes given below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nRR0lFyzs8pzc0DMsISc0pTlWJ1opUMgTxHEI4pNTAwMi9WQJVyAmIjFJ4xmGeEW5sRVKGhJZhrjENlLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"Column", type text}, {"Value", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"ID", "Column"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"All", each _, type table [ID=nullable number, Column=nullable text, Value=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([All],"Index",1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"ID", "Column", "Value", "Index"}, {"ID", "Column", "Value", "Index"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom", each if [Index] = 1 then [Column] else [Column] & Number.ToText([Index] )),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Column", "Index"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom]), "Custom", "Value")
in
    #"Pivoted Column"

Fowmy_0-1635751800317.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

It looks good on my model. Appreciated

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.

Top Solution Authors