cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

sorting with two different fields in Gallery

Hi All,

 

I have 2 sort icons and i want my gallery to sort based on those 2 fields.

If i click first icon it should sort by "ID" asc and if i click that again it should sort "ID" desc.

and If i click second icon it should sort by "Name" asc and if i click that again it should sort "Name" desc.

 

I can able to do it for 1 field but unable to do it for 2 fields.

SortByColumns(Filter([DataSource], [Formula]), "Title1", If(SortDescending1, Descending, Ascending))

how to do it for 2 fields?

And also in the above example if instead of "Title1" if  have "Title 1" then how to handle that space?

 

Thanks in advance

Prakash

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@Anonymous ,

This has expanded somewhat from the simple question you asked on your first post. 

Why are you using variables for the full sort - just use two Boolean variables - I have called them Sort1 and Sort2 below. Note that this is syntax guidance only

With(
   {
      MyData:
      AddColumns(
         'Data Source_1',
         "MyStatus",
         Request_x0020_Status.Value
      )
   },
   SortByColumns(
   If(
      Dropdown1.Selected.Value = "All", 
      MyData,
      Filter(
         MyData,
        'Request Status'.Value = Dropdown1.selected.Value
      ),
      "SortColumn", 
      If(
         Sort1,
         Descending,Ascending
      ),
      "MyStatus",
      If(
         Sort2,
         Descending,Ascending
      )
   )
)

 

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.

View solution in original post

6 REPLIES 6
WarrenBelz
Super User
Super User

Hi @Anonymous ,

You need to give them both sort orders - I assume you have different sort buttons.

SortByColumns(
   Filter(
      [DataSource], 
      [Formula]
   ), 
   "Title1", 
   If(SortDescending1, Descending, Ascending),
   "Name",
   If(SortDescending2, Descending, Ascending)
)

 

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.

Anonymous
Not applicable

Hi @WarrenBelz ,

 

Thanks for your reply. Instead of "Name" in your example if i have a field "ThisItem.Status.Value" then how to put that formula?

How to handle a field with ThisItem. in prefix and .Value in suffix?

 

Thanks in Advance

Prakash

Anonymous
Not applicable

Hi All,

 

In the above question i have Status field in drop down and i believe because of that it is showing ThisItem.Status.Value?

Based n the drop down selection in Status my gallery will get filtered.

 

Regards,

Prakash M

@Anonymous ,

You do not need ThisItem - you are sorting a list. 

You also cannot sort by complex field types - you would need to do something like this

SortByColumns(
   Filter(
      AddColumns(
         [DataSource], 
         "MyStatus",
         Status.Value
      ),
      [Formula]
   ), 
   "MyStatus", 
   If(SortDescending1, Descending, Ascending),
   "YourOtherField",
   If(SortDescending2, Descending, Ascending)
)

 

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.

 

Anonymous
Not applicable

Hi @WarrenBelz ,

 

I understood the concept that we are adding a column named "MyStatus" but unable to implement in my app since i am very new to Power Apps and my existing formula in this app is little different from what you provided.

 

I have 2 columns named as Full Name and Request Status and both these columns are present in Gallery.

In my Sort icon --> in on Select --> i have provided the below formula

First sort icon(Full Name)-->UpdateContext({SortColumn:"Full_x0020_Name",SortDescending: !SortDescending})

Second Sort Icon(Request Status)-->UpdateContext({SortColumn:"Request_x0020_Status",SortDescending: !SortDescending})

 

Now in Gallery--> in Items --> i have given the below formula

If(Dropdown1.Selected.Value = "All", SortByColumns('Data Source_1',SortColumn, If(SortDescending, Descending, Ascending)),

SortByColumns(Filter([@'Data Source_1'],'Request Status'.Value = Dropdown1.selected.Value),SortColumn, If(SortDescending,Descending,Ascending)))

 

So with the help of variable SortColumn which we created in both the sort icons that we are using here in gallery.

 

In Dropdown1 we have provided the Request Status Field --> in items --> we have given CollectVideo

 

and in the screen --> on Visible --> we have given the below formula

ClearCollect(collectVideo, {Value:"All"});

Collect(collectVideo, Choices([@'Data Source_1'].Request_x0020_Status))

 

Now my problem is in my second sort icon button my formula is throwing error:

Second Sort Icon(Request Status)-->UpdateContext({SortColumn:"Request_x0020_Status",SortDescending: !SortDescending})

 

I am not sure here how i need to give Request Status value.

 

Please help!!

 

Thanks

Prakash

@Anonymous ,

This has expanded somewhat from the simple question you asked on your first post. 

Why are you using variables for the full sort - just use two Boolean variables - I have called them Sort1 and Sort2 below. Note that this is syntax guidance only

With(
   {
      MyData:
      AddColumns(
         'Data Source_1',
         "MyStatus",
         Request_x0020_Status.Value
      )
   },
   SortByColumns(
   If(
      Dropdown1.Selected.Value = "All", 
      MyData,
      Filter(
         MyData,
        'Request Status'.Value = Dropdown1.selected.Value
      ),
      "SortColumn", 
      If(
         Sort1,
         Descending,Ascending
      ),
      "MyStatus",
      If(
         Sort2,
         Descending,Ascending
      )
   )
)

 

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.

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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