ערוך

שתף באמצעות


Use expressions in conditions to check multiple values

In this tutorial, you'll learn to use expressions and conditions to compare multiple values in Advanced mode.

When you create a cloud flow, you can use the Condition card in basic mode to quickly compare a single value with another value. However, there're times when you need to compare multiple values. For example, you might want to check the value of a few columns in a spreadsheet or database table.

You can use any combination of the following logical expressions in your conditions.

Expression Description Example
and Takes two arguments and returns true if both values are true.
Note: Both arguments must be Booleans.
This expression returns false:
and(greater(1,10),equals(0,0))
or Takes two arguments and returns true if either argument is true.
Note: Both arguments must be Booleans.
This expression returns true:
or(greater(1,10),equals(0,0))
equals Returns true if two values are equal. For example, if parameter1 is someValue, this expression returns true:
equals(parameters('parameter1'), 'someValue')
less Takes two arguments and returns true if the first argument is less than the second argument.
Note: The supported types are integer, float, and string.
This expression returns true:
less(10,100)
lessOrEquals Takes two arguments and returns true if the first argument is less than or equal to the second argument.
Note: The supported types are integer, float, and string.
This expression returns true:
lessOrEquals(10,10)
greater Takes two arguments and returns true if the first argument is greater than the second argument.
Note: The supported types are integer, float, and string.
This expression returns false:
greater(10,10)
greaterOrEquals Takes two arguments and returns true if the first argument is greater than or equal to the second argument.
Note: The supported types are integer, float, and string.
This expression returns false:
greaterOrEquals(10,100)
empty Returns true if the object, array, or string is empty. This expression returns true:
empty('')
not Returns the opposite of a boolean value. This expression returns true:
not(contains('200 Success','Fail'))
if Returns a specific value if the expression results in true or false. This expression returns "yes":
if(equals(1, 1), 'yes', 'no')

Prerequisites

Here's what you'll need to complete this walkthrough.

  • Access to Power Automate.
  • Your own spreadsheet with the tables described later in this walkthrough. Be sure to save your spreadsheet in a location such as Dropbox or Microsoft OneDrive so that Power Automate can access it.
  • Microsoft 365 Outlook (While we use Outlook here, you can use any supported email service in your flows.)

Use the 'or' expression

Sometimes your workflow needs to take an action if the value of an item is valueA or valueB. For example, you may be tracking the status of tasks in a spreadsheet table. Assume that the table has a column named Status and the possible values in this column are:

  • completed
  • blocked
  • unnecessary
  • not started

Here's an example of what the spreadsheet might look like:

Screenshot of a sample spreadsheet with a Status column.

Given the preceding spreadsheet, you want to use Power Automate to remove all rows with a Status column that's set to completed or unnecessary.

Let's create the flow.

Start with a blank flow

  1. Sign into Power Automate.

  2. On the left pane, select My flows.

  3. Select New flow > Scheduled cloud flow.

Add a trigger to your flow

  1. Give your flow a name.

  2. Set the schedule to run the flow once daily.

  3. Select the Create button to go to the next step.

Note

Power Automate uses either the classic cloud flows designer or the cloud flows designer with Copilot. To identify which designer you’re using, go to the Note section in Understand the cloud flows designer with copilot capabilities.

Select the spreadsheet and get all rows

  1. Select New step.

  2. Search for rows, and then select Excel Online (Business).

    Select the get a row action that corresponds to the spreadsheet that you're using. For example, if you're using Google Sheets, select Google Sheets - Get rows.

  3. Select the List rows present in a table action.

    Screenshot of listing rows in a table.

  4. Select the Location, Document Library, File, and Table that contain your data.

    Screenshot of Location, Document Library, File, and Table fields in the List rows present in a table card.

Check the status column of each row

  1. Select New step.

  2. Search for apply to each, and then select the Apply to each - Control.

  3. Add the value token to the Select an output from previous steps box.

    This value token represents the spreadsheet table and all of its data.

  4. Select Add an action on the Apply to each card.

  5. Search for condition, and then select the Condition control.

  6. Add the following Or expression. This Or expression checks the value of each row in the table. If the value of the Status column is completed Or unnecessary, the Or expression evaluates to "true".

    Here's an example of a Condition card.

    Screenshot of an 'or' expression.

Delete matching rows from the spreadsheet

  1. Select Add an action on the If yes branch of the condition.

    The If yes branch runs if the OR condition evaluates to true.

  2. Search for Delete a row, select Excel Online (Business), and then select Delete a row.

  3. On the Delete a row card, set the Location, Document Library, File, and Table boxes exactly as you set these boxes on the List rows present in a table card earlier in this tutorial.

  4. In the Key Column dropdown list, select _PowerAppsId_.

  5. In the Key Value field, insert the _PowerAppsId_ dynamic value.

  6. Save your flow.

Run the flow with the 'or' expression

The flow runs after you save it. If you created the spreadsheet shown earlier in this tutorial, here's what it looks like after the run completes.

Screenshot of the spreadsheet when the 'OR'expression completes.

Notice all data from rows that had completed or unnecessary in the Status column were deleted.

Use the 'and' expression

Assume you have a spreadsheet table with two columns. The column names are Status and Assigned. Assume also that you want to delete all rows if the Status column's value is blocked and the Assigned column's value is John Wonder. To accomplish this task, follow all steps earlier in this tutorial, but when you edit the Condition card in advanced mode, use the and expression shown here.

@and(equals(item()?['Status'], 'blocked'), equals(item()?['Assigned'], 'John Wonder'))

Here's an example of a Condition card.

Screenshot of the 'and' expression.

Run the flow with the 'and' expression

If you've followed the steps in this tutorial, your spreadsheet should look similar to the following screenshot.

Screenshot of the spreadsheet before your flow runs.

After your flow runs, your spreadsheet should look similar to the following screenshot.

Screenshot of the spreadsheet after your flow runs.

Use the 'empty' expression

Notice that there are several empty rows in the spreadsheet now. To remove them, use the empty expression to identify all rows that don't have text in the Assigned and Status columns.

To accomplish this task, follow all steps listed in the Use the 'and' expression section earlier in this tutorial. When you edit the Condition card in advanced mode, use the following empty expression.

@and(empty(item()?['Status']), empty(item()?['Assigned']))

Your Condition card should look similar to the following screenshot.

Screenshot of the 'empty' expression.

After your flow runs, the spreadsheet should look similar to the following screenshot.

SScreenshot of the spreadsheet after 'empty' runs.

Notice extra lines are removed from the table.

Use the 'greater' expression

Imagine you've bought baseball tickets for your coworkers and you're using a spreadsheet to ensure you're reimbursed by each person. You can quickly create a cloud flow that sends a daily email to each person who hasn't paid the full amount.

Use the greater expression to identify the employees who haven't paid the full amount. You can then automatically send a reminder email to those who haven't paid in full.

Here's a view of the spreadsheet.

Screenshot of the spreadsheet of those who haven't paid in full.

Here's the implementation of the greater expression that identifies all persons who have paid less than the amount due from them.

@greater(item()?['Due'], item()?['Paid'])

Use the 'less' expression

Imagine you've bought baseball tickets for your coworkers, and you're using a spreadsheet to ensure you're reimbursed by each person by the date to which everyone agreed. You can create a cloud flow that sends a reminder email to each person who hasn't paid the full amount if the current date is less than one day before the due date.

Use the and expression with the less expression since there are two conditions being validated.

Condition to validate Expression to use Example
Has the full amount due been paid? greater @greater(item()?['Due'], item()?['Paid'])
Is the due date less than one day away? less @less(item()?['DueDate'], addDays(utcNow(),1))

Combine the 'greater' and 'less' expressions in an 'and' expression

Use the greater expression to identify the employees who have paid less than the full amount due and use the less expression to determine if the payment due date is less than one day away from the current date. You can then use the Send an email action to send reminder emails to those employees who haven't paid in full and the due date is less than one day away.

Here's a view of the spreadsheet table.

Screenshot of the spreadsheet table.

Here's the implementation of the and expression that identifies all employees who have paid less than the amount due from them and the due date is less than one day away from the current date.

@and(greater(item()?['Due'], item()?['Paid']), less(item()?['dueDate'], addDays(utcNow(),1)))

Use functions in expressions

Some expressions get their values from runtime actions that might not yet exist when a cloud flow starts to run. To reference or work with these values in expressions, you can use functions that the Workflow Definition Language provides. More information. To learn more, go to Reference guide to workflow expression functions in Azure Logic Apps and Power Automate.

Training: Introduction to expressions in Power Automate (module)