PowerApps Coalesce Function Explained By Examples

PowerApps Coalesce Function Explained By Examples

The PowerApps coalesce function is one of the less common functions. One reason for this might be, that you can do everything that the coalesce function does with if statements.

So why learn it all? The function helps you to write less code which is more elegant.

For instance, the following If statement can be replaced by a one-liner with the coalesce function.

If(
    !IsBlank(name),name,
    !IsBlank(nickname),nickname,
    "unknown"
)

By using the PowerApps coalesce function you can achieve the same result:

Coalesce(name,nickname,"unknown")

This already gives you an impression, what the coalesce in PowerApps is.

So let’s find out what exactly the functions is doing, take a look at some examples and common use cases for the coalesce function.

PowerApps Coalesce Function

The coalesce function in PowerApps will check every given parameter in order from left to right. The function will return the first parameter value that is non-empty and non-blank. PowerApps coalesce command will return blank when there is no non- empty and non-blank value.

Syntax

Coalesce( Value1 [, Value2, ... ] )

Parameters

  • Value1 (mandatory):
  • Value2,… (optional):

Return Value

  • Returns the first parameter that is non-blank and non-empty.
  • Returns blank, if none of the given parameters is not blank or empty.

PowerApps Coalesce Examples

Simple Coalesce Examples

Coalesce( "" )	
=> blank

Coalesce( "", "Joe" )	
=> Joe

Coalesce( "", Blank(), "Mike" )	
=> Mike

Coalesce( "Joe", "Mike" )	
=> Joe

Coalesce common use cases

Setting default values

The coalesce functions comes in handy, whenever you want to set a default value.

For example you might want to display ‘none’, in case you have no data for some information:

Coalesce( NickNameTextInput1.Text, "none" )	

Patch with coalesce

You can use coalesce in the context of patch function call to update a record if it already exists or to create one if not:

Patch(
    Employee,
    Coalesce(
        Lookup(
            Employee,
            ID=employeeId
        ),
        Defaults(Employee)
    ),
    {
       Name: NameTextInput.Text
    }
)

Leave a Comment

Your email address will not be published.