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
jthomson
Solution Sage
Solution Sage

Pivoting/unpivoting/grouping help needed

Hi,

 

I've got a bunch of data where the main ID of each case is of the format 123456X, where 123456 is the main case number, and X is an optional ending to indicate a case type. I'm needing to group everything by the main case number, but retain the information in all other columns, making a duplicate column for each possible case type with the case type within the column name (kind of how it works when you expand a table after a merge of queries) - so something like this, very simplified, once I've separated out the main ID field into case number and case type:

 

pbiforum1.PNG

 

I could do this by duplicating the queries for each possible case type, filtering on the case type column and then merging everything back together, but I'm thinking there's got to be a more efficient way to do this which doesn't require duplication (there's about 8-9 different case types and the potential for more to be added later) and have lots and lots of intermediate queries. I'm sure I've seen something similar on the forums before but for the life of me I can't find it. Any ideas on how to get this done?

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi  @jthomson,

 

What visual do you want to show the data? Table or Matrix? Matrix  should be easier.

 

1.Go to Query Qditor and select columns data1 and data2 then click Unpivot Column.

 

2. Then combine the column data and type by adding a custom column.

 

Capture.PNG

3. You could remove the columns type and Attribute, apply and Close.

 

4.Create the matrix with columns case, custom and values.

 

matrix.PNG 

If you want to show as table, you may add one more step after the step 2 above in Query Editor.

You need pivot the column custom.

 

pivotpng.png

 

Then you will get the new table like below.

 

table.PNG

 

Hope this can help you!

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
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

3 REPLIES 3
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi  @jthomson,

 

What visual do you want to show the data? Table or Matrix? Matrix  should be easier.

 

1.Go to Query Qditor and select columns data1 and data2 then click Unpivot Column.

 

2. Then combine the column data and type by adding a custom column.

 

Capture.PNG

3. You could remove the columns type and Attribute, apply and Close.

 

4.Create the matrix with columns case, custom and values.

 

matrix.PNG 

If you want to show as table, you may add one more step after the step 2 above in Query Editor.

You need pivot the column custom.

 

pivotpng.png

 

Then you will get the new table like below.

 

table.PNG

 

Hope this can help you!

 

Best Regards,

Cherry

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

Think either I've not been clear or you've misunderstood what I'm after - I need the data model to look like the end result, I'm not going to show that output in a visual, but with some tweaks to what you've suggested with the pivoting step I think I've got it to work, cheers

Hi  @jthomson,

 I need the data model to look like the end result, I'm not going to show that output in a visual, but with some tweaks to what you've suggested with the pivoting step I think I've got it to work, cheers


 

For your this requirement, you could refer to the second way I have replied first time. 

 

After the transform in Query Editor, you could get the data model look like the end result.

 

table.PNG

 

It seems that you have found the solution, only thing that you'll have to notice, just always share your solution or accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
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.