Null Checks in Power Automate-Empty() vs Equals()

Hello everyone! I am back with another tiny Power Mantra which we should follow while making Power Automate Flows.
Say, we have a scenario where we are updating a row in Dataverse with certain dynamic values but what if those Dynamic Values are not present during the Flow Run. Thus we should always have Null or Empty check while we are updating a value. But which one to use when and what is the difference? Let’s explore it here!

Scenario: I have 3 tables storing the city, state and country respectively. Then I have a table called as locations storing the combination of the above three tables. Here I have kept 2 records as follow:

Record 1
Here I have the all the 3 fields filled-up

Record 2
In this record, I have the Country data missing

Then finally I have a map table, where my requirement is if I select the city, the state and country should auto-populate.
Let’s see how can we do it.

This flow triggers as soon as a Map record is added. Then we are matching the city of this newly created record with the metadata entity “Locations”. We are listing down all such rows but are limiting the result to 1. These 2 steps will remain the same throughout.


Then we are updating the Maps record with the matching state and country.

Way 1: Here we will use Equals() function and I am writing the following expression:

For Countries -> if(equals(items(‘Apply_to_each’)?[‘_new_country_value’],null),null,concat(‘/new_countries(‘,items(‘Apply_to_each’)?[‘_new_country_value’],’)’))

For States -> if(equals(items(‘Apply_to_each’)?[‘_new_state_value’],null),null,concat(‘/new_states(‘,items(‘Apply_to_each’)?[‘_new_state_value’],’)’))

When we run this flow by selecting the above two cities, we see its a success in both the scenarios.

Thus we can use Equals() for dynamic elements from dataverse.

But we see that in case of complicated flows, where we have to save the data in a string variable, Equals() doesn’t work.
Wanna have a look ?

First look at the flow:

I am initializing 2 string variables at the onset.

Then I am testing with just country here, so I am doing a compose on the country value to show you the result and then using the following expression, I am filling up the country:

if(equals(variables(‘Country’),null),null,concat(‘/new_countries(‘,variables(‘Country’),’)’))

We see that the flow fails:


Even though we see the output of the variable as “null” but still it throws an error and equals() doesn’t work.
Way 2: But instead when we write:

if(empty(variables(‘Country’)),null,concat(‘/new_countries(‘, variables(‘Country’),’)’))

This works well, as also when we directly use empty with the fields it works, So what is the conundrum here ? Why is it working for one & not for the other !?

Well Well Well! Whenever the string variable is set to a null, Power Automate tries to convert it to an empty string and stores it as “” in the backend. That’s why the if(equals()) condition didn’t produce the expected output when we trying to compare it with null value. But when we used empty() it produces the expected result as the string is clearly empty.

Thus we should use the null compare for dynamic field values and empty comparison for string variable values .

This is also helpful while we are putting Condition actions with these expressions in the flow itself.

I hope “When should we use ‘null’ check and when should we use ’empty’ check? ” this is clear to you now.
For any queries, do ping me. Hope it cleared certain concepts!

Find the Functions() guide here: https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#logical-comparison-functions

& the Power Quote of the day is:

“It’s the possibility of having a dream come true that makes life interesting.”
—The Alchemist by Paulo Coelho

Author: powershalinee

Techno-Functional Consultant

5 thoughts on “Null Checks in Power Automate-Empty() vs Equals()”

Leave a reply to Nishant Rana Cancel reply