Variables are one of the most valuable actions in Power Automate , and today, we’ll look at how the “decrement variable” action works.
The “decrement variable” action will get an “Integer” or “Float” variable and decrement it by the value that you provide it. It’s pretty simple but super powerful since having an action that we can do this safely can save us from some issues.
So the concept is simple. You have a variable with a value, and after the “decrement variable,” the variable will contain a value that is the difference between it and the value provided.
Where to find it?
You can find it in the “Build-in” action.
You may need to extend it and search for “Variables”.
Select the “decrement variable” action.
Here’s what it looks like.
Now that we know how to find it let’s understand how to use it.
The first thing to understand is that the “decrement variable” action needs a variable to decrement. It may look obvious, but sometimes it would be helpful to define a variable and decrement it “on the spot,” but it’s not possible.
If you don’t have a variable, here’s what it would look like.
Not very useful, right?
Another thing to consider is that the “Decrement Variable” action will only work if the variable is an “Integer” or a “Float.” Even if you have a string variable that contains a number, it won’t work. We can easily see it here:
Let’s see it in action now that we know what we can use. First, let’s see how to decrement it to a numeric value:
Notice that we’re not even initializing the variable with a value. This is a nice touch from Microsoft, where if the variable doesn’t contain an initial value, then Power Automate considers it zero.
How about if we want to decrement an “Integer” variable with a floating point number? Like this:
Power Automate will do the “right thing” and block us from doing it since we cannot have a valid result.
How about the opposite? If we have a “Float” variable and want to add a numeric value?
No problem since the value makes sense in the end:
Finally, let’s try the floating point value on a “Float” variable.
No problem. The value is possible to decrement, so Power Automate does it without an issue.
Usually, in Power Automate, we typically use the actions’ outputs where we get the data. For example, if we have a “compose” action, we fetch the result of the expression on the “compose” action output. But in the case of the “decrement variable” action, we are not doing that. We are changing the content of the variable that exists elsewhere, meaning that if we want the decremented value, we need to access the variable.
It makes sense if you think about it, but I wanted to highlight this because it’s something that escapes a bit from the “norm” on how Power Automate works.
As far as I know, there’s no severe limitation to the “decrement variable” action, but if you’re aware of one, I would like to know about it. Please email me , and I’ll include it here.
Here are some things to keep in mind.
Name it correctly
The name is super important in this case since we can have a lot of variables per Flow. Always build the name so that other people can understand what you are using without the need to open the action and check the details.
Always add a comment
Adding a comment will also help avoid mistakes. Indicate the variable’s usage and why you’re decrementing the value. Also include the meaning of the value itself, for example, “decrements the value by 1 to count the number of items left to parse in the array”. It’s essential to enable faster debugging when something goes wrong.
Always deal with errors
Have your Flow fail graciously and notify someone that something failed. It’s horrible to have failing Flows in Power Automate since they may go unlooked-for a while or generate even worse errors. I have a template that you can use to help you make your Flow resistant to issues. You can check all details here.
Back to the Power Automate Action Reference.