cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Power Apps
Power Apps

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

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

Highlighted
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

Highlighted
Helper I
Helper I

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
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,189)