“With” and “setFocus”: Handy formulas for Power Apps

Hand using a laptop in coffee shop

Hello there,

A little news on two handy formulas for Power apps recently released : “With” and “setFocus”

Here is some reference for the first one : “With” documentation
This formula allow you to simplify complex formulas by dividing them into sub formulas. The syntax is the following :

With(,)

For instance, you can use “with” to define two sub formulas and display the result of their addition:

With( { a: 1,
        b: 2 },
    a+b)

NB: When dealing with multiple sub-formulas in the record, we put then into brackets “{…}” and separate them with comma “,”.

Using the “With” keyword, you can simplify more complex formulas by doing some processing in your declaration. Here is an example from the documentation :

With( 
    Match( "PT2H1M39S", "PT(?:\d+)H)?(?:(?\d+)M)?(?:(?\d+)S)?" ),
    Time( Value( hours ), Value( minutes ), Value( seconds ) )
)

The result from the formula above would be : 2:01 AM

Don’t hesitate to check the documentation linked above, we are definitely going to see interesting use of it…


Another function I would like to introduce in this article is “setFocus”.

Thanks to this key-word, you will be able to manipulate the focus on a control of your application.
The syntax is straight forward :

setFocus()

This formula greatly improve the user experience. Here is an illustration from the official documentation :

I hope you found these information useful and will make interesting things with it 😉

See you soon in the blog section !

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.