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
thmonte
Helper IV
Helper IV

Properly unpivitoing columns for a dataset

If I have a dataset that looks like the following:

 

person

Attrib1Attrib2Attribute3Attrib1ValueAttrib2ValueAttrib3Value
JohnEyesFingersNose251
LouEyesFingersNose201

 

How do I turn it into something like this

 

nameattribamount
JohnEyes2
JohnFingers5
JohnNose1
LouEyes2
LouNose1

 

Typically when i research this issue the resolution is to always create multiple queries for each column pair and then append them to each other but to me thats the least pefromance friendly way as I have to load thousands of rows on a refresh and all these queires fill up my editor.

1 ACCEPTED SOLUTION

@v-eachen-msft  thank you for the response but i acheived the same thing using this other solution found here:

 

https://community.powerbi.com/t5/Desktop/Unpivot-Multiple-Coumns/td-p/442606

 

However, I'm not sure which is more performance friendly..

View solution in original post

5 REPLIES 5
v-eachen-msft
Community Support
Community Support

Hi @thmonte ,

 

You can follow these steps:

1. You need to replace "Attribute3" with "Attrib3".

2. Unpivot "Attrib1","Attrib2","Attrib3" columns.

3. After it, unpivot "Attrib1Value","Attrib2Value","Attrib3Value" columns.

4. Then, replace "Value" with "".

5. Open Advanced Editor, add an m query:

#"Remove Rows" = Table.SelectRows(#"Replaced Value",each ([Attribute]=[Attribute.1]) and ([Value.1]<>"0"))

6. Remove "Attribute" and "Attribute1" columns.

Here is the result.

3-1.PNG

You can download my test file from the link.
 

 

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

@v-eachen-msft  thank you for the response but i acheived the same thing using this other solution found here:

 

https://community.powerbi.com/t5/Desktop/Unpivot-Multiple-Coumns/td-p/442606

 

However, I'm not sure which is more performance friendly..

Hi @thmonte ,

 

I don't think there is any difference in performance. You can pick a method that is easier for you to understand.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
PattemManohar
Community Champion
Community Champion

@thmonte  Could you please confirm - Is the number of attribute columns (in this example, which are three attributes) is constant or it will also change dynamically ?





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




It's constant. In my case it's always 8 columns for each

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.