Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
I need help changing a table from multiple rows to a grouped by and then into a single row see example. I need to be able to do this in Power Query.
Solved! Go to Solution.
Assuming the row structure will always be repeated,
Try:
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"fZHRasMwDEV/Rfg5MNLB3l1ZSbwkkpGdZqX0/39j2kq7mC71o3x0L/fqcnFt2368u8blJSfCAh5LFN4MlGY5UYCkkuAN0OfBXZu/xZnKIAGkA+KiZ5uwQCeKVGFJIpct1Xv1PYFp60A+QBDRaoNOMRCbjC1HLItS3v1XE887fl+x3Ox6/8rOI8qcpohm07iFR5aVf4nDz/uvouOiUz95i7PFngtZIwdZK+ipjk6FS4Vs8h1VRmIwr5z3GBUcdyxuDTwS34E68aeQlWJHu34D",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [ID = _t, groupdesc = _t, itemdescp = _t]
),
#"Changed Type" = Table.TransformColumnTypes(
Source,
{{"ID", Int64.Type}, {"groupdesc", type text}, {"itemdescp", type text}}
),
#"Reordered Columns" = Table.ReorderColumns(#"Changed Type", {"groupdesc", "itemdescp", "ID"}),
#"Added Index" = Table.AddIndexColumn(#"Reordered Columns", "Index", 1, 1, Int64.Type),
#"Inserted Modulo" = Table.AddColumn(
#"Added Index",
"Modulo",
each Number.Mod([Index], 7),
type number
),
#"Added Conditional Column" = Table.AddColumn(
#"Inserted Modulo",
"Custom",
each if [Modulo] = 5 then "EVIDENCE 1" else [groupdesc]
),
#"Removed Columns" = Table.RemoveColumns(
#"Added Conditional Column",
{"groupdesc", "Index", "Modulo"}
),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns", {{"Custom", "GroupDesc"}}),
#"Pivoted Column" = Table.Pivot(
#"Renamed Columns",
List.Distinct(#"Renamed Columns"[GroupDesc]),
"GroupDesc",
"itemdescp"
)
in
#"Pivoted Column"
Proud to be a Super User!
Paul on Linkedin.
I was abel to take your code an tweak it with the fields I needed and it worked perfectly. Thank you for your insight and knowledge.
Thank you, however I need this as a table to use in power query. Is there a way to do this in power query?
Assuming the row structure will always be repeated,
Try:
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"fZHRasMwDEV/Rfg5MNLB3l1ZSbwkkpGdZqX0/39j2kq7mC71o3x0L/fqcnFt2368u8blJSfCAh5LFN4MlGY5UYCkkuAN0OfBXZu/xZnKIAGkA+KiZ5uwQCeKVGFJIpct1Xv1PYFp60A+QBDRaoNOMRCbjC1HLItS3v1XE887fl+x3Ox6/8rOI8qcpohm07iFR5aVf4nDz/uvouOiUz95i7PFngtZIwdZK+ipjk6FS4Vs8h1VRmIwr5z3GBUcdyxuDTwS34E68aeQlWJHu34D",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [ID = _t, groupdesc = _t, itemdescp = _t]
),
#"Changed Type" = Table.TransformColumnTypes(
Source,
{{"ID", Int64.Type}, {"groupdesc", type text}, {"itemdescp", type text}}
),
#"Reordered Columns" = Table.ReorderColumns(#"Changed Type", {"groupdesc", "itemdescp", "ID"}),
#"Added Index" = Table.AddIndexColumn(#"Reordered Columns", "Index", 1, 1, Int64.Type),
#"Inserted Modulo" = Table.AddColumn(
#"Added Index",
"Modulo",
each Number.Mod([Index], 7),
type number
),
#"Added Conditional Column" = Table.AddColumn(
#"Inserted Modulo",
"Custom",
each if [Modulo] = 5 then "EVIDENCE 1" else [groupdesc]
),
#"Removed Columns" = Table.RemoveColumns(
#"Added Conditional Column",
{"groupdesc", "Index", "Modulo"}
),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns", {{"Custom", "GroupDesc"}}),
#"Pivoted Column" = Table.Pivot(
#"Renamed Columns",
List.Distinct(#"Renamed Columns"[GroupDesc]),
"GroupDesc",
"itemdescp"
)
in
#"Pivoted Column"
Proud to be a Super User!
Paul on Linkedin.
thank you so much, however I am getting a small issue when I am using my actual source data. please see code below:
let
Source = lwmodop,
#"Changed Type" = Table.TransformColumnTypes(
Source,
{{"lwmainid", Int64.Type}, {"groupdesc", type text}, {"itemdesc", type text}}
),
#"Reordered Columns" = Table.ReorderColumns(#"Changed Type", {"groupdesc", "itemdesc", "lwmainid"}),
#"Added Index" = Table.AddIndexColumn(#"Reordered Columns", "Index", 1, 1, Int64.Type),
#"Inserted Modulo" = Table.AddColumn(
#"Added Index",
"Modulo",
each Number.Mod([Index], 7),
type number
),
#"Added Conditional Column" = Table.AddColumn(
#"Inserted Modulo",
"Custom",
each if [Modulo] = 5 then "EVIDENCE 1" else [groupdesc]
),
#"Removed Columns" = Table.RemoveColumns(
#"Added Conditional Column",
{"groupdesc", "Index", "Modulo"}
),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns", {{"Custom", "GroupDesc"}}),
#"Pivoted Column" = Table.Pivot(
#"Renamed Columns",
List.Distinct(#"Renamed Columns"[GroupDesc]),
"GroupDesc",
"itemdesc"
),
#"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"mogroup", "moitem", "lwmodopid", "addtime", "adduser", "mobilepkey", "origmfrrec", "ismfrrec"}),
#"Filtered Rows" = Table.SelectRows(#"Removed Columns1", each ([lwmainid] = 106))
in
#"Filtered Rows"
The problem is that you have many more fields than the sample data you posted. There is also an issue in the sample data which needs to be solved: you have two rows where the value is "Evidence" in both, and you cannot have two columns with the same name (hence the importance of having the same row structure...)
Proud to be a Super User!
Paul on Linkedin.
@cisyncllc , Matrix visual
Id on row, Group Desc of COlumn
and max of Itemdesc on value
https://docs.microsoft.com/en-us/power-bi/visuals/desktop-matrix-visual
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!