You are currently viewing How to use PowerApps coalesce function correctly?
PowerApps Coalesce function

How to use PowerApps coalesce function correctly?

  • Post author:
  • Post category:Power Apps
  • Reading time:7 mins read

In this blog post, we will learn what is PoweApps coalesce function and how to use coalesce function in PowerApps.

PowerApps coalesce function

Syntax

Coalesce( Value1 [, Value2, ... ] )
  • The PowerApps coalesce function replaces blank values or empty string with a different value while leaving non-blank values and non-empty string values unchanged,
  • The PowerApps coalesce function returns the first expression that does not evaluate to BLANK. If all expressions evaluate to BLANK, BLANK is returned.
  • Each value is evaluated in order until a value that is not blank and not an empty string is found. Values after this point are not evaluated.
  • It is shorter to use COALESCE than writing an IF statement with the ISBLANK function. “Very hand to make your formulas a little less busy.”

PowerApps coalesce function examples

Example1: check if the DisplayName not blank then return it and if the FullName is not blank return it , otherwise return undefined. These formula we can perform using If function and coalesce function as shown below.

Solution using If function.

If(
    !IsBlank(DisplayName),DisplayName,
    !IsBlank(FullName),FullName,
    "Undefined"
)

Solution using PowerApps coalesce function

It will be shorter than the if statement. This formula will return the first value that is not blank or not empty string , it operate in order from left to write . Then it will check if DisplayName is blank or not if it is not blank it will return its value otherwise it will go to the next value “FullName” to check if it is blank or not and so on till not blank and not an empty string is found, and if all expressions evaluate to BLANK, BLANK is returned.

Coalesce(DisplayName,FullName,"Undefined")

Example2: it will return the first value that not blank or empty

Coalesce("Heba","Hamza")
PowerApps coalesce function
PowerApps coalesce function examples

Example3: it will return the second value that not blank or empty as the first value is empty string

col2 | Power Platform Geeks

Example4: I will operate from the left and find empty string, then the second value is blank as the blank() function always return blank value, so it will go to the third value “Heba” that is not empty and not blank value.

Coalesce( "", Blank(), "Heba" )	
// it will return Heba

Example5: Using PowerApps Coalesce function with patch function

Patch function without Coalesce function you have to check first if the record not blank then update and if blank create new one


If(
    !IsBlank(Lookup(YourDatasource, ID=RecordID))
    Patch(
        YourDatasource,
        Lookup(YourDatasource, ID=RecordID),
        {ColumnName: "Column Value"}
    ),
    Patch(
        YourDatasource,
        Defaults(YourDatasource),
        {ColumnName: "Column Value"}
    )
)

Patch function using Coalesce function

the below formula is the same but using the Coalesce function . It also check if the record is found in your data source using the lookup function or not if the record found then update it otherwise create new one in your data source.


Patch(
    YourDatasource,
    Coalesce(
        Lookup(YourDatasource, ID=RecordID),
        Defaults(YourDatasource)
    ),
    {ColumnName: "Column Value"}
)

As you see using Coalesce function in your formula in PowerApps reduce the amount of code you return if you will check for blank values.

Conclusion

In this post we discuss how to use the Power Apps Coalesce function and knew that it return the first expression that does not evaluate to BLANK or empty string and if all the expression is blank then the return value from the Coalesce function will be blank.

See Also
Join us
Need Help
  • Have a related question? Please ask it at deBUG.to Community.

Heba Kamal

Microsoft MVP, MCT, Technical Speaker, Blogger, and Microsoft 365 and Power Platform Consultant.