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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Combining filter/sort/...
Power Apps
Unanswered

Combining filter/sort/search

(0) ShareShare
ReportReport
Posted on by 909

Hello,

 

I am currently troubled with my Gallery as I try to implement some Filters.

 

I have this function:

Sort(Filter(Search(IdeaBox_1;SearchBox.Text;"Nazwa";"Opis"); Utworzony >= DatePicker1.SelectedDate &&
Utworzony <= DatePicker2.SelectedDate); Utworzony; If(SortDescending2;Descending;Ascending)) 

It allow me to use SearchBox data input (and filter by some stuff Nazwa-Name/Opis-Description).

It also allows me to use DatePickers, and button date ascending/descending that filter 'Utworzony" = Date of creation

 

I need to apply this filter on top of that function:

Filter(IdeaBox_1;'Utworzone przez'.Email=User().Email)

This is the most important filter as this filter the gallery view to only "my" propositions. This is crucial as in this view I allow users to delete/edit theirs propositions.

 

And I need default sort that will sort propositions in accordance with likes that they received. This was used here:

 

Sort(
Sort(Search(IdeaBox_1;SearchBox.Text;"Nazwa";"Opis");Utworzony;If(SortDescending2;Descending;Ascending));
Polubienia;Descending)

Sort(Polubienia;Descending)

 

I would love to have a priority like that:

 

1. Default view Filter(IdeaBox_1;'Utworzone przez'.Email=User().Email)

2. Default sort  Sort(Polubienia;Descending)

3. Optional sort - rest of the stuff (SearchBox - input box, Utworzony - Created, SortDescending2 - Date asc/desc sort).

 

I also would like to avoid situation with with nested - sort. For example when I Likes were on top of Sort they couldn't be overrided - so for example it was sorting like that:

 

3 likes - 12.09

3 likes - 11.09

3 likes - 14.09

2 likes - 11.09

2 likes - 09.09

 

Normaly date filter asc/desc should sort it like that:

 

2 likes - 09.09

2 likes - 11.09

3 likes - 11.09

3 likes - 12.09

3 likes - 14.09

 

But with nested sorts it is like that:

 

3 likes - 11.09

3 likes - 12.09

3 likes - 14.09

2 likes - 09.09

2 likes - 11.09

 

Likes always has a priority over date.

 

Please help me to finish this as it is beyond my capability.

I've read a lot about Sort,Filter but this is so far too hard.

 

 

 

Categories:
  • GarethPrisk Profile Picture
    2,828 on at

    My apologies if anything got lost in translation.

    First, I would use a Global Variable for your User's email.

    Set(gblUserEmail;User().Email);;

     Run that in the app's OnStart or anytime ahead before interacting with the data.

     

    For your Gallery's items:

    With({varDataMyRecords: Filter(IdeaBox_1; 'Utworzone przez'.Email = gblUserEmail)};
    With({varDataFilteredByDate: Filter(varDataMyRecords; Utworzony >= DatePicker1.SelectedDate && Utworzony <= DatePicker2.SelectedDate)};
    	SortByColumns(
    		Search(varDataFilteredByDate; SearchBox.Text; "Nazwa";"Opis");
    		"Polubienia"; Descending; "Utworzony"; If(SortDescending2;Descending;Ascending)
    		)
    	)
    )

    There are a number ways to accomplish this, including a single set of Filter criteria, and then appropriate wrapping of functions. However, the way it is written above may be simpler to decode and process, and should ultimately be almost identical (if not more efficient, when processing).

    In a nutshell:

    • The first With establishes a contextual variable of the records filtered to just the User
    • The next With establishes a filtered version of the User's data, per the Date ranges
    • Then we are using that filtered user data, by date, and filtering it further (potentially) based on a Search
    • The eventual resulting data set is then sorted first by "Polubienia" (Descending)
    • It is then sorted further, by "Utworzony" (dynamic direction, based on variable)

    Hopefully you can paste that in without much issue.

     

    A single code-block would be something like:

    SortByColumns(
    	Search(
    		Filter(
    			IdeaBox_1; 'Utworzone przez'.Email = gblUserEmail; Utworzony >= DatePicker1.SelectedDate && Utworzony <= DatePicker2.SelectedDate
    		);
    	SearchBox.Text; "Nazwa";"Opis"
    	);
    "Polubienia"; Descending; "Utworzony"; If(SortDescending2;Descending;Ascending)
    )
  • Elitezone Profile Picture
    909 on at

    @GarethPrisk 

    This was a great explanation. Thank you - I learned a lot.

    Regarding the function I however received two errors:

     

    Elitezone_0-1600844258336.png

    First function SortByColumns has invalid arguments.

    "Utworzony" (Created) does not exist.

     

    But it does exist! It is in the same gallery on label:

    "Data utworzenia: " & ThisItem.Utworzony

    and it shows data (date value).

     

    Here is this field in Sharepoint also:

    Elitezone_1-1600844993685.png

     

  • GarethPrisk Profile Picture
    2,828 on at

    The context variables may have made the exact schemas inaccessible. Typically, if you're not shaping the data, it's not a problem. Since we are stacking variables the context may be off; hard to troubleshoot without being hands on. 

     

    Can you try the second example I provided, to see if it gives the same error?

  • Elitezone Profile Picture
    909 on at

    @GarethPrisk 

     

    Elitezone_0-1600860571392.png

     

     

     

    Same error.

    When I use this formula with this error it always shows 0 results.

     

    By the way I just noticed that I used wrong datepickers/input text (I took it from another gallery that works better).

    I updated the formula:

     

     

    SortByColumns(
    	Search(
    		Filter(
    			IdeaBox_1; 'Utworzone przez'.Email = gblUserEmail; Utworzony >= DatePicker1_1.SelectedDate && Utworzony <= DatePicker2_1.SelectedDate
    		);
    	SearchBox_Priv.Text; "Nazwa";"Opis"
    	);
    "Polubienia"; Descending; "Utworzony"; If(SortDescending2;Descending;Ascending)
    )

     

    Tried to change some stuff - do input, change datepicker date but nothing worked...

     

    Gareth if this does not work maybe we can delete SortDescending - I can afford that if the others filters/sort functions will work.

    If you cannot help me fix this function please help me to delete Utworzony iF(SortDescending). I tried to do that but the function fails.

    I can have one less filter.

     

     

  • Elitezone Profile Picture
    909 on at

    @GarethPrisk 

    I kindly ask for further help. Without your function my application will not work correctly.

     

    Thank you.

  • Elitezone Profile Picture
    909 on at

    Anyone else can help me?

  • Elitezone Profile Picture
    909 on at

    Currently my formula looks like that:

     

    Sort(Filter(Search(AddColumns(IdeaBox_1;"AuthorName";'Utworzone przez'.DisplayName);SearchBox.Text;"Nazwa";"Opis";"AuthorName"); (Utworzony) >= DatePicker1.SelectedDate && (Utworzony) <= DatePicker2.SelectedDate +1); Utworzony; If(SortDescending2;Descending;Ascending))

    I only need to add a defalt filter "Polubienia" - descending. This is a field that has amount of like provided. I would like to have this by default, but be adjustable. 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 194 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 150

Last 30 days Overall leaderboard