web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Sort by Multiple Values
Power Apps
Answered

Sort by Multiple Values

(0) ShareShare
ReportReport
Posted on by 14

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 

 

Categories:
I have the same question (0)
  • HadynM Profile Picture
    279 on at

    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 Profile Picture
    14 on at

    Hello Hayden,

     

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

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

     

    Paul 

  • PaulRGemme Profile Picture
    14 on at

    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 Profile Picture
    14 on at

    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
    )
    })

     

     

     

     

  • Verified answer
    HadynM Profile Picture
    279 on at

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

    Cheers

  • PaulRGemme Profile Picture
    14 on at

    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

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard