Usage Of Coalesce Function In Power Automate

Introduction

In Power Automate, the most common scenario is to verify null values and default to a specific value. In Power Automate it can be achieved easily using Coalesce Function as an example and Plan Object is considered.

Step 1

Login to the required Power Apps environment using URL make.powerapps.com by providing the user name and password and click on Flows on the left-hand side as shown in the below figure.

Usage of Coalesce Function in Power Automate

Step 2

After step 1, click on New Flow and select instant cloud flow and provide the trigger as Manually trigger a flow and click on Create as shown in the below figure.

Usage of Coalesce Function in Power Automate

Step 3

After step 2, name the flow as Coalesce. To hold Plan Object we must click on + New Step and choose an operation and in the text box type Initialize Variable and select Initialize variable and provide the following step name as Initialize variable - Plan Object.

Name: Plan

Type: Object

Value

{
    "name": "VenkataSubbaraoPolisetty",
    "plantype": null,
    "connection": "landline"
}

As shown in the below figure.

Usage of Coalesce Function in Power Automate

Step 4

Click on + New Step and Choose an operation and in-text box type Compose and provide step name as Compose - Coalesce and select inputs and in the below popup select expression and type the following as expression

Coalesce (object_1: any) which returns the first non-null object in the arguments passed in

Example

If the plan type is null then false will be defaulted as value otherwise nonnull value specified in Plan Object, Step 3 will be returned.

Usage

coalesce(variables('Plan')?['plantype'],false)

After specifying the value then click on Ok/Update as shown in the below figure.

Usage of Coalesce Function in Power Automate

Step 5

After step 4, click on Save -> Test -> Manually and click on Test then Run flow. If no errors click on Done and observe the result. False will be returned as shown in the below figure.

Usage of Coalesce Function in Power Automate

Step 6

After Step 5, provide the input object as,

Name: Plan

Type: Object

Value:

{
    "name": "VenkataSubbaraoPolisetty",
    "plantype": true,
    "connection": "landline"
}

 Click on Save -> Test -> Manually and click on Test then Run flow. If no errors click on Done and observe the result that true will be returned as shown in the below figure.

Usage of Coalesce Function in Power Automate

Note

  1. Make sure to save and run the flow whenever you try expressions.
  2. MS documentation is found here

Conclusion

In this way, one can easily handle null values using Coalesce function in a few minutes and use it for required scenarios.


Similar Articles