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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Qasim_Jan
Frequent Visitor

Keep Original Sort Order Of A Column Table.

Hello Power BI community,

I am currently facing an issue while trying to create a pivot table in Power Query with unpivoted data. Specifically, I have three columns: EmployeeName, Year, and Count, in unpivoted order. My goal is to pivot this data while preserving the original sort order of the EmployeeName column and arranging the years in ascending order.

However, when I pivot the data by selecting the Year column, the EmployeeName order changes. I would greatly appreciate your assistance in achieving this objective while maintaining the initial sort order of the EmployeeName column and ensuring that the years are displayed in ascending order.

Your expertise and guidance on this matter would be invaluable to me. Thank you in advance for your time and assistance.

Best regards,

Qasim

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Qasim_Jan ,

 

Before you perform your pivot step in Power Query, go to the Add Column tab > Index Column > From 1. This will index your table in the current sort order.

After you pivot , you can then sort by the index column and year to get the data in the exact order you want.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
BA_Pete
Super User
Super User

Hi @Qasim_Jan ,

 

Before you perform your pivot step in Power Query, go to the Add Column tab > Index Column > From 1. This will index your table in the current sort order.

After you pivot , you can then sort by the index column and year to get the data in the exact order you want.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi @BA_Pete ,

Your suggestion to add an index column before the pivot and then sorting by the index column and year was spot on. It worked like a charm!

Your expertise and willingness to assist are truly appreciated. Thank you once again for your prompt and effective help.

Best regards,

Qasim

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.