Blog

Formula - Difference between round, square, and curly brackets

For app builders who are relatively new, the syntax for writing formula can be confusing - perticularly with regards to the use of brackets. This post summarises the bracket types that are available in Power Apps.

On several occasions, app builders have asked me to explain the difference between the bracket types in Power Apps. In this post, I summarise the bracket types that are available with example usage.

1 - Curley brackets - {}

We use curly brackets to define a record. An example record looks like this:

{
Firstname:"Tim",
Surname:"Leung",
'Address 1':"10 High Street",
'Address 2':"London"
}
Notice how the field names and values are separated by a colon. We escape field names with spaces using single quotes, and we define text values inside double-quotes.

There are numerous reasons why app builders define records, especially because working with data plays a key role in many Power Apps. A very common reason for constructing a record is so that we can add to a data source (eg SharePoint, Excel, SQL Server) by calling the Patch function.

As an example, here's a formula to add a record to a SharePoint list.

Patch(SharePointList,
Defaults(SharePointList),
{
Firstname:"Tim",
Surname:"Leung",
'Address 1':"10 High Street",
'Address 2':"London"
}
)

2 - Square brackets - []

We use square brackets to define a single column table with the column header 'value'.

Most typically, we use square brackets to define simple lists of values that we can display in controls. An example would be a month picker that contains the values 1-12.

[1,2,3,4,5,6,7,8,9,10,11,12]

Since this syntax defines a single-column table, we can use this data structure as an input with the wide range of table shaping functions that Power Apps provides. For example, we can use this syntax to return only those month numbers that are equal to or greater than the current month.

Filter([1,2,3,4,5,6,7,8,9,10,11,12],
Value >= Month(Now())
)

We can use the [] syntax to define a single-column table of almost all objects, including records, tables, media, and screens. For example, we could define a single-column table of screens like so.

[BrowseScreen1, EditScreen1, DisplayScreen1]
We could then set the Items property of a dropdown control to this table, and add a formula to navigate the user to the selected screen.

3 - Round brackets ()

There are 2 main uses for round brackets in Power Apps. First, Round brackets feature in calls that invoke functions. Here's an example call to a function.

IsToday( 
Date(2021, 6, 1)
)

The second reason for using round brackets is to parenthesise operations, particularly those that relate to mathematical operations. Here's an example of how we would use round brackets in the calculation of a percentage.

(86/65) * 100

Conclusion

There are 3 types of brackets that we can use with Power Apps - curly, square, and round. This post summarised the differences between these three types.
Related posts