cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Diamonddedo
Frequent Visitor

How to conditionnally pass parameters to Filter function in Powerapps ?

Hi ! I'm looking to build an app which requires for me to filters conditionnally the filters that I need.

 

Here is what I'm trying to do :

 

 

 

Filter(table, If(Sites_Filter <> "Tous", Site.Value = Sites_Filter, true) || If(Groupes_Dropdown.SelectedText.Value <> "Tous", GroupeID = Groupes_Dropdown.Selected.ID, true)

 

 

Can I use Filter() in a way that if condition is true, it uses my first argument as a Filter

 

If(Sites_Filter <> "All", arg to use as a Filter is true, arg to ignore if false)

 

Thanks 

5 REPLIES 5
Nogueira1306
Super User
Super User

If(Sites_Filter <> "Tous", 
   Filter(Table, Site.Value = Sites_Filter),
   If(Groupes_Dropdown.SelectedText.Value <> "Tous", 
      Filter(GroupeID = Groupes_Dropdown.Selected.ID),
      Table
    )
)

 

Try that

 

If you need additional help please tag me in your reply and please like my reply.
If my reply provided you with a solution, pleased mark it as a solution ✔️!

Best regards,

Gonçalo Nogueira

Check my LinkedIn!

Buy me a coffee!

Check my User Group (pt-PT)!

Last Post on Community

My website!

RandyHayes
Super User
Super User

@Diamonddedo 

Yes, you can do that, although using If statement in the filter function is generally a bad practice.

Please consider changing your Formula to the following:

Filter(table, 
    (Sites_Filter <> "Tous" || Site.Value = Sites_Filter) && 
    (Groupes_Dropdown.Selected.Value <> "Tous" || GroupeID = Groupes_Dropdown.Selected.ID)
)

Working with a simple Boolean result to the second parameter of the Filter function is preferred. 

 

The above should give you what you are looking for.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Your solution works great, it just miss one thing, whenever the condition is false, i'll need Filter() to ignore the filter

 

For example with Sites_Filter <> "Tous"

 

If Sites_Filter == "Tous", then no Filter is applied

If Sites_Filter <> "Tous", then the Filter Site.Value = Sites_Filter is applied

 

I don't know if you see what I mean

RandyHayes
Super User
Super User

@Diamonddedo 

That is correct in the formula.

If you look at the boolean logic in it, then it reads just as you mention.

 

However, you are also introducing another dropdown into the formula - doesn't that play a part of your results as well?  You did not mention that in your reply - only the Sites_Filter.

 

You are kind of looking at it as a "do this", or "or this instead" - which doesn't really apply here.  

The filter function is quite basic, what it does is evaluate every row of your datasource against the value in the second parameter of the filter function.

   Filter(<datasource>,  <trueOrFalseCriteria>)

Every record is evaluated against the formula in the second parameter, so if the final result of that evaluation is true, then the record is included in the results.  If it is false, then it is not included.

 

So in the formula provided, if Sites_Filter = "Tous", then that is true.  Since that comparison is in an OR statement, then the rest of the formula is totally irrelevant as a true OR'ed with anything else will always be true (and thus the row included - i.e. "not filtered").

 

The only difference in the formula provided is that it also includes the Groupes dropdown.  I am not sure how you are expecting to account for that based on your last reply.

If you could clarify how that play a part, then that would be helpful.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

I'm sorry if I didn't explained myself very well

 

I need to check if a condition is true or false, then if it's true, pass the filter that the Filter() function need to add.

 

For example let's say that Sites_Filter is set to "Tous" and Groupes_Dropdown is Set to X

 

Since Sites_Filter is set to "Tous" Then I need Filter() to ignore that parameter, and not filter the table by this value,

Where as Groupes_Dropdown isn't set to "Tous" so I need to Filter in my table every records where groupe = X

 

Which is why I wanted to do conditional parameters like so :

 

Filter(data, If(condition_is_true, Filter_to_use, true) && ...)   Here if my condition is true, then the If function returns the Filter that Filter() needs to use, if my condition is false, then it's passed true, which would be "ignored" since true is always true i guess.

 

Please tell me if I need to explain myself again, English is not my native language, sorry for the bad explanation

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,176)