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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
cisyncllc
Frequent Visitor

Need Help with cross Tab table

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.

 

Cross tab table.JPG

1 ACCEPTED 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"

Captura de pantalla 2022-08-29 181819.png





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

7 REPLIES 7
cisyncllc
Frequent Visitor

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.  

cisyncllc
Frequent Visitor

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"

Captura de pantalla 2022-08-29 181819.png





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

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





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






cisyncllc_0-1661794477928.png

 

amitchandak
Super User
Super User

@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

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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
Top Kudoed Authors