cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
akbarmahfuzalam
Post Prodigy
Post Prodigy

Sorting Choice Column with SortByColumns

Hello,

I am trying to use the SortByColumns for the choice column and I am not getting it right.

 

My formula goes like... for Gallery

 

If(
Dropdown1.Selected.Value = "All",
Search(
SortByColumns(
Filter(
ColManualCountNew,
WorkedDate >= DateFrom.SelectedDate && WorkedDate <= DateTo.SelectedDate
),
"WorkedDate",
If(
SortDescending1,
Descending,
Ascending
)
),
SearchBox.Text,
"TeamLead",
"Title"
),
Search(
SortByColumns(
Filter(
ColManualCountNew,
WorkedDate >= DateFrom.SelectedDate && WorkedDate <= DateTo.SelectedDate && QueueName.Value = Dropdown1.Selected.Value
),
"WorkedDate",
If(
SortDescending1,
Descending,
Ascending
)
),
SearchBox.Text,
"TeamLead",
"Title"
)
)

 

And on Sort Icon

UpdateContext({SortDescending1: !SortDescending1})

 

Help is required to fix the workable formula

1 ACCEPTED SOLUTION

Accepted Solutions

@akbarmahfuzalam 

Sorry, the reason for all the red error is that I had a typo in the formula provided.  Please scrub through the formulas I provide as I type them by hand without the aid of a design editor.

 

Formula should be:

DropColumns(
    SortByColumns(
        AddColumns(
            Search(
                Filter(ColManualCountNew,
	           WorkedDate >= DateFrom.SelectedDate && 
                   WorkedDate <= DateTo.SelectedDate && 
                   (Dropdown1.Selected.Value="All" || QueueName.Value = Dropdown1.Selected.Value)
                ),
                SearchBox.Text, "TeamLead", "Title"
            ),
            "_queueName", QueueName.Value
        ),
        "_queueName",
        If(SortDescending1, Descending, Ascending),
        "WorkedDate"
    ),
    "_queueName"
)

This also has been modified to primarily sort by the QueueName and in the order of the sort depending on your icon.  Then secondarily, it will sort the WorkedDate.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

7 REPLIES 7
RandyHayes
Super User III
Super User III

@akbarmahfuzalam 

What is the Choice column that you are trying to sort on?  Your formula specifies "WorkedDate" as the column your are sorting from now.  Is it that you are also trying to sort on the QueueName column?

If so, then consider the following formula:

DropColumns(
    SortByColumns(
        AddColumns(
            Search(
                Filter(ColManualCountNew,
	           WorkedDate >= DateFrom.SelectedDate && 
                   WorkedDate <= DateTo.SelectedDate && 
                   (Dropdown1.Selected.Value="All" || QueueName.Value = Dropdown1.Selected.Value)
                ),
                SearchBox.Text, "TeamLead", "Title"
            ),
            "_queueName", QueueName.Value
        )
        "WorkedDate",
        If(SortDescending1, Descending, Ascending),
        "_queueName"
    ),
    "_queueName"
)

 

First, this removes the duplicate Search and Filter of your original formula by moving the Dropdown "All" logic to the actual filter formula.  Next, it adds the value of the QueueName as a returned column in order to sort on it.  Finally, it removes the added column, just in case you have other controls in your app that rely on the schema of the Gallery record.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
StalinPonnusamy
Community Champion
Community Champion

Hi @akbarmahfuzalam 

 

We can sort by choice column

 

SortByColumns(
   AddColumns(
      'Issue tracker',
      "PriorityValue",
      Priority.Value
   ),
   "PriorityValue", 
   Ascending
)

 

 

Priority - Choice Column in SP

StalinPonnusamy_0-1626973383443.png

If you like this post, give it a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

 

Thanks
Stalin

@RandyHayes ,

 

First, I am filtering as per the Dropdown1 and then by date and I have an icon Sort which I want to sort the choice column.

 

akbarmahfuzalam_2-1626973670848.png

akbarmahfuzalam_0-1626974188731.png

 

akbarmahfuzalam_1-1626973507643.png

 

 

StalinPonnusamy
Community Champion
Community Champion

@RandyHayes pointed the important thing to drop the column once done otherwise it causes an issue on another screen (s)

 

In this Case Filtering by Priority and Sort by Shipping method. Both are choice column in SP.

DropColumns(
    SortByColumns(
        AddColumns(
            Filter(
                [@'Issue tracker'],
                Priority.Value= ComboBox1.Selected.Value
            ),
            "ShippingMethodValue",
            ShippingMethod.Value
        ),
        "ShippingMethodValue",
        If(
            SortDescending1,
            Descending,
            Ascending
        )
    ),
    "ShippingMethodValue"
)

 

Thanks
Stalin

@akbarmahfuzalam 

Sorry, the reason for all the red error is that I had a typo in the formula provided.  Please scrub through the formulas I provide as I type them by hand without the aid of a design editor.

 

Formula should be:

DropColumns(
    SortByColumns(
        AddColumns(
            Search(
                Filter(ColManualCountNew,
	           WorkedDate >= DateFrom.SelectedDate && 
                   WorkedDate <= DateTo.SelectedDate && 
                   (Dropdown1.Selected.Value="All" || QueueName.Value = Dropdown1.Selected.Value)
                ),
                SearchBox.Text, "TeamLead", "Title"
            ),
            "_queueName", QueueName.Value
        ),
        "_queueName",
        If(SortDescending1, Descending, Ascending),
        "WorkedDate"
    ),
    "_queueName"
)

This also has been modified to primarily sort by the QueueName and in the order of the sort depending on your icon.  Then secondarily, it will sort the WorkedDate.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

@RandyHayes 
Thanks a ton. It works for me.
You always rescue me when I am in trouble.

RandyHayes
Super User III
Super User III

@akbarmahfuzalam 

Happy to help!!

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (2,784)