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
deanbland
Helper III
Helper III

Unpivot a column based on its location, not name

Hi, 

 

I am trying to unpivot columns based on their position as the column headers are dynamic dates that change each month. 

 

How would I go about this?

 

Thank you!

6 REPLIES 6
deanbland
Helper III
Helper III

Hi @v-shex-msft , 

 

The basis of what you have done is correct, I just meant to unpivot them, but within the M query, not to use the column headers. 

 

The column headers change each month and so this would caue problems and so I would need to unpivot the columns without using the column header. 

 

Hope this makes a bit more sense? 

 

Regards, 

 

Dean

HI @deanbland,

Yes, it is possible, you may need to check the steps of getting and recognize data on your query table to remove the 'change data type' and 'promote header' operations.
Then you can refer to my sample formulas steps as I share to convert your records to date category with position attribute and correspond values.
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
v-shex-msft
Community Support
Community Support

Hi @deanbland,

Can you please share some dummy data with a similar data structure and expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@deanbland ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Hi @v-shex-msft & @amitchandak 

 

The dataset looks like this: 

 

01/01/202201/02/202201/03/202201/04/202201/05/202201/06/202201/07/202101/08/202101/09/202101/10/2021
000000111.20.36
1000.9900.590.6311.580.25
0000.3200.660.4810.320.99
000010.941.2310.081.35

As ststed above, I want to unpivot these columns by referencing their position within the table. 

 

Thank you! 

 

Dean

HI @deanbland,

Did you mean to transform your records to group them based on date and unpivot based on different positions?

1.png

If that is the case, you can take a look at the following formulas: (I transpose these records to vertical and unpivot on position fields)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY7ZDQAhCER78duwAspqLcb+21jFIyRrIpE3DEetLuDTHwUi5xXIAluIFpIFsfAOwAXZQjGAYULz/YYhXQJ3gM4GFrWjtUEpJ02agvDpS1kVSv89wHRSEf1iXo27OIbfDpyeEudtfJSgA4D7uvYB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t, Column10 = _t]),
    #"Transposed Table" = Table.Transpose(Source),
    #"Renamed Columns" = Table.RenameColumns(#"Transposed Table",{{"Column1", "Date"}, {"Column2", "P1"}, {"Column3", "P2"}, {"Column4", "P3"}, {"Column5", "P4"}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Renamed Columns", {"Date"}, "Attribute", "Value")
in
    #"Unpivoted Columns"

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help 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.