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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
rnehrboss
Helper II
Helper II

Pivot/Unpivot Question

Having trouble thinking through this pivot/unpivot question transform.

I have data like this:

IDWhich fruits do you like?How many do you have?Which fruits do you like 2?How many do you have 2?Which fruits do you like 3?How many do you have 2?
101Apple4Plumb8Orange14
102Orange3Apple2Pear9
103Peach5Orange2Grapes11
104Grapes2Apple3Plumb12

 

I'm trying to get to data like this:

101Which FruitsApple4
102Which FruitsOrange3
103Which FruitsPeach5
104Which FruitsGrape5
101Which 2 Plumb8
102Which 2 Apple2
103Which 2 Orange2
104Which 2 Apple3
101Which 3Orange14
102Which 3Pear9
103Which 3Grapes11
104Which 3Plumb12

 

And finally to this (which is simply conditionally changing the Which 2 and 3's to which... so I think that's not hard)

101Which FruitsApple4
102Which FruitsOrange3
103Which FruitsPeach5
104Which FruitsGrape5
101Which FruitsPlumb8
102Which FruitsApple2
103Which FruitsOrange2
104Which FruitsApple3
101Which FruitsOrange14
102Which FruitsPear9
103Which FruitsGrapes11
104Which FruitsPlumb12

 

Any ideas?

Thanks!

 

4 REPLIES 4
DOLEARY85
Resident Rockstar
Resident Rockstar

Sorry forgot the last part - add a new column to that table for which fruits:

 

Column = "Which Fruits do You Like?"
 
DOLEARY85_0-1681492274577.png

 

 
DOLEARY85
Resident Rockstar
Resident Rockstar

Hi,

 

you could duplicate the table a couple of times and remove 2 of the which friuts and how many columns in each.

Rename all the columns to remove numbering and so they are the same in each table and then append them together, then just unpivot the which fruits column.

 

DOLEARY85_0-1681489894951.png

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

A great idea.  Problem is I have about 30 groups of these with 10 each.. So might become quite cumbersome.

Ah okay, you could create a calculated table with DAX in the data view:

 

t2 =
UNION(SUMMARIZE('Table (6)','Table (6)'[ID],'Table (6)'[Which fruits do you like?],'Table (6)'[How many do you have?]),SUMMARIZE('Table (6)','Table (6)'[ID],'Table (6)'[Which fruits do you like 2?],'Table (6)'[How many do you have 2?]),(SUMMARIZE('Table (6)','Table (6)'[ID],'Table (6)'[Which fruits do you like 3?],'Table (6)'[How many do you have 2?.1])))
 
DOLEARY85_0-1681491982620.png

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.