Skip to main content

How to Format a Formula in Power Apps Studio

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A long formula on one line is hard to read and harder to change. The formula bar's Format text puts each function's arguments on their own lines, indented under the function, without changing what the formula does.

The example is the list of people on the Reports screen of the Overtime Timesheet app. Its gallery's Items groups a month's entries by person and works out each person's name, departments and hours, all in one formula.

Prerequisites​

  • An app open for editing in Power Apps Studio, with a long formula. Microsoft's formulas overview introduces the formula bar: the property list on the left, the formula on the right.

Step 1: Select the Formula​

Select the control, then the property in the list on the left of the formula bar. Here, the gallery galPeopleRS and its Items, written on one line, which the formula bar wrapped onto two:

The formula bar with the Items property of the gallery written on one line and wrapped onto two: If(IsBlank(locRowsRS), Blank(), Sort(AddColumns(GroupBy(locRowsRS, Email, Rows), Employee, First(Rows).Employee, Departments, Concat(Distinct(Rows, Department), Value, ", "), Hours, Sum(Rows, Hours)), Hours, SortOrder.Descending))

Step 2: Open the Formula Bar's Tray​

Select the arrow at the right end of the formula bar. The formula bar grows, and a tray at its bottom shows three buttons: Format text, Remove formatting and Find and replace. Microsoft lists the same three among the pop-out formula bar's editing tools.

Step 3: Select Format Text​

Select Format text. Each function's arguments went onto their own lines, indented under the function, with each closing bracket on its own line:

The formula bar after Format text, with the gallery's Items on 31 indented lines: If, IsBlank of locRowsRS, Blank, Sort, AddColumns, GroupBy with locRowsRS, Email and Rows, then Employee, First(Rows).Employee, Departments, Concat of Distinct of Rows and Department, Value and a comma, Hours and Sum of Rows and Hours, then Hours and SortOrder.Descending, with the Format text, Remove formatting and Find and replace buttons in the tray under it

Only the spaces and line breaks changed. With every space and line break taken out, the text was the same before and after.

Step 4: Make the Formula Bar Taller​

The open formula bar showed about seven lines, not enough for a 31-line formula. Drag its bottom edge down to show more, as Microsoft's Find and Replace article suggests for complex expressions. For more room still, the formula bar can open in a window of its own (Use the pop-out formula bar).

Remove Formatting​

Remove formatting goes the other way. It put the whole formula back on one line, and also took out the spaces after the commas:

The formula bar after Remove formatting, with the gallery's Items on one line without spaces after the commas, wrapped onto two lines: If(IsBlank(locRowsRS),Blank(),Sort(AddColumns(GroupBy(locRowsRS,Email,Rows),Employee,First(Rows).Employee,Departments,Concat(Distinct(Rows,Department),Value,", "),Hours,Sum(Rows,Hours)),Hours,SortOrder.Descending))

I selected Format text again afterwards, and the formula went back to its indented form.

The Result​

The formula is easier to read, and each part is on its own line to change. It does exactly what it did before: only its layout changed.

Common Mistakes​

MistakeWhat happensDo this instead
Reading a long formula in the closed formula barYou see a line or two of itOpen the tray and drag the formula bar taller
Formatting by typing line breaks by handIndents end up unevenFormat text
Expecting Remove formatting to keep the spacesIt takes out the spaces after commas tooFormat text to lay it out again

Troubleshooting​

SymptomLikely causeFix
No Format text buttonThe tray is closedSelect the arrow at the right end of the formula bar
Part of the formula is out of sightThe formula bar is too shortDrag its bottom edge down, or open it in its own window

FAQ​

Does Format text change what the formula does?​

No. Only spaces and line breaks change, and Power Apps doesn't need them to read a formula.

Does it work in the pop-out formula bar?​

Yes. Microsoft lists Format text and Remove formatting among the pop-out formula bar's editing tools.

Conclusion​

Select the property, open the formula bar's tray, and select Format text: each argument goes on its own line, indented under its function. Drag the formula bar taller to read it all, and use Remove formatting to put it back on one line.

Additional Resources​