Many think that the not function is useless. Usually, the “not” function is used in comparisons, so if you’re comparing if something is not something else, why not compare if something is different? It makes sense when you think about it a bit further the not function can make things a lot easier to understand.
Let’s explore how to use the “not” function.
It follows a simple pattern. It receives true or false and negates it. For example:
not(true) will return false
It’s a dumb example, but it’s essential to understand that the parameter needs a boolean value. If you try with something else, for example, a 1, you’ll get the following error:
Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language function 'not' expects its parameter to be a boolean. The provided value is of type 'Integer'. Please see https://aka.ms/logicexpressions#not for usage details.'.
The 1 and 0 are usually alternative representations of true and false, respectively, but in this case, it’s considered as integers. Thes same happens with the string “true”. For example:
You’ll get the same error as above.
What about arrays with boolean values? To test it, let’s use the createArray function.
We’ll get the following error:
Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language function 'not' expects its parameter to be a boolean. The provided value is of type 'Array'. Please see https://aka.ms/logicexpressions#not for usage details.'.
Always the same issue. We need to provide boolean values or functions that return a boolean value.
So let’s look at some examples where it makes sense to have the not function.
The first is to validate data. Let’s imagine that we want to check if a task is not completed. We have a percentage that can be anything between 0 and 100%. So we would like to check if the percentage is not 100%. The alternative would be too complex to check if it’s equal to 1 and 2 and 3 and so on. It is cumbersome, to say the least, even if you don’t think about the decimal numbers possible. It’s a lot easier to check if it’s not 100%. Any other value is ok, like:
Another example can be to check if something is incorrect. Notice the phrasing if something is incorrect. The mindset is if something is wrong, we’ll do something (the positive path), and if it’s correct, we won’t do anything, for example (the negative direction).
not(equals(item()?['Author_Name'], 'Manuel Gomes'))
Imagine that I’m using Power Automate to upload the article to my server, and I want to ensure that the author is correct by using the equals function.
Since I’m the only author for this site (for now 😉), I would like to check if the name is the same as the one already defined. If not, I need to fix it. I can use the above expression to check the name and correct it before uploading.
Depending on the size of your string, your expression may return an error, even if it’s correct. Please note that the expressions have a max size of 8,192 characters. If you have an expression that is even bigger than 1000, I would strongly advise breaking it into smaller, manageable formulas.
Here are some things to keep in mind.
Use “debug” compose actions.
Since the comparison will return true or false, sometimes it’s tricky to understand how the calculation is done, depending on how complex the expression is. So I recommend using Compose actions to have the values that go “in” the function. This way, if the value doesn’t make sense, you can understand, based on the parameters, why it was calculated that way.
There’s no real reason to do it, but if you find yourself in a situation where you have nested not functions in a formula, you should review it and make everything more straightforward. You end up in the same place if you do it since a double negation will cancel it out. If this happens, either remove all the not functions or check if one should not be there.
Back to the Power Automate Function Reference.