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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

When I 'Unpivot' certain columns, it alters the data in the whole model? - even unselected columns

My spreadsheet contains a lot of dates as colums and I want to 'unpivot' these so they collapse into one column. When I select the columns that I want to be affected, the whole spreadhseet ends up changing, even the columns I did not select. 

 

I can't figure out what is causing the change? I worked on an older version of this spreadsheet and never had this problem. 

 

I have attached two images showing a before and after.

 

 

 

The dates to the right are what I want to condense into one column. the information to the left I can organise properly in the visualisation. 

PBI before.PNG

 

I am selecting the columns to the left as there is only about 7/8 and then doing Transform>Unpivot Other Columns.

 

But this changes the whole spreadsheet as you can see below.

 

PBI after.PNG

 

Any tips would be much appreciated!

 

Cheers

1 ACCEPTED SOLUTION
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

Please note that definition of unpivot column:

Capture.PNG

If you'd like to merge several columns into one column,I'd like to suggest below M code: (Select Date1&2&3, then unpivot)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTIEYiMDQ0t9Q30jIBOEYnWilZJAwhA+VNYYJpUMZBhDlcJlTZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Date1 = _t, Date2 = _t, Date3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column1", "Column2"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each [Value] <> null and [Value] <> "")
in
    #"Filtered Rows"

0.PNG1.PNG

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

View solution in original post

1 REPLY 1
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

Please note that definition of unpivot column:

Capture.PNG

If you'd like to merge several columns into one column,I'd like to suggest below M code: (Select Date1&2&3, then unpivot)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTIEYiMDQ0t9Q30jIBOEYnWilZJAwhA+VNYYJpUMZBhDlcJlTZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Date1 = _t, Date2 = _t, Date3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column1", "Column2"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each [Value] <> null and [Value] <> "")
in
    #"Filtered Rows"

0.PNG1.PNG

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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