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

Visibility using Or, or ||

Hi all!

 

I'm looking for a "cheat" if you will, on how to shorten the method I want to use to display something.

 

I have a label that I only want to appear if the words left, right, or both are selected in numerous comboboxes. I know this sounds strange, just bear with me here.

 

I was hoping that something like:

 

"Left" || "Right" || "Both" in combobox1.SelectedItems.Value

 

would work, but it only evaluates against "Both".

 

I'm aware I can type out something like:

 

"Left" in combobox1.SelectedItems.Value || "Right" in combobox1.SelectedItems.Value || "Both" in combobox1.SelectedItems.Value

 

and it would work perfectly, but as I stated above I have numerous comboboxes and am looking for an easier method to display this thing.

 

Any advice is appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Visibility using Or, or ||

If the selection mode in the combobox is single elements (SelectMultiple = false), then you can use this expression:

ComboBox1.Selected.Value in ["Left", "Right", "Both"]

If the combobox can have multiple selections, then you can use a combination of the ForAll and Sum functions to check whether the values are part of the selection or not:

Sum(
    ForAll(
        ["Left", "Right", "Both"],
        If(Value in ComboBox1.SelectedItems.Value, 1, 0)),
    Value) > 0

But at this point the expression is starting to get almost as complicated as the one that you have:

"Left" in combobox1.SelectedItems.Value ||
"Right" in combobox1.SelectedItems.Value ||
"Both" in combobox1.SelectedItems.Value

So it's up to you to decide which one you like the best 🙂

View solution in original post

3 REPLIES 3
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Visibility using Or, or ||

If the selection mode in the combobox is single elements (SelectMultiple = false), then you can use this expression:

ComboBox1.Selected.Value in ["Left", "Right", "Both"]

If the combobox can have multiple selections, then you can use a combination of the ForAll and Sum functions to check whether the values are part of the selection or not:

Sum(
    ForAll(
        ["Left", "Right", "Both"],
        If(Value in ComboBox1.SelectedItems.Value, 1, 0)),
    Value) > 0

But at this point the expression is starting to get almost as complicated as the one that you have:

"Left" in combobox1.SelectedItems.Value ||
"Right" in combobox1.SelectedItems.Value ||
"Both" in combobox1.SelectedItems.Value

So it's up to you to decide which one you like the best 🙂

View solution in original post

Super User
Super User

Re: Visibility using Or, or ||

Hi @i_reminisce

In addition to  @CarlosFigueira's great examples, if the combobox has multiple selections, another method you can use is to combine the list of selected combobox values into a single string and to use a Regular Expression to search for a match.
The syntax would look like this.

IsMatch(Concat(ComboBox1.SelectedItems,Value & " ") ,
        ".*(Left|Right|Both).*"
)

Here's a link that explains the alternation expression in more detail:

https://www.regular-expressions.info/alternation.html

i_reminisce
Level: Powered On

Re: Visibility using Or, or ||

Thanks for the awesome suggestions!

 

My comboboxes in this case are just single choice, so your first method will at least save me a little bit of time!

 

Also, thanks @timl for your idea, that can actually work for me down the road in this same app haha.

Helpful resources

Announcements
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 Kudoed Authors (Last 30 Days)
Users online (5,488)