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

Community site session details

Session Id :
Power Apps - Building Power Apps
Suggested answer

Sort two columns at one time

(0) ShareShare
ReportReport
Posted on by 94
Hi all,
 
I have a hard time in sorting these items based on CompletedTime. It already follows the Date_x002f_Time ASC condition, but how do I fix my code to have it sort CompletedTime next?
 
Here's my current code:
I'd really appreciate if anyone could help me figured this out.
Thank you so much.
I have the same question (0)
  • Suggested answer
    MS.Ragavendar Profile Picture
    4,298 Super User 2025 Season 2 on at
    Sort two columns at one time
     
    Try this code and let me know.
    With(
        {
            orderSeq: Filter(
                SortByColumns(
                    SortByColumns(
                        Orders,
                        "Date_x002f_Time", SortOrder.Ascending
                    ),
                    "CompletedTime", SortOrder.Ascending
                ),
                Status = "Urgent" && 
                (Progress = "Order Received" || Progress = "In Progress" || Progress = "Delivery")
            )
        },
        ForAll(
            Sequence(CountRows(orderSeq)),
            Patch(
                Index(
                    orderSeq,
                    Value
                ),
                {RowNo: "U" & Value}
            )
        )
    )
    
     
    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item
     
     
  • Suggested answer
    RobGasp Profile Picture
    2 on at
    Sort two columns at one time
    I'd also recommend using the code like this: SortByColumn(SortByColumn(Filter(),SortCol1,Asc),SortCol2,Asc) So it filters and then sorts the data, could give you a performance boost (Doesn't sort irrelevant data first). Note do this only if your sort is delegable.
  • AR-03030545-0 Profile Picture
    94 on at
    Sort two columns at one time
     
    I tried and did not work. It stayed the same.
  • MS.Ragavendar Profile Picture
    4,298 Super User 2025 Season 2 on at
    Sort two columns at one time
     
    If sorting still doesn't work as expected:
    • Check the data type of CompletedTime – Ensure it's stored as a DateTime value, not a string.
    • Debug using a Collection - Add ClearCollect(collectionName, datascource) before ForAll to inspect the sorted output.
    • Display collectionName in a gallery to verify sorting behavior.
    • Try sorting CompletedTime in descending order (SortOrder.Descending) to see if any change occurs
    With(
        {
            orderSeq: Filter(
                SortByColumns(
                    Orders,
                    "Date_x002f_Time", SortOrder.Ascending,
                    "CompletedTime", SortOrder.Ascending
                ),
                Status = "Urgent" && 
                (Progress = "Order Received" || Progress = "In Progress" || Progress = "Delivery")
            )
        },
        ClearCollect(testOrders, orderSeq),  // Collect sorted data for inspection
        ForAll(
            Sequence(CountRows(orderSeq)),
            Patch(
                Index(
                    orderSeq,
                    Value
                ),
                {RowNo: "U" & Value}
            )
        )
    )
    
     
  • AR-03030545-0 Profile Picture
    94 on at
    Sort two columns at one time
     
    Patch(
            Orders,
            Defaults(Orders),
            {
                'Date/Time': Text(
                    Now(),
                    DateTimeFormat.LongDateTime
                ),'Pre-Order Time': If(
                !IsBlank(PreOrderTime.Text) && Trim(PreOrderTime.Text) <> "",
                Text(TimeValue(PreOrderTime.Text), "h:mm AM/PM"), ...
            }
    )
     
    This is how I configured for Date_x002f_Time and CompletedTime (Pre-Order Time) on the Submit button. 
    Perhaps this could be the reason why it is not working out?
  • Suggested answer
    MS.Ragavendar Profile Picture
    4,298 Super User 2025 Season 2 on at
    Sort two columns at one time
     
    Patch(
        Orders,
        Defaults(Orders),
        {
            'Date/Time': Now(), // Ensure this remains DateTime
            'Pre-Order Time': If(
                !IsBlank(PreOrderTime.Text) && Trim(PreOrderTime.Text) <> "",
                DateAdd(
                    DateValue(Text(Now(), "[$-en-US]yyyy-mm-dd")),
                    Value(Hour(TimeValue(PreOrderTime.Text))),
                    Hours
                ) + Time(
                    Hour(TimeValue(PreOrderTime.Text)),
                    Minute(TimeValue(PreOrderTime.Text)),
                    0
                ),
                Blank()
            )
        }
    )
    
     
     
    I believe this will works because its storing CompletedTime as a valid DateTime field.
     
    Ensures sorting works correctly in your gallery because it is no longer a text string.
     
    In the dataverse table ensure that the column type for CompletedTime is DateTime and not Text.
     
     
     
  • AR-03030545-0 Profile Picture
    94 on at
    Sort two columns at one time
     
    I am using SharePoint List. If I changed the data type of CompletedTime from text/string to DateTime, won't it affect the whole system? FYI, the system has been published to be used to users but stop for a while because I need to do this improvement. 
  • MS.Ragavendar Profile Picture
    4,298 Super User 2025 Season 2 on at
    Sort two columns at one time
     
    Yes, changing the data type of CompletedTime from Text to DateTime in SharePoint will affect the whole system if other parts of your app, flows, or reports rely on the existing text format.
     
    For e.g, If records are stored as text ("2:56 PM"), changing the column type won't auto-convert old values to DateTime. You may need to manually update old records.
  • AR-03030545-0 Profile Picture
    94 on at
    Sort two columns at one time
     
    CompletedTime is used at/for this only:
     
    1. User interface
      • Submit button - to patch CompletedTime (Pre-Order Time defined by users)
      • Text field a.k.a PreOrderTime.Text- to store CompletedTime (Pre-Order Time defined by users)
    2. Runner interface/Dashboard like shown in the picture
      • Text field - to display the CompletedTime (or in the dashboard it is stated as Order Need)
    I took some time to analyze this to ensure that this stuff won't affect the system if I change the data type. 
     
    But, just to clarify, I still can go back (like undo/change the data type from DateTime to text again) to changing things in the way it used to be IF it gives some impact to the system, right? :")
  • MS.Ragavendar Profile Picture
    4,298 Super User 2025 Season 2 on at
    Sort two columns at one time
     
    Yes exactly correct, Instead of that you showing the items in gallery right.
     
    Apply the sorting to the columns in the gallery, let the user will sort the columns accordingly this gives more flexibility to the users. 
     
    Instead of the changing the backend schema.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 650 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 445 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 319

Last 30 days Overall leaderboard