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

Need to comapare multiple conditions in the If loop in Power Automate Desktop

I need to compare the Name and the status of employee are matching or not using IF loop how to compare multiple conditions in the If loop using "AND" and "OR" Operators

15 REPLIES 15
PetrosF-MSFT
Microsoft
Microsoft
Radhika1
Helper IV
Helper IV

Hi,

 

I need to multiple conditions in the If statement.

I have many files of the same pattern, out of it I do not want to delete certain files starting with specific name followed by number ex. 'ABC-1234'.

I tried the following, but it is not working. Please help for the solution.

 

 

Radhika1_0-1632904970474.png

 

I would approach this completely differently. 

set up a temp folder

get files in folder ABC-1234*
move files to temp

get files in folder RES-1564*

move files to temp

get files in folder FED-1234*
move files to temp

get all files in folder

delete files

get all files in temp

move files back to folder

Thanks for your reply and it works.

I posted this to know whether multiple conditions are possible in a single if statement for my scenario.

 

Here are some ideas you can try, but the solution I know will work is below the dotted line.

 

Here: https://docs.microsoft.com/en-us/power-automate/desktop-flows/variable-manipulation

 

It says you can do this:

MichaelAnnis_0-1632926486864.png

I personally don't think this would work, because the operator is built into IF, and it doesn't give an And/Or option.

 

On the other hand, you can do nested If's to accomplish AND functions:

  • If name is
    • If status is
      • Do something
    • EndIF
  • EndIF

So in this example, it would only "Do something" If both statements were true.

--------------------------------------------------------------------------------------------------

Solution that will definitely work:

 

You can use Switch & Case to handle all possibilities of AND/OR Functions, but this gets complicated.  You have to set each If Statement to True (1) or False (0), so that looks like this:

  • If Name is True
    • Set Variable %NameIF% to (1)
  • Else
    • Set Variable %NameIF% to (0)
  • EndIF
  • IF Status is True
    • Set Variable %StatusIF% to (1)
  • Else
    • Set Variable %StatusIF% to (0)
  • EndIF
  • Set Variable %Result% to 'Name%NameIF%,Status%StatusIF%' 

#I used text other than just numbers in %Result% so it didn't mistake it for a number and turn "01" into "1".

 

Now that you have the result variable, which is 1 of 4 options, you can use Switch Case to "do something" based on your result:

  • Switch %Result%
    • Case Name0,Status0
      • Do something for 0,0
    • Case Name0,Status1
      • Do something for 0,1
    • Case Name1,Status0
      • Do something for 1,0
    • Case Name1,Status1
      • Do something for 1,1

Best of luck!

PAG
Frequent Visitor

Here is another approach with OR conditions, using a list and looping items:

https://power.automate.gallery/LIhE73Pp1sy4 

shindomo
Continued Contributor
Continued Contributor

Hello @Radhika1 

 

You can use multiple conditions in IF statement. 🙂

 

You would better to check the solution posted by @sakula1996  in the thread below:

Solved: If condition logic - Power Platform Community (microsoft.com)

 

Also yet another thread discussing the same issue you should read through:

How to include the logical AND/OR operators in con... - Power Platform Community (microsoft.com)

 

Thank you.

Highboy
Continued Contributor
Continued Contributor

Highboy_0-1633334355239.png

Highboy_1-1633334436955.png

 

Highboy
Continued Contributor
Continued Contributor

And/Or is working just fine
Try This example

Highboy_3-1633335160295.png

 

Highboy_4-1633335192040.png

 

Hi,

Thank you for your response!

Actually the match starts with 'ABC-1234' and after that it contains some text (ABC-1234 ttttccvvfilename.pdf). So, I cannot give Match = ABC-1234, I have to give it like Match does not start with 'ABC-1234'. Any idea how to implement?

 

 

Highboy
Continued Contributor
Continued Contributor

Me setting Match to "ABC-1234" was only because i did not want to do the parse and to show how the multiple or's worked

Highboy
Continued Contributor
Continued Contributor

My suggestion would be

For each CurentItem9 in files
  Parse text
    If %match% is empty

      Delete file

   end
end

That is if what you are trying to do is to delete all files not starting with ABC-1234 or RES-1564 or FED-1234

Hi,

 

I have to give two if conditions,

 

For each CurentItem9 in files
  Parse text
    If %match% isn't empty

      if %match% doesn't starts with ABC-1234 or RES-1564 or FED-1234

       Delete file

   end
end

 

because I have other files which have a same pattern as ABC-1456(numbers will vary) which should be deleted.

Highboy
Continued Contributor
Continued Contributor

This will check for the two conditions you need.
Replace the Set variable with your parse function

 

Highboy_2-1633338562149.png

 

 

Highboy_3-1633338592224.png

 

 

It is working perfectly! 

Thank you for the solution.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,264)