cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
i_reminisce
Helper I
Helper I

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
CarlosFigueira
Power Apps
Power Apps

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
CarlosFigueira
Power Apps
Power Apps

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 🙂

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

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
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (4,371)