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

How to include the logical AND/OR operators in conditionals

I would like to know how to include the logical AND/OR operators in conditionals, previously on WinAutomation this could be achieved like this:

 

The AND "&&" operator can be used inside an "If" condition using the following format

 

First Operand: %TextVar_1 == "ABC" && TextVar_2 == "DEF"%

Operator: =

Second Operand: True

 

The OR "||" operator can be used in a similar way

 

First Operand: %TextVar_1 == "ABC" || TextVar_2 == "DEF"%

Operator: =

Second Operand: True

 

I have tried to express it in this way in Power Automate Desktop and it is not working.

 

In my case I am reading a single cell value from excel which is stored into the variable %ExcelData%, I would like to use an If conditional to review if the variable's value is either "Payer" or "Doc" I need it to do certain actions, but if it is blank I need it to go into a different set of actions.

 

I have already tried to express it in different ways but I haven't been able to achieve this logic, this is what I have tried so far:

 

First Operand: %ExcelData = "Payer" || ExcelData = "Doc"%

Operator: =

Second Operand: True

 

With the above conditional I get an Invalid Value message, you might have noticed I removed the double equal signs, I have tried with the double equal signs and it also says invalid value in this way.

 

First Operand: %ExcelData = 'payer'% || %ExcelData = 'doc'%

Operator: =

Second Operand: True

 

The above conditional is accepted by PAD but when I run it it doesn't seem to be working as intended as it is not realizing that the cell value is actually Payer.

 

 

 

 

 

 

 

 

21 REPLIES 21
adijain
Microsoft
Microsoft

Hello @AlanYC ,

 

Thank you for bringing this issue to us. We will investigate this further on our end and get back to you with the correct syntax for using AND/OR operators. For now, could you please instead use the workaround of using two if conditions to verify the ExcelData var for both 'Payer' and 'Doc' separately. 

 

Thanks for trying out Power Automate Desktop!

Thank you, I will wait for your reply. I am currently using the workaround that you mentioned of creating two separate conditionals.

adijain
Microsoft
Microsoft

Hi @AlanYC,

 

Please find the syntax for the logical AND/OR operators in PAD conditionals below:

  • AND instead of && 
  • OR instead of ||
  • = instead of ==

Example:

temp.JPG

 

Please let us know if you have any further questions.

 

Thanks,

Aditya

Good afternoon @adijain , I'm Efrain from Panama. 

 

I'm Developer, but at the same I'm new in Power Automate. And I need to know the next info:

I was trying use this logic but I have question. Can I use the second operand as result? This question is because I need to do a comparison of two variables, but I need the result as TRUE or FALSE value.

 

I'm testing new apps to my company, and one these apps POD. 

 

Regards.

miketran13
Impactful Individual
Impactful Individual

Thanks a lot for this Adijain, it was thing I am looking for. It helps a lot and can reduce the complexity of my process.

 

Regards,

Mike

Use a Set variable to write the result of a boolean expression into something to use later.

HI @efrainC_Onq, thanks for the question, you would need to set the first operand as a variable, like what @Henrik_M  suggested and then that variable will have the result as True or False - as shown below:

adijain_0-1611747090334.png

In above, the %NewVar% will have either True or False value.  Hope it makes sense. 

vtse
Frequent Visitor

Hi,

try the following

 

set the two values payer and doc as variables var1 and var2

then use the if action as following 

First operand    %ExcelData== var1 || ExcelData== var2%

operator equals (=)

second operator TRUE

Hi,

 

this should be:

 

First Operand: %ExcelData = 'payer'% || %ExcelData = 'doc'%

Operator: =

Second Operand: %True%

ericcho
New Member

To expand on this topic....what is the proper notation for operators that are not straight up equals?

For example I want to quality something that contains "payer" or startswith "doc"

....something along the lines of:

 

%contains(ExcelData,'payer') OR startswith(ExcelData,'doc')%

 

Thanks in advance

Anonymous
Not applicable

Hello @ericcho 

 

We can use conditional functions such like Contains() or StartsWith() in [First operand] of If action.

 

For example:

%Contains(VAR, 'KEY', False) OR StartsWith(VAR, 'KEY', False)%

 

* The 3rd argument of each function means "Ignore case = False" thus "Case sensitive".

 

 

shindomo_0-1635588263115.png

 

shindomo_1-1635588272313.png

 

[List of available 8 functions]

  • Contains(VAR, 'KEY', False)
  • NotContains(VAR, 'KEY', False)
  • IsEmpty(VAR)
  • IsNotEmpty(VAR)
  • StartsWith(VAR, 'KEY', False)
  • NotStartsWith(VAR, 'KEY', False)
  • EndsWith(VAR, 'KEY', False)
  • NotEndsWith(VAR, 'KEY', False)

 

Thank you.

This is great!! How did you find out? 🤔

Anonymous
Not applicable

Hello @Henrik_M 

Thanks for your resonse.

Here is how did I find it out. 🙂

 

1) I have set up 8 different conditions for each of the empty IF actions.

 

shindomo_0-1635766448282.png

 

For example (Operator = "Contains"):

shindomo_1-1635766606568.png

 

2) Copy & Paste the code from Flow Designer to Notepad.

 

SET VAR TO $'''ABC'''
IF Contains(VAR, $'''KEY''', False) THEN
END
IF NotContains(VAR, $'''KEY''', False) THEN
END
IF IsEmpty(VAR) THEN
END
IF IsNotEmpty(VAR) THEN
END
IF StartsWith(VAR, $'''KEY''', False) THEN
END
IF NotStartsWith(VAR, $'''KEY''', False) THEN
END
IF EndsWith(VAR, $'''KEY''', False) THEN
END
IF NotEndsWith(VAR, $'''KEY''', False) THEN
END

 

3) I guessed that these conditional functions in Robin language could be used in the first operand of the IF action... Bingo!

businesstaken
Frequent Visitor

thanks a lot, very useful

StanAtFlumerics
Regular Visitor

If somebody has issues with power automate desktop's if conditions and Boolean comparisons / values:

I had to enclose the True/False value in % characters, like variables:

 

First Operand: %SomeVariable%

Operator: =

Second Operand: %True%

Hi,

 

Thanks for this trick. What if we need to check a web page contains 2 text. Let us say we will use "If web page contains" action

 

Here I want to check If web page does not contains a text with OR operator, I have tried many ways but no luck. Below one doesn't work or doesn't properly check the conditions  

 

Marutha_K_0-1664437229721.png

 

or & and statements only work inside %'s, you're just literally searching for "ALL SALES ARE FINAL OR limited availability" the OR does not separate anything on its own as that would be weird. Also OR & AND only support boolean values, so this wouldn't work anyway, instead I recommend just using an "Else If" in your IF statement as that's the closest you can get to an OR.

momlo
Helper V
Helper V

You could also grab the source code of the page, then parse with regex, then use IF to see if your variable returned by regex it empty or not.

 

IF (NotContains(Browser, 'All Sales Are Final', True) OR NotContains(Browser, 'Limited Availability', True)) = $'''True''' THEN

 

Which looks like this:

JasonWS_0-1665063806931.png

 

If I wanted to run actions when the webpage contains neither of those phrases, I would use an AND operator instead.

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.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

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