cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ericonline
Community Champion
Community Champion

AND works, OR works, but not AND( OR( ) ) ?

Hello, 

Need some eyes on this.. I feel like I've run into this before but can't recall what I'm doing wrong. 

Scenario:

  • Toggle1 Control INSIDE a Gallery
  • Toggle2 Control OUTSIDE a Gallery
  • Trying to build a "Toggle-all" option outside the Gallery
  • Trying to set the Default Property of Toggle1 based on Toggle2 

Toggle1- INSIDE Gallery:

  • Here are the debug steps I've taken (read code comments):
    • /*===================================================
      Results in "pass"
      ===================================================*/
      If( Or( ThisItem.status = "off", IsBlank(ThisItem.status) ), "pass", "fail")
      /*===================================================
      Results in "pass"
      ===================================================*/ If( Toggle2.Value = true, "pass", "fail")
      /*===================================================
      Results in "fail" WHY?
      ===================================================*/ If(
      Or(
      ThisItem.status = "off",
      IsBlank(ThisItem.status)
      ),
      false,
      And(
      Or(
      ThisItem.status = "off",
      IsBlank(ThisItem.status)
      ),
      Toggle2.Value = true
      ),
      Toggle2.Value,
      true
      )
1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @ericonline ,

Could you please share a bit more about your scenario?

Could you please show more details about the "Results in "fail" WHY?"? What happens with your formula?

 

Based on the formula that you mentioned, I think there is something issue with it. If the first condition within your If function is true, the result your If function returns is always true, regardless of whether you check or uncheck your Toggle 2 control.

In other words, if the first condition in your If function is met, the following conditions within the If function would not be executed.

More details about the If function in PowerApps, please check the following article:

If function

 

I have made a test on my side, please take a try with the following formula (set the Default property of the Toggle 1 control to following😞

If(
    Toggle2.Value = true,
    true,     /* <-- You could also consider type Toggle2.Value here */
    If(
          ThisItem.status = "off" || IsBlank(ThisItem.status),
          false,
          true
      )
)

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
RandyHayes
Super User
Super User

@ericonline  so in your formula, I read it as:

If ConditionA is true, false, otherwise If ConditionB is true, then true.

Condition A is field is "off" or Blank

Condition B is field is "off" or Blank and Toggle is true and Toggle is true (you are and'ing the toggle value twice).

 

So, if I boil this down, I am seeing that you are really just looking to see if any of these conditions are met. 

If I look at the inverse of the problem, it seems that, if the item is "on" and not Blank, it should be "on"/true.

 

What I am missing from your end-goal is, are you trying to use the Toggle2 as a master "on" or master "off" toggle?

 

If you are trying to do master "on", then your formula should be:

   !(ThisItem.Status="Off") || IsBlank(ThisItem.Status) || Toggle2.Value

If the status is not "off" or the status is blank or the toggle is on = set to on.

Or:

  (!(ThisItem.Status2="Off") && !IsBlank(ThisItem.Status2)) || Toggle22.Value

If the status is not "off" and the status is not blank OR the toggle is on = set to on

Or:

  !(ThisItem.Status2="Off") && !IsBlank(ThisItem.Status2) || (Toggle22.Value && !IsBlank(ThisItem.Status2))

If the status is not "off" and the status is not blank OR the toggle is on and the status is not blank = set to on

 

You might give the shortened notation (&& || !) a try over using the And, Or and Not as a formula - makes it a little easier to digest the logic.

 

Hope this helps some.

 

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

You will need to add an If(  in front of the And, along with the closing ). In BOLD below.

===================================================*/
If(

    Or(
        ThisItem.status = "off",
        IsBlank(ThisItem.status)
    ),
    false,
    If(And(
        Or(
            ThisItem.status = "off",
            IsBlank(ThisItem.status)
        ),
        Toggle2.Value = true
        ),
        Toggle2.Value,
    true

     )
)

v-xida-msft
Community Support
Community Support

Hi @ericonline ,

Could you please share a bit more about your scenario?

Could you please show more details about the "Results in "fail" WHY?"? What happens with your formula?

 

Based on the formula that you mentioned, I think there is something issue with it. If the first condition within your If function is true, the result your If function returns is always true, regardless of whether you check or uncheck your Toggle 2 control.

In other words, if the first condition in your If function is met, the following conditions within the If function would not be executed.

More details about the If function in PowerApps, please check the following article:

If function

 

I have made a test on my side, please take a try with the following formula (set the Default property of the Toggle 1 control to following😞

If(
    Toggle2.Value = true,
    true,     /* <-- You could also consider type Toggle2.Value here */
    If(
          ThisItem.status = "off" || IsBlank(ThisItem.status),
          false,
          true
      )
)

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,831)