3 Ways to Convert Yes or No to Boolean True or False in Power Automate

Do you need to convert Yes or No values to true and false values in Power Automate?

You may often encounter situations where you need to convert Yes or No values to their respective Boolean equivalents, true or false.

This conversion can be crucial for maintaining data consistency when dealing with multiple data sources.

You can utilize expressions or condition actions to perform the transformation. This allows you to map the incoming Yes or No value to its corresponding true or false value.

This article will guide you through the process of transforming Yes or No values into true or false Booleans.

Convert Yes No to Boolean with the If Function

You can easily convert Yes or No text values to boolean values true or false using the if function. This function can be used in expressions to compare a given value to the required text values and then return the corresponding boolean value.

The if function works in a simple way; you can use the syntax if(condition, true, false) where the condition checks for a Yes value.

if(equals(outputs('YN_Value'),'Yes'),true,false)

For example, you can use the above expression to convert a given text value to a boolean.

The equals function compares the value from a Compose action named YN Value to see if it’s equal to Yes. If they match, the result is true. Otherwise, it returns false.

📝 Note: Keep in mind that the comparison is case-sensitive. To make it case-insensitive, consider using the toLower function so that it does not matter if the input is yes, YES, or Yes.

if(equals(toLower(outputs('YN_Value')),'yes'),true,false)

The above expression demonstrates this approach. It converts your value to lowercase and then compares that to a lowercase yes value.

Both these approaches only check for a Yes value and assume any other value will be a No.

This might not be the case and you might also want to check for a No value. This will require a nested if expression.

if(
	equals(toLower(outputs('YN_Value')),'yes'),
	true,
	if(
		equals(toLower(outputs('YN_Value')),'no'),
		false,
		'Other'
	)
)

The above expression will check your value for a Yes, and return true if this is the case. Otherwise, it will check if the value is No and return false if this is the case. If the value is neither Yes or No, it will return the text Other.

Convert Yes No to Boolean with the Bool Function

You can convert Yes or No string values to their corresponding boolean values without the if function.

The equals function will actually return a true or false value. So this can be used to convert the Yes/No to true/false. Then you can use the bool function to ensure this is boolean value.

bool(equals(outputs('YN_Value'),'Yes'))

The above expression will return true when the value in your Compose action is Yes, and false otherwise.

bool(equals(toLower(outputs('YN_Value')),'yes'))

In some scenarios, you may want to be more flexible with the input strings and not limit them to exact case matches. To make this conversion case-insensitive, use the toLower function as above.

By converting both the input string and the comparison string (‘yes’ in this case) to lowercase using the toLower function, you can ensure that the comparison is case-insensitive.

Convert Yes No to Boolean with a Condition Action

You can also use the Condition action to avoid using expressions to convert Yes or No values to their corresponding boolean true or false values.

Here is a summary of the steps needed to convert Yes/No to boolean with a Condition action.

  1. Add an Initialize variable action to your flow. This will be used to set a value to either true or false depending on the Condition action.
  2. Give your variable a Name such as ynValue. This will be used to refer to the variable later in the flow.
  3. Set the variable as String with the Type dropdown menu.
  4. Add a Condition action to your flow.
  5. Add the value to the left side of the condition that you want to convert to a true/false. In this example, this value is from a Compose action.
  6. Select the is equal to comparison option from the dropdown menu.
  7. Enter a @{false} expression on the right side of the condition.

Now you will be able to set the variable to a true or false value within the Condtion If yes and If no branch.

  1. Add a Set variable action in the If yes branch of the Condition action.
  2. Select the Name of your variable. In this case, it’s the ynValue variable.
  3. Add a @{true} expression to the Value input of your Set variable action.
  4. Add a Set variable action in the If no branch of the Condition action.
  5. Select the Name of your variable as the ynValue variable.
  6. Add a @{false} expression to the Value input of your Set variable action.

With these steps, you can easily convert Yes or No text values to their corresponding boolean true or false values using a Condition action.

Conclusions

Converting Yes/No text values to Boolean (true/false) values can be achieved using several methods.

The Condition action is a user-friendly way to include conditional statements in your flow. It enables you to define a condition based on your Yes/No values. Then variables can be set based on the condition to obtain a true or false value.

Expressions involving the if, bool, and equals functions can also be used to convert yes/no values.

When working with expression, you can also include the toLower function to create a case-insensitive solution.

Have you used any of the methods to convert yes and no values to boolean? Do you have any other tips? Let me know in the comments!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!