Forum Discussion

Qasim_Jan's avatar
Qasim_Jan
Frequent Visitor
2 years ago
Solved

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

  • 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

2 Replies

  • 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

    • Qasim_Jan's avatar
      Qasim_Jan
      Frequent Visitor

      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