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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
matheus_peppers
Frequent Visitor

Error when pivoting table

Hello, everyone. What's up?

I'm trying to make a pivot in my table that looks like this:

 

matheus_peppers_0-1666390374460.png

 

If you notice, the values that should be columns are repeated, because I added several tables, because I need a list view of all tables.

However, when I pivot, the following error occurs:

 

matheus_peppers_1-1666390456776.png

 

 

Can anyone help me by telling me what it could be, or what I can do to fix it and leave the list the way I want it, which is leaving the header at the top and the sequence of values at the bottom?

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @matheus_peppers ,
you need to create an additional column that creates a row number for the future table.
That will be calculated by adding an index column and applying a "Number.IntegerDivide"-operation on it with the number of of pivot column (rows for each batch).
Please paste the following code into the advanced editor and follow the steps:

 

let
    Source = Table.FromRows(
        Json.Document(
            Binary.Decompress(
                Binary.FromText(
                    "PcunFQAwCAXAXb6OSC8ybQoe+68RgsCdOSJMOASwIyxRVG1RUh1RVl1RUf1RbTQb3cawETyYHw==",
                    BinaryEncoding.Base64
                ),
                Compression.Deflate
            )
        ),
        let
            _t = ((type nullable text) meta [Serialized.Text = true])
        in
            type table [Column1 = _t, Column2 = _t]
    ),
    #"Changed Type" = Table.TransformColumnTypes(Source, {{"Column1", type text}, {"Column2", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Integer-Divided Column" = Table.TransformColumns(
        #"Added Index",
        {{"Index", each Number.IntegerDivide(_, 5), Int64.Type}}
    ),
    #"Pivoted Column" = Table.Pivot(
        #"Integer-Divided Column",
        List.Distinct(#"Integer-Divided Column"[Column1]),
        "Column1",
        "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

1 REPLY 1
ImkeF
Super User
Super User

Hi @matheus_peppers ,
you need to create an additional column that creates a row number for the future table.
That will be calculated by adding an index column and applying a "Number.IntegerDivide"-operation on it with the number of of pivot column (rows for each batch).
Please paste the following code into the advanced editor and follow the steps:

 

let
    Source = Table.FromRows(
        Json.Document(
            Binary.Decompress(
                Binary.FromText(
                    "PcunFQAwCAXAXb6OSC8ybQoe+68RgsCdOSJMOASwIyxRVG1RUh1RVl1RUf1RbTQb3cawETyYHw==",
                    BinaryEncoding.Base64
                ),
                Compression.Deflate
            )
        ),
        let
            _t = ((type nullable text) meta [Serialized.Text = true])
        in
            type table [Column1 = _t, Column2 = _t]
    ),
    #"Changed Type" = Table.TransformColumnTypes(Source, {{"Column1", type text}, {"Column2", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Integer-Divided Column" = Table.TransformColumns(
        #"Added Index",
        {{"Index", each Number.IntegerDivide(_, 5), Int64.Type}}
    ),
    #"Pivoted Column" = Table.Pivot(
        #"Integer-Divided Column",
        List.Distinct(#"Integer-Divided Column"[Column1]),
        "Column1",
        "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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors