Calculate Age using Power Automate

Today, let’s learn how to calculate a person’s age using Power Automate.

There are multiple ways to calculate a person’s age. The DOB field which I have is of string type. So, I thought of using Power Automate to achieve this.

Search for Common Data Service and the trigger should be When a record is created, updated, or deleted as shown in the below image. Next, enter the required details like the environment and the entity name.

Figure 1: Selecting trigger for this flow

Then we will add a condition to our flow, where we will check whether the Date of Birth field is null or not.

Figure 2: Check Date of Birth field is null or not

If the Data of Birth field is not null then we will calculate the age. For that when the condition is met the flow would go under IF yes condition, where we will have to provide the entity name and field under which the calculated age needs to be populated.

Figure 3: Mapping of entity under which the calculated age value to be populated
div(div(sub(ticks(utcNow('yyyy-MM-dd')),ticks(triggerBody()['new_dateofbirth'])),864000000000),365.25)

We will use the above expression for calculating the age. 
Place the cursor inside the Calculate Age field and paste the above expression under the expression section and click on the Update button.

Figure 4: Using expression for calculating value.

Now, we need to test our flow. Hit the Test button on the right top of your screen.

Figure 5: Test Flow

After a successful run of the flow. We can see age would have been populated under the Calculate Age field under the Contact entity.

Hope this helps anyone !!!

Design a site like this with WordPress.com
Get started