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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Will_Smith
Regular Visitor

Is there an easy way to sort data per type in power query?

Hi, 

Can I sort data from the table on the left (type A & B mixed in one column)to to the table on the right each type has its own qty column?
table a.pngtable b.png

8 REPLIES 8
mussaenda
Super User
Super User

Hi @Will_Smith ,

 

mussaenda_0-1693389115125.png

 

ToddChitt
Super User
Super User

Sorry, I missunderstood your original post. I thought the table on the right was what you wanted to GET to. But that is one of the tables you already have? So what are you trying to do here? What would your final data look like?




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





No, you understood my original post right. I want my final data look like table B, the one on the right. 

My final goal is for table B to table A's connection to the SQL server. I have 2 senarios for solution:

 

1, Pivot. My understanding is once I do a pivot, my pivot table will be updated as my table A getting refreshed from the SQL server.  If I merge this pivot to table B, would table B gets updated as table A?

 

2, Sort table A  the same format like table B, then merge table A to table B so table B would have the same connection to SQL server and updates as the database update.

 

I thought senario 2, might be more straight forward, then I posted my original quetion.

 

 

 

So your data coming out of SQL Server looks like Table A, on thge left. What in your data tell you that the value of 10091 for A should be on the same row as 20024 for B? Is/are there some other column(s) involved?




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Yes and yes, there are other columns involved.

I will ask again: What in your data tell you that the value of 10091 for A should be on the same row as 20024 for B? Can you include that in the sample data?

 

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0MLA0BNFKsTrRSk5AlpGBgZEJXASmxhhIG6OoMYOIxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t, QTY = _t, ID = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"QTY", Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Type]), "Type", "QTY", List.Sum)
in
#"Pivoted Column"




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Will_Smith
Regular Visitor

Hi ToddChitt, 

 

I got the left hand side table (A)  from SQL server, and planning to merge A to the right hand side table (B), so the data for Type_A_QTY and Type_B_QTY stays up to date.

 

If I do a Pivot from Table A then merge to Table B, would the data in Table B get update when the data in my SQL server updates?

 

Thank you!

ToddChitt
Super User
Super User

You should do a PIVOT operation in Power Query. Do you have some other column in there so you don't get a full SUM




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.