cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mdvantonder
Helper I
Helper I

Sort Gallery by Dropdown selection of column title

I'm busy with my first app, so this may be a basic question.

I need my Gallery to sort in ascending order according to a column title selection in a dropdown list. The three columns are Instrument, Make, and Expiry Date.

 

I tried the following:

In the Items property of Dropdown1 the function is

 

["Instrument","Make","Expiry Date"]

 

 In the Items property of Gallery1 the function is

 

SortByColumns(Equipment, Dropdown1.Selected.Value, Ascending)

 

This seems to work when I select Instrument or Make, but when I select Expiry Date, an error occurs.

I thought it may either be:

  • The title containing a space; so, I changed the function to contain "Expiry_x0020_Date". Did not work.
  • The data type of the column, which is DateTime.

I tried several other solutions provided in the forums, but to no avail.

1 ACCEPTED SOLUTION

Accepted Solutions
v-yutliu-msft
Community Support
Community Support

Hi @mdvantonder ,

Do you want to sort based on the value selected in the drop down?

I've made a similar test and found that using "ExpiryDate" will be enough to sort based on field named Expiry Date.

Try to set like this:

In the Items property of Dropdown1 the function is

 

["Instrument","Make","ExpiryDate"]

 

 In the Items property of Gallery1 the function is

 

SortByColumns(Equipment, Dropdown1.Selected.Value, Ascending)

 

 

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.

View solution in original post

8 REPLIES 8
eka24
Super User III
Super User III

Try

 

Sort(Equipment, Dropdown1.Selected.Value,Ascending)

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

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.

Hi @eka24. I tried your suggestion of the Sort() function, but it does not do anything. The SortByColumns() at least sorts per Instrument and Make, but not per the Expiry Date. Do you have a suggestion why that particular column throws an error?

eka24
Super User III
Super User III

You can either remove the space in the Expiry Date to "Expiry_Date"

 

Or 

 

Create a collection:

ClearCollect( colSortTable,

{ SortColumn: "Instrument"} ,

{ SortColumn: "Make"} ,

{ SortColumn: "Expiry Date"}

)

 

Then use the colSortTable in the Dropdown Items

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

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.

 

@eka24  I am trying to avoid the underscore in the title for visual considerations. However, I will try your collection suggestion. I have not worked with collections before, so please bear with me: Where do I create this collection?

Put the Collection OnStart of the App.

After that restart the App then continue with the usual process

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

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.

v-yutliu-msft
Community Support
Community Support

Hi @mdvantonder ,

Do you want to sort based on the value selected in the drop down?

I've made a similar test and found that using "ExpiryDate" will be enough to sort based on field named Expiry Date.

Try to set like this:

In the Items property of Dropdown1 the function is

 

["Instrument","Make","ExpiryDate"]

 

 In the Items property of Gallery1 the function is

 

SortByColumns(Equipment, Dropdown1.Selected.Value, Ascending)

 

 

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.

View solution in original post

Porter
Frequent Visitor

G'day Mate,

 

If you want to keep the space in Expiry Date you can use the previous answer given in conjunction with Switch().

 

SortByColumns(Equpiment, Switch(Dropdown.Selected.Value, "Instrument", "Instrument", "Make", "Make", "Expiry Date", "ExpiryDate"), Ascending)

 

Hope this helps 🙂

I found that the space in the column title was the reason for the dropdown not recognising the selection. I decided to eliminate the space in the column title (as also suggested by @v-yutliu-msft). However, I'll try the suggestion from @Porter in future when I want to keep the space.

Thanks for all the help! 💪

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

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

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

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.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors
Users online (2,846)