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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Alirezam
Helper V
Helper V

Transposing two column when there are consecuti

Hi friends, 

In Power Query, is it possible?

I have a table like this 

 

DateApr-21
MeterA
Reading1001
DateMay-21
MeterB
Reading1003
DateApr-21
MeterC
ReadingJun-21

 

And I want this table:

DateMeterReading
Apr-21A1001
May-21B1003
Apr-21C1008

 

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

Hi @Alirezam ,

Here is an option:

1. Add Index column (starting from 0)
2. Divide Index by 3 using Number.IntegerDivide function
3. Pivot first column using second column as values

ERD_0-1622184890951.png

4. Remove Index column

ERD_1-1622185433435.png

Code for everything:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckksSVXSUXIsKNI1MlSK1YlW8k0tSS0CCYF5QamJKZl56UC+oYEBRAFUi29iJboWJ0wtxshasNjijKnFQik2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),

    AddedIndex = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    IntegerDivided = Table.TransformColumns(AddedIndex,{{"Index", each Number.IntegerDivide(_, 3)}}),
    #"Pivoted Column" = Table.Pivot(IntegerDivided, List.Distinct(IntegerDivided[Column1]), "Column1", "Column2"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns"

 

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Sure thing, you can split the original table into 3 sub-tables; then transpose them.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckksSVXSUXIsKNI1MlSK1YlW8k0tSS0CCYF5QamJKZl56UC+oYEBRAFUi29iJboWJ0wtxshasNjijKnFQik2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Split Table" = Table.Split(Source, 3),
    #"Transposed Tables" = List.Transform(#"Split Table", each Table.PromoteHeaders(Table.Transpose(_))),
    #"Combined Tables" = Table.Combine(#"Transposed Tables")
in
    #"Combined Tables"

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

ERD
Community Champion
Community Champion

Hi @Alirezam ,

Here is an option:

1. Add Index column (starting from 0)
2. Divide Index by 3 using Number.IntegerDivide function
3. Pivot first column using second column as values

ERD_0-1622184890951.png

4. Remove Index column

ERD_1-1622185433435.png

Code for everything:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckksSVXSUXIsKNI1MlSK1YlW8k0tSS0CCYF5QamJKZl56UC+oYEBRAFUi29iJboWJ0wtxshasNjijKnFQik2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),

    AddedIndex = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    IntegerDivided = Table.TransformColumns(AddedIndex,{{"Index", each Number.IntegerDivide(_, 3)}}),
    #"Pivoted Column" = Table.Pivot(IntegerDivided, List.Distinct(IntegerDivided[Column1]), "Column1", "Column2"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns"

 

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors