cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PaulRGemme
Level: Powered On

Sort by Multiple Values

Hello All,

 

I am new to Power Apps and  trying to get the sorting function to work.

I have an app that was built and originally only had 2 days to select from, and it was requested to add another day.

 

I can get it to sort if only one day is selected, and also if all 3 are selected.

 

How can I get this to sort by 2 fields selected; IE if tuesday and wednesday are selected should show all  available tuesday and wednesday slots.  Attached are code I am currently using.

 

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

 

If(TueCheckBox.Value = true And WedCheckBox.Value = false And ThurCheckBox.Value = false,
If(month_dropdown.Selected.Value = "All",
SortByColumns(Filter('Massage Bookings', Weekday(Start_x0020_Time) = 3 And Status.Value =

"Open" And DateDiff(Now(), Start_x0020_Time) >= 0 ),"Start_x0020_Time"),
SortByColumns(Filter('Massage Bookings', Weekday(Start_x0020_Time) = 3 And Status.Value =

"Open" And DateDiff(Now(), Start_x0020_Time) >= 0 And _Month = Month(Start_x0020_Time) ),"Start_x0020_Time")),


If(TueCheckBox.Value = false And WedCheckBox.Value = true And ThurCheckBox.Value = false,
If(month_dropdown.Selected.Value = "All",
SortByColumns(Filter('Massage Bookings', Weekday(Start_x0020_Time) = 4 And Status.Value =

"Open" And DateDiff(Now(), Start_x0020_Time) >= 0 ),"Start_x0020_Time"),
SortByColumns(Filter('Massage Bookings', Weekday(Start_x0020_Time) = 4 And Status.Value =

"Open" And DateDiff(Now(), Start_x0020_Time) >= 0 And _Month = Month(Start_x0020_Time) ),"Start_x0020_Time")),


If(TueCheckBox.Value = false And WedCheckBox.Value = false And ThurCheckBox.Value = true,
If(month_dropdown.Selected.Value = "All",
Filter('Massage Bookings', Weekday(Start_x0020_Time) = 5 And Status.Value = "Open"

And DateDiff(Now(), Start_x0020_Time) >= 0 ),
Filter('Massage Bookings', Weekday(Start_x0020_Time) = 5 And Status.Value = "Open"

And DateDiff(Now(), Start_x0020_Time) >= 0 And _Month = Month(Start_x0020_Time))),

If(Instructor_dropdown.Selected.Value = "Doesn't matter",
If(TueCheckBox.Value= true And WedCheckBox.Value = true And ThurCheckBox.Value = true,
If(month_dropdown.Selected.Value = "All",
SortByColumns(Filter('Massage Bookings', Status.Value = "Open" && DateDiff(Now(), Start_x0020_Time)
>= 0),"Start_x0020_Time"),
SortByColumns(Filter('Massage Bookings', Status.Value = "Open" And DateDiff(Now(), Start_x0020_Time)
>= 0 And _Month = Month(Start_x0020_Time)),"Start_x0020_Time")))))))

Any Help would be greatly appreciated.

 

Thank you,

Paul 

 

1 ACCEPTED SOLUTION

Accepted Solutions
HadynM
Level 8

Re: Sort by Multiple Values

Add it, the other stuff is still relevant to your app.

Cheers

View solution in original post

6 REPLIES 6
HadynM
Level 8

Re: Sort by Multiple Values

Hi @PaulRGemme

To me, there is one step that will greatly simplify the function - using a collection to hold the days selected.

In the screen OnVisible add:

 

ClearCollect(SelectedDaysCollection ,[])

This will create an empty collection ready to capture the days the user chooses.

 

 

For the checkbox controls for each day, there are two actions: OnCheck and OnUncheck.

For the Tuesday checkbox OnCheck add the following:

Collect(SelectedDaysCollection,{Value:3})

For the Uncheck add:

RemoveIf(SelectedDaysCollection,Value=3)

Do the same for the other two days, changing the value to match the Weekday of that control.

When testing it should look something like this

sample.JPG

 

Now your function can be something similar to:

SortByColumns(
    Filter('Massage Bookings', 
        Weekday(Start_x0020_Time) in SelectedDaysCollection 
        And Status.Value = "Open" 
        And If(month_dropdown.Selected.Value = "All",Start_x0020_Time >= Now(),_Month = Month(Start_x0020_Time))
    ),
"Start_x0020_Time")

The great thing about using In with a collection is if they decide to add another day for the user to choose from you only need to add another checkbox.

Hope that helps.

Hadyn

PaulRGemme
Level: Powered On

Re: Sort by Multiple Values

Hello Hayden,

 

That worked perfectly, and so much more simplfied to maintain!

Thank you for sharing your knowledge- it is Greatly Appreciated!

 

Paul 

PaulRGemme
Level: Powered On

Re: Sort by Multiple Values

Actually, This was working  in edit / play mode, but now that I have published it, it does not work correctly. Any ideas why that would be?

 

Paul

PaulRGemme
Level: Powered On

Re: Sort by Multiple Values

Hi Hayden,

 

IN trying to get this to work when published...

Below is the code I currently have for "Onvisible" on the brrowse gallerry screen.

 

when adding - ClearCollect(SelectedDaysCollection ,[]) do I add this to the exisiting code, or should I delete what was originally there?

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

Refresh('Massage Bookings');
UpdateContext({
_Month1 : Switch(
Month(First(Filter('Massage Bookings', Status.Value = "Open" && DateDiff(Now(), Start_x0020_Time) >= 0)).Start_x0020_Time),
1, "Jan 2019",
2, "Feb 2019",
3, "Mar 2019",
4, "Apr 2019",
5, "May 2019",
6, "June 2019",
7, "July 2019",
8, "Aug 2019",
9, "Sep 2019",
10,"Oct 2019",
11,"Nov 2019",
12,"Dec 2019",
"No value"
)
});

UpdateContext({
_Month : Switch(
month_dropdown.Selected.Value,
"Jan 2019", 1,
"Feb 2019", 2,
"Mar 2019", 3,
"Apr 2019", 4,
"May 2019", 5,
"June 2019", 6,
"July 2019", 7,
"Aug 2019", 8,
"Sep 2019", 9,
"Oct 2019", 10,
"Nov 2019", 11,
"Dec 2019", 12
)
})

 

 

 

 

HadynM
Level 8

Re: Sort by Multiple Values

Add it, the other stuff is still relevant to your app.

Cheers

View solution in original post

PaulRGemme
Level: Powered On

Re: Sort by Multiple Values

Hello Hayden,

 

I had implemted this solution for displayiong the days, and works perfectly.

 

I was wondering how I could also add seletced Months?

There would be a drop down menu to display the month, and depnding on month selected  it would shows the days available for that month?

any help would be greatly appreciated

 

 

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,840)