cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rwittels
Resolver I
Resolver I

Need assistance with sort by date when Gallery is filtered

Hi. My issue is related to 3 of my source data columns:

  1. Date - the date an item was created/opened
  2. 'Date Closed' - the date an item was closed
  3. Status - items have a status of either "Open" or "Closed"

I have set up my Gallery with a button which filters results by status.  When the list is displaying "Open" items, the SortUpDown button sorts by Date perfectly. When the list is displaying "Closed" items, I want the SortUpDown button to sort by 'Date Closed', which is not working.

 

Here is my setup:

OnStart, I declare a global variable: Set(varStatus, true)

The button which filters results by status has this OnSelect property: UpdateContext({varStatus: !varStatus})

One of the labels in my gallery displays the date. The Text property on it is:

If(ThisItem.Status = "Open",Text(ThisItem.Date,"[$-en-GB]yyyy/mm/dd hh:mm"),Text(ThisItem.'Date Closed',"[$-en-GB]yyyy/mm/dd hh:mm"))

The original property was ThisItem.Date which is part of my issue.

When "Open" items are listed, the date displayed is Date.

GalleryDate.jpg

 

 

 

 

 

When "Closed" items are listed, the date displayed is 'Date Closed'.

GalleryDateClosed.jpg

 

 

 

 

 

This is where I need the help

My Gallery Items property is:

SortByColumns(Filter(Main,If(varStatus,Status="Closed",Status="Open"), TextSearchBox1.Text in If(varStatus,'Date Closed',Date) || TextSearchBox1.Text in Location || TextSearchBox1.Text in Issue),"Date",If(SortDescending1,Descending,Ascending))

 

Where the column is specified as "Date", I need it to be "Date Closed" if the Status="Closed". That way it will sort by 'Date Closed' instead of Date, which is not valid on the "Closed" items screen. I have tried many If Statements which all seem logical to me but the problem is that it keeps telling me that "The specified column 'Date Closed' does not exist". I assume it is because the 'Date Closed' field was not added to my gallery, only Date.

 

So, do I need to add the 'Date Closed' field and simply hide Date when "Closed" items are displayed? Is there an easier way?

1 ACCEPTED SOLUTION

Accepted Solutions
v-jefferni
Community Support
Community Support

Hi @rwittels ,

 

Could you please share more details about the Items of the Gallery? Is that Main a collection?

 

If so, 'Date Closed' field is necessary to add into the collection then you could filter by that field. It would not be complex with the two fields:

 

1\  Use 2 Labels to display the respective field, Date:

 

Text(ThisItem.Date,"[$-en-GB]yyyy/mm/dd hh:mm")

 

 

 and Date Closed: 

 

Text(ThisItem.'Date Closed',"[$-en-GB]yyyy/mm/dd hh:mm")

 

 

2\ Make the 2 Labels overlap.

 

3\ Set Visible of the Date Label: !varStatus, Date Closed Label: varStatus

 

4\ Modify the formula in Gallery Items:

 

SortByColumns(Filter(Main,If(varStatus,Status="Closed",Status="Open"), TextSearchBox1.Text in If(varStatus,'Date Closed',Date) || TextSearchBox1.Text in Location || TextSearchBox1.Text in Issue),If(varStatus,"Date Closed","Date"),If(SortDescending1,Descending,Ascending))

 

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

 

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

1 REPLY 1
v-jefferni
Community Support
Community Support

Hi @rwittels ,

 

Could you please share more details about the Items of the Gallery? Is that Main a collection?

 

If so, 'Date Closed' field is necessary to add into the collection then you could filter by that field. It would not be complex with the two fields:

 

1\  Use 2 Labels to display the respective field, Date:

 

Text(ThisItem.Date,"[$-en-GB]yyyy/mm/dd hh:mm")

 

 

 and Date Closed: 

 

Text(ThisItem.'Date Closed',"[$-en-GB]yyyy/mm/dd hh:mm")

 

 

2\ Make the 2 Labels overlap.

 

3\ Set Visible of the Date Label: !varStatus, Date Closed Label: varStatus

 

4\ Modify the formula in Gallery Items:

 

SortByColumns(Filter(Main,If(varStatus,Status="Closed",Status="Open"), TextSearchBox1.Text in If(varStatus,'Date Closed',Date) || TextSearchBox1.Text in Location || TextSearchBox1.Text in Issue),If(varStatus,"Date Closed","Date"),If(SortDescending1,Descending,Ascending))

 

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

 

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
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.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

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