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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
PhilippeMuniesa
Resolver I
Resolver I

powerquery sort based on two columns

hello,

 

I have a table with three columns, and I would like to sort on 2 columns,

I do not find how to do.

While waiting for a relevant solution, I merged the two columns and sorted it out, but I think there is more efficiency.

 

I attach an excel file with the starting table and the desired result.

 

https://www.dropbox.com/t/DsQFZmgLoay8YUNK

 

Thnaks a lot

 

Philippe

7 REPLIES 7
lbendlin
Super User
Super User

How Power Query Thinks: Taking the Mystery Out of Streaming and Query Folding (Video) | Ben Gribaudo

 

Sorting is covered around the 20:00 mark but you will want to watch the entire video, multiple times.

lbendlin
Super User
Super User

Sort by the first column. Sort by the second column.  You will see little numbers appear

 

lbendlin_0-1672700606266.png

 

Or you can do it in code.

 

Note:  Sorting in Power Query is a red flag/code smell.  In the vast majority of cases you do not need/want to sort your data in Power Query.

@lbendlin 

Can you explain shortly why it is not a good idea to sort data in PQ ?

@Einomi did you watch the video?

@lbendlin 

Can you explain shortly why it is not a good idea to sort data in PQ ?

Hi! I'm not sure why PQ strips out sorting when merging queries sometimes, but the fix is this:
- After sorting the columns, click on the "fx" button in the formula bar (on the left)
- Put the code after the "=" in parenthesis, and add the "Table.Buffer" function in front

Example:
= Table.Buffer(#"Sorted Rows1")

This somehow makes the sorting "stick" no matter what else you do.

Yes, i'm interested too.

And in my project, i need sort tables because thay are not read in order and for the transformations, i need to get table sorted by date and by item.

Sincerly

 

Philippe

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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