Do you need to add 1 to a variable in your flow?
Creating a counter variable in Power Automate is quite a common need. This can be used to track how many times a loop iterates.
To create a counter variable, you will need to 1 to the current value of the variable.
In this article, we will introduce how to achieve this simple, yet crucial, operation within Power Automate.
What Type of Variables Can You Add 1?
Variables are essential for storing data during a flow. They come in different data types such as integer, float, string, boolean, array, and object.
The data type will determine what type of value the variable can hold. Only the Integer and Float options will allow you to hold a numerical value.
The Integer data type will allow whole numbers such as 3, and the Float option will allow decimal numbers such as 3.5. These are the only variable data types that will allow you to add 1 to the value.
Adding 1 to a Variable with the Increment Variable Action
Here is how to set up your flow with a variable and then add 1 to it.
Start by initializing the variable with the Initialize variable action to create, name, and set an initial value for the variable.
- Add the Initialize variable action to your flow.
- Give the variable a name such as myVar in the Name field.
- Select either Integer or Float as the data Type.
- Set the initial Value of the variable to any number. This is an optional step and if you leave the Value field empty, the initial value will default to 0 when the variable is referenced in later steps.
If the variable is for use as a counter, it should be an Integer data type with an initial value of 0.
- Add the Increment variable action to your flow.
- Select the previously initialized variable in the Name dropdown.
- Set the Value to 1. This is the amount you want to add to the previous value of your variable. You can set this Value field to any value.
These two actions will allow you to create your variable and then add 1 to the initial value.
💡 Tip: If you place the Increment variable action inside an Apply to each loop action, the variable will increment by 1 each time the loop iterates.
If the variable is for use as a counter, this will be an Integer data type with an initial value of 0.
Adding 1 to a Variable with the Add Function
Using the Increment variable action is definitely the most straightforward method of adding 1 to your variable.
But you might want to add a number to your variable without overwriting the variable. For this scenario, you can use the add function anywhere in the flow.
Syntax of the Add Function
In Power Automate, you can use the add function within a Compose action or any other action field to easily add 1 to a variable.
This function allows you to add any two numbers.
The syntax for using the add function is as follows.
This will return the sum of
Use an Expression to Add 1 to Variable
Here’s how to use an expression to add 1 to your variable.
- Click into the field where you want to use the result from adding 1 to your variable. This will open the Expression and Dynamic content popup
- Click on the Expression tab in the popup.
- Add the above expression to the expression editor.
- Press the OK button.
Make sure you update the
myVar reference in the expression to the name of your variable. Then when the flow runs this will result in the current value of the variable plus one.
You can easily add 1 to a variable using the Increment Variable action. This action supports variables of float and integer types.
By utilizing the Increment variable action, you can create counters and keep track of loops or specific occurrences.
Another option is to use the add function for cases where you don’t want to overwrite the current variable value.
How do you add values to your variables? Let me know in the comments!