web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Automate
Unanswered

PAD Sorting Datatable

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello all,

 

I'm reading in data from an excel file but my flow will only work if the datatable is sorted by a specific column. I know I can manually sort the excel table itself but I'd rather have the ability to sort the data in app if possible. Is there any way to do this?

 

Thanks in advance!

I have the same question (0)
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    I wish I knew how to sort a datatable, but I just don't see it.  As a workaround inside of PAD, I am thinking of extract a column, because you can sort a %List% variable.   Sort the list, and then do a for each on the list to create a new datatable, like this:

    • For each %CurrentItem% in %List%
      • For Each %CurrentItem2% in %OldDataTable%
        • If %CurrentItem2[3]% = %CurrentItem% #where Column 3 is the wanted column
          • Add Item %CurrentItem2% to %NewDataTable%
        • EndIF
      • End #For Each
    • End #For Each

     

    It's a stupid workaround, but without a sort option on the datatable, I don't know how else you would do it.  It's just re-writing the datatable in the right order.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hello @Anonymous 

     

    You can execute SQL query on Excel worksheet, as described in the following document:

    Run SQL queries on Excel files - Power Automate | Microsoft Docs

     

    With this method, you can use "ORDER BY" clause in SQL statement to sort by column you want.

    Such like this:

     

    SELECT * FROM [Sheet1$]
    ORDER BY [Name]

     

    shindomo_1-1634349531711.png

     

    Sample flow:

    shindomo_0-1634349314700.png

     

    Source Excel worksheet:

    shindomo_2-1634349832889.png

     

    Datatable you will get as a result of SQL query (sorted by [Name] column in ascending order in this case):

    shindomo_3-1634349898752.png

     

    Thank you.

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Ok, thank you both. I wish there was a cleaner way of doing this.

  • mdevaney Profile Picture
    29,991 Moderator on at

    @Anonymous, @MichaelAnnis 
    We can use the new DataTable actions to Sort on a single-column like this:

    mdevaney_0-1660321520694.png

     

  • Damian_Marquith Profile Picture
    2 on at

    @mdevaney  - I just wanted to thank you for your example above.  I had been trying to use the Index number generated in the 'DataTableMatches' output from the new 'Find or replace in data table' .. to pass through to identify fields in my second datatable.  I kept getting errors every time I passed to the array... until I saw your example.. and saw the "Convert text to number" and then it clicked.  Why would an INTEGER OUTPUT for a ROW INDEX BE AS TEXT ??  Anyway, thank you for showing this.  Hopefully others will find this useful as well.  

  • Malik5 Profile Picture
    on at

    You can use 'Run .NET script' action to Sort your Data Table variable in PAD.

     

    Once the action is run successfully, you will have you Data Table variable sorted with the column name and sort direction you've provided, which in the example below is Rejected as column name, and asc as sort direction.

     

    Malik5_0-1706706258906.png

     

    Malik5_1-1706706295923.png

     

  • mcn24 Profile Picture
    5 on at

    @Malik5 May I ask which one is Data Table variable in your example? Thank you. 

  • Malik5 Profile Picture
    on at

    Yes, pFVRs is the Data Table, it is a Flow variable, which is being used as an input and output parameter at the same time.

     

    Thank you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 427

#2
Vish WR Profile Picture

Vish WR 316

#3
David_MA Profile Picture

David_MA 260 Super User 2026 Season 1

Last 30 days Overall leaderboard