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
adavid999
Helper V
Helper V

Pivot columns

Hello,

I would like to pivot a column in my query that will go from this:

 

IDChoice
1A
2A
3A
3B
4A
5A
5B

to this:

 

IDChoice1Choice2
1A 
2A 
3AB
4A 
5AB

When I try to do this I receive an error message. I am very new to this so hopefully something simple I am not doing?

Many thanks,

A

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi @adavid999 ,

 

Go to edit queries >click on the column"Choice">"Add Column">"Conditional Column">then create 2 columns as below:

Annotation 2020-01-30 122215.pngAnnotation 2020-01-30 122526.pngAnnotation 2020-01-30 122552.png

 

And you will see:

Annotation 2020-01-30 122743.png

Then choose  close and apply :

Annotation 2020-01-30 122826.png

 

Finally, you need to create a new table using a dax expression as below:

 

 

Table 2 =
SUMMARIZE (
    'Table',
    'Table'[ID],
    "Choice 1", MAX ( 'Table'[Custom] ),
    "Choice 2", MAX ( 'Table'[Custom.1] )
)

 

And you will see :

 

Annotation 2020-01-30 123043.png

 

For the related .pbix file,pls click here.

 

Best Regards,
Kelly

 

Dear @v-kelly-msft ,

 

Thank you this worked! (and if you have time/patience) if there are other exisitng fields I would like to bring into the new table, linked to choices, how would I do this? So this:

IDChoiceColour
1ARed
2AGreen
3ARed
3BGreen
4ARed
5BGreen
5ARed

Would become

IDChoice1Choice2Colour1Colour2
1A   
2A   
3ABRedGreen
4A Red 
5BAGreenRed

 

In effect I guess I am asking how to transpose rows to columns within a table, while maintining link to unique id. I'm not sure if I have explained it clearly!

 

Many thanks,

 

Adam

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.