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 Platform Community / Forums / Power Apps / sorting by multiple co...
Power Apps
Answered

sorting by multiple columns

(0) ShareShare
ReportReport
Posted on by 557



I have sort function in items property.  I need to be able to first sort by column "Need More Information" is equal to Yes , then sort by descending ID Order. 

 

this is what I currently have:
Sort(
_finaltable,
ID,
SortOrder.Ascending)

Categories:
  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @joel914823 - assuming the "Need More Information" field is a Single Line Text data type:

     

    SortByColumns(
     _finaltable,
     "NeedMoreInformation", //powerapps should automatically detect the correct field syntax
     SortOrder.Descending,
     "ID",
     SortOrder.Ascending
    )

     

  • joel914823 Profile Picture
    557 on at

    @Amik Thank you 🙂  sorry I should have clarified that the column is a Yes/No type column in SharePoint.  Would that change the above?  

  • Prabhakar_S Profile Picture
    735 Moderator on at

    Hi @joel914823 ,

     

    By this way you can sort the "Need More Information" column first where it equals "Yes", and then by the "ID" column in descending order. 

    SortByColumns(
    Filter(
    _finaltable,
    'Need More Information' = "Yes"
    ),
    "ID",
    SortOrder.Descending
    )

     

    To Sort Multiple Columns: You can add more columns to the 'SortByColumns' function if you need to sort by more than one column. The sort will be applied in the order the columns are specified.

    For example, to sort first by "Need More Information" (descending) and then by "ID" (descending):

    SortByColumns(
    _finaltable,
    "Need More Information",
    SortOrder.Descending,
    "ID",
    SortOrder.Descending
    )

     

    Adjust the column names and sorting orders as per your specific requirements.

     

    Thanks!!!

     

    Please consider marking my response as the accepted solution if it successfully resolves your concern. If you found the information beneficial in other aspects, kindly express your appreciation by giving it a thumbs-up.

  • Verified answer
    Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @joel914823 - The SortByColumns function runs on string data types, and Power Apps considers a SharePoint Yes/No field as a complex data type.

     

    To complicate matters a little, the Yes/No data type returns a Boolean (true/false).

     

    You will need to leverage the AddColumns function to create another "virtual" column which returns string "Yes" for true and string "No" for false, and then sort on that column.

     

    Assuming all of this is related to your other post, use:

     

    With(
     {
     _prefiltered_data: Filter(
     'eCom Intake',
     Status.Value = "Open - Assigned",
     Len(Dropdown4.Selected.Value) = 0 || LOB.Value = Dropdown4.Selected.Value,
     Len(Dropdown4_1.Selected.Value) = 0 || 'Issue Type'.Value = Dropdown4_1.Selected.Value,
     !Checkbox1.Value || 'Created By'.Email = User().Email
     )
     },
     With(
     {
     _transformed_data: AddColumns(
     _prefiltered_data,
     TextID,
     Text(ID),
     CreatedByDisplayName,
     'Created By'.DisplayName,
     AssignedToDisplayName,
     AssignedTo.DisplayName,
     YesNoAsText,
     If(
     'Your Yes/No Field',
     "Yes",
     "No"
     )
     )
     },
     With(
     {
     _filtered_by_names: Search(
     _transformed_data,
     SearchInput_tb.Text,
     Title,
     CreatedByDisplayName,
     AssignedToDisplayName
     ),
     _filtered_by_id: Search(
     _transformed_data,
     SearchInput_tb.Text,
     TextID
     )
     },
     With(
     {
     _finaltable: If(
     !SearchID_tg.Checked && !SearchRequestor_tg.Checked,
     _filtered_by_names,
     _filtered_by_id
     )
     },
     SortByColumns(
     _finaltable,
     "YesNoAsText",
     SortOrder.Descending,
     "ID",
     SortOrder.Ascending
     )
     )
     )
     )
    )

     

  • joel914823 Profile Picture
    557 on at

    Hello @Amik 

     

    Do you know if I need to add  ".Value = true" within the Add columns portion?  I tried your suggestion below but gave me error.  When I add the ".Value=true" it wipes out all the items from the gallery.

    With(

        {

            _prefiltered_data: Filter(

                'eCom Intake',

                Status.Value = "In Progress",

                Len(Dropdown4.Selected.Value) = 0 || LOB.Value = Dropdown4.Selected.Value,

                Len(Dropdown4_1.Selected.Value) = 0 || 'Issue Type'.Value = Dropdown4_1.Selected.Value,

                !Checkbox1.Value || 'Created By'.Email=User().Email

           

            )

        },

        With(

            {

                _transformed_data: AddColumns(

                    _prefiltered_data,

                    TextID,

                    Text(ID),

                    CreatedByDisplayName,

                    'Created By'.DisplayName,

                    AssignedToDisplayName,

                    AssignedTo.DisplayName,

                    YesNoAsText,

                    If(

                        'NeedMoreInfoOPS - Current'.Value = true,

                        "Yes",

                        "No"

                    )

                )

            },

            With(

                {

                    _filtered_by_names: Search(

                        _transformed_data,

                        SearchInput_tb.Text,

                        Title,

                        CreatedByDisplayName,

                        AssignedToDisplayName

                    ),

                    _filtered_by_id: Search(

                        _transformed_data,

                        SearchInput_tb.Text,

                        TextID

                    )

                },

                With(

                    {

                        _finaltable: If(

                            !SearchID_tg.Checked && !SearchRequestor_tg.Checked,

                            _filtered_by_names,

                            _filtered_by_id

                        )

                    },

                    SortByColumns(

                        _finaltable,

                        "YesNoAsText",

                        SortOrder.Descending,

                        ID,

                        SortOrder.Ascending

                    )

                )

            )

        )

    )

  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @joel914823 - for this section:

     

    If(
     'Your Yes/No Field',
     "Yes",
     "No"
    )

     

    Enter the actual name of your Yes/No field.

     

    As mentioned earlier, the Yes/No data type returns a Boolean (true/false). Because of this, you will notice I have not bothered to check if the output of that field equals true because a Yes/No data type already returns a Boolean value anyway.

  • joel914823 Profile Picture
    557 on at

    I was able to change it back to a choice type column.  How could I alter the formula to use that instead of the boolean.  Thank you so much @Amik 

  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @joel914823 - sorry I do not understand what you mean by "I was able to change it back to a choice type column".

     

    The formula I provided is applicable to a Yes/No data type (because that is the data type you have stated).

  • joel914823 Profile Picture
    557 on at

    Hello @Amik  I created a new column and instead of it being Yes/No, I made it a choice column.  How could I apply it into the formula now that it is a choice column?  Thank you so much.

  • Verified answer
    Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @joel914823 - No idea why you have randomly changed this to a Choice column. I provided you with a solution and an explanation for what to do with a Yes/No data type because that is what you asked for. 

     

    For a Choice column, you will need:

     

    
    With(
     {
     _prefiltered_data: Filter(
     'eCom Intake',
     Status.Value = "Open - Assigned",
     Len(Dropdown4.Selected.Value) = 0 || LOB.Value = Dropdown4.Selected.Value,
     Len(Dropdown4_1.Selected.Value) = 0 || 'Issue Type'.Value = Dropdown4_1.Selected.Value,
     !Checkbox1.Value || 'Created By'.Email = User().Email
     )
     },
     With(
     {
     _transformed_data: AddColumns(
     _prefiltered_data,
     TextID,
     Text(ID),
     CreatedByDisplayName,
     'Created By'.DisplayName,
     AssignedToDisplayName,
     'AssignedTo'.DisplayName,
     ChoiceString,
     'Your Yes No Choice'.Value
     )
     },
     With(
     {
     _filtered_by_names: Search(
     _transformed_data,
     SearchInput_tb.Text,
     Title,
     CreatedByDisplayName,
     AssignedToDisplayName
     ),
     _filtered_by_id: Search(
     _transformed_data,
     SearchInput_tb.Text,
     TextID
     )
     },
     With(
     {
     _finaltable: If(
     !SearchID_tg.Checked && !SearchRequestor_tg.Checked,
     _filtered_by_names,
     _filtered_by_id
     )
     },
     SortByColumns(
     _finaltable,
     "ChoiceString",
     SortOrder.Descending,
     "ID",
     SortOrder.Ascending
     )
     )
     )
     )
    )

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 330

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard