Blog
Formula - Difference between round, square, and curly brackets
July 20. 2021
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:
{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.
Firstname:"Tim",
Surname:"Leung",
'Address 1':"10 High Street",
'Address 2':"London"
}
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'.
[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.
- Categories:
- formula
Related posts
- FormuIas - Is it possible to call a user-defined function recursively in Power Apps?
- Formulas - A beginners guide on how to create and call user-defined functions (UDFs)
- Formula - How to add a button that converts degrees Centigrade to Fahrenheit and vice versa
- Formula - How to convert a single delimited string to rows and columns
- Data - How to group data in a gallery and calculate sums
- Formula - How to calculate compound interest
- Utilities - The best way to peform OCR on images of Power Apps Formulas
- Example - How to use a drop down control to convert currencies
- Formula - How to parse JSON in Power Apps- 4 examples
- Data - How to get a row by ordinal number
- Formula - What to do when the If statement doesn't work?
- Formula - Boolean And / Or operators - What is the order of precedence?
- Controls - How to set the data source of a Combo Box to a comma separated string
- Numbers - 10 examples of how to round numbers
- Top 3 highlights of upcoming enhancements to the Power Apps language (Power FX)
- Email - Sending email attachments with the Office 365 Outlook connector
- Formula - What to try when numbers don't format correctly
- Controls - How to convert HTML to Text
- Formulas - how to return all days between two dates
- Formula - How to create comma separated (CSV) list of items
- Formula - How to use the IF and Switch functions - 3 common examples
- Location - Finding the closest location and and sorting records by distance, based on the current location of the user
- Formulas - How to cope with weekends and public holidays in date calculations