Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

SortByColumns Search a collection using a variable to display in a gallery


I need to sort a field within a gallery. I created a gallery to display fields stored in my collection. I need to place my "NHPNum" field in ascending order. I'm using the below and returning an error. 



"varBuilderCase" is my variable to return the information link to a particular opportunity ID. 


My original syntax that is working is :NHPNum

Which of course is just displaying the values for this field. The issue is my list of records in the gallery is not in order. Any suggestions are appreciated. Thanks in advance.

Super User
Super User

Are you saying that the above expression is displaying all the expected results but not in the correct sort order? Are you getting any errors?

If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit Bhatia

I am getting an error. Thanks

Can you please share the error?

The errors are: "The function 'Search' has some invalid arguments." & "The function 'SortByColumns' has some invalid arguments.

But perhaps I'm using the wrong syntax altogether. In the Text property for this field: HNPNum and the gallery is connected to HPCollection. I return the following results:



I need to sort NHPNum in ascending order. When I did a simple sort formula: Sort(HPCollection,NHPNum,Ascending) my error was "Expected Text Value". So any assistance to get it in ascending order would be appropriated. Thanks 


Hi @Fleming ,

Could you tell me how do you set variable varBuilderCase?

I need to know the data type of varBuilderCase.

Please make sure that "varBuilderCase.OpportunityID" is text type.

The right syntax of Search function is: 

Search( Table, SearchString, Column1 [, Column2, ... ] )

The second parameter should be string.

What's more, you should change SortByColumns function too.

Please use formula like this:


You need to use  ""  on both sides of the fieldname.

SortOrder.Ascending is the default. You do not need to list it.


Here are docs about these two functions for your reference:




Best regards,


Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yutliu-msft  The variable is set multiple steps back when the user enters the ID. This pulls information saved for the given opportunityID from my datasource (SharePoint) and save it to the collection (HPCollection). OpportunityID is a text field.
I did updated the search and sortbycolumn syntax to your suggestion and I received the attached errors. When I hoover over NHPNum it states the field does not exist. I also included an image of the field from my collection. At this point, I'm ok with removing the search functionality if I can get assistance on a simple ascending sort for NHPNum which is a number field in my collection. Thanks in advance.

Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.


New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,574)