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

Assistance with sorting - need to sort based on values

Hi Folks -

 

I have the following logic in a gallery and it's working as expected:

SortByColumns(
    AddColumns(
        Filter(rdAssets, 
			Or(
				StartsWith(Alias, TextSearchBox4.Text),
				StartsWith(Name, TextSearchBox4.Text),
				StartsWith(Target_x0020_Short_x0020_Name, TextSearchBox4.Text),
				StartsWith(Brand_x0020_Name, TextSearchBox4.Text),
				StartsWith(PF_Research_Code, TextSearchBox4.Text),
				StartsWith(Generic_x0020_Name, TextSearchBox4.Text),
				StartsWith(Development_Name, TextSearchBox4.Text),
				StartsWith(Alternate_Name, TextSearchBox4.Text)) && RequestStatus.Value<>"Delete"),
    "txtPortfolioStatus", Portfolio_x0020_Status.Value),
    "txtPortfolioStatus", If(SortDescending1, Descending, Ascending),
"Alias", If(SortDescending1, Descending, Ascending)
)

 

However, I want to add another condition to the Sort function where I sort the field "RequestStatus" by values (in this order) "New","Updated" and then everything else.  Is this possible?

9 REPLIES 9
Highlighted
Super User
Super User

Re: Assistance with sorting - need to sort based on values

@simms7400 

You’ll need to use Collections to accomplish this:


Put your data in a colle

ClearCollect(colMyData,
SortByColumns(
    AddColumns(
        Filter(rdAssets, 
			Or(
				StartsWith(Alias, TextSearchBox4.Text),
				StartsWith(Name, TextSearchBox4.Text),
				StartsWith(Target_x0020_Short_x0020_Name, TextSearchBox4.Text),
				StartsWith(Brand_x0020_Name, TextSearchBox4.Text),
				StartsWith(PF_Research_Code, TextSearchBox4.Text),
				StartsWith(Generic_x0020_Name, TextSearchBox4.Text),
				StartsWith(Development_Name, TextSearchBox4.Text),
				StartsWith(Alternate_Name, TextSearchBox4.Text)) && RequestStatus.Value<>"Delete"),
    "txtPortfolioStatus", Portfolio_x0020_Status.Value),
    "txtPortfolioStatus", If(SortDescending1, Descending, Ascending),
"Alias", If(SortDescending1, Descending, Ascending)
)
);

ClearCollect(colOrderedData, Filter(colMyData, RequestStatus="New"));

Collect(colOrderedData, Filter(colMyData, RequestStatus="Updated"));

Collect(colOrderedData, Filter(colMyData, !(RequestStatus="New" Or RequestStatus="Updated")));

 

If RequestStatus is a choices column then you must changes all references to RequestStatus.Value instead.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Community Champion
Community Champion

Re: Assistance with sorting - need to sort based on values

Hi @simms7400 ,

A simple way would be to make "New" and "Updated" "_New" and "_Updated" or have a shadow numeric column updated when the status is changed, with your sorting order.

 

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. If the content was useful in other ways, please consider giving it Thumbs Up.

Highlighted
Community Champion
Community Champion

Re: Assistance with sorting - need to sort based on values

From your request, is the column ReportStatus a choice column?

Follow this structure to add to the existing formula

Sort( Datasource,ReportStatus.Value , [ "New", "Updated" ] )

 

Or if not a s

Sort( Datasource,ReportStatus , [ "New", "Updated" ] )

 

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-sort

------------

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

Highlighted
Post Prodigy
Post Prodigy

Re: Assistance with sorting - need to sort based on values

@mdevaney 

 

Thank you!  Would I put this collection on app start up and then just reference the collection name in the gallery?

Highlighted
Super User
Super User

Re: Assistance with sorting - need to sort based on values

@simms7400 

I would put it in the OnVisible property of the page then reference the collection name in the gallery.  Then I would also make a refresh button with the same code in it.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Post Prodigy
Post Prodigy

Re: Assistance with sorting - need to sort based on values

@mdevaney 

 

Hi - I made a collection on the On Visible property and used the name for the gallery results.  However, the gallery no longer searches and when I set a status to "New" or "Updates", it's not at the top. What could I be doing wrong?

Highlighted
Super User
Super User

Re: Assistance with sorting - need to sort based on values

@simms7400 

Sorry, I did not know you had a search field.  It’s not working because the collection is already loaded before you put data in the Search box.

 

Instead, make a “Search” button and put the code in the OnSelect property.  Once the user has typed in the search field they should click ‘Search‘.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

 

Highlighted
Post Prodigy
Post Prodigy

Re: Assistance with sorting - need to sort based on values

There's not another way to do this? I dont want to have end users have to click a button to search when before they didn't have to.

Highlighted
Super User
Super User

Re: Assistance with sorting - need to sort based on values

@simms7400 

I suppose you could put it inside the OnChange property of the Text Input instead.  You could also set the DelayOutput property of the Text Input to true so the change is registered immediately.


Link to Text Input article;

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/controls/control-text-input

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Helpful resources

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,394)