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

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (3,714)