Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 38 ยท Controls and Formulas

Power Fx Basics

Learn the Power Fx formula language: data types, operators, text, number and date functions, If and Switch, blank values, and how to read and write formulas.

Power Fx is the low-code formula language of Power Apps. It was designed to feel like Excel formulas: declarative, strongly typed and focused on a few dozen functions you combine. If you know spreadsheet formulas, you already know the style.

This lesson covers types, operators and the functions you will use constantly. Real Power Fx runs inside Power Apps; the stand-ins here reproduce the results of the formulas shown so you can experiment.

Data types

Type Examples
Text (string) "Hello", "2024-05-01"
Number 42, 3.14
Boolean true, false
Date, Time, DateTime Today(), Now(), Date(2025, 3, 15)
Record {Name: "Ana", Age: 30}
Table [1, 2, 3] or Table({A: 1}, {A: 2})
Color Color.Red, RGBA(255, 0, 0, 1)
Choice, Image, Media and others from data sources

Power Fx converts between types when it can ("5" + 1 gives 6), but it is safer to convert explicitly with Value(), Text() and friends.

Operators

  • Arithmetic: + - * / ^ and % (percent, as in 50%).
  • Comparison: = <> < > <= >=. Note = is both assignment-free comparison and equality. There is no ==.
  • Logical: And/&&, Or/||, Not/!.
  • Text join: & concatenates ("Hello, " & name).
  • in tests membership: "a" in "banana" (substring) or 3 in [1, 2, 3].

Text functions

TEXT
Upper("abc")             // "ABC"
Lower("ABC")             // "abc"
Len("hello")             // 5
Left("Power Apps", 5)    // "Power"
Mid("Power Apps", 7, 4)  // "Apps"
Substitute("a-b-c", "-", "+")  // "a+b+c"
Trim("  hi  ")           // "hi"
Text(1234.5, "#,##0.00") // "1,234.50"

Format codes are locale aware; check how your region writes decimal separators.

Number and date functions

TEXT
Round(3.14159, 2)       // 3.14
RoundUp(2.1, 0)          // 3
Sum(1, 2, 3)             // 6
Max(3, 9, 4)             // 9
Today()                  // today's date
DateAdd(Today(), 7, TimeUnit.Days)
DateDiff(Date(2025,1,1), Date(2025,3,1), TimeUnit.Months)  // 2
Text(Today(), "dddd, mmmm d")   // e.g. "Monday, May 5"

The stand-in below mimics several of these functions in JavaScript, and prints the same results as the comments above.

JS Stand-in: text and number helpers

Press Run (or Ctrl + Enter) to see the console output here.

No output.

If and Switch

TEXT
If(Score >= 90, "A", Score >= 80, "B", "C")
Switch(Status, "New", Color.Blue, "Done", Color.Green, Color.Gray)

If accepts several condition and result pairs, with an optional last default. Switch compares one value against several constants.

Blank, IsBlank, Coalesce

An empty cell or unset value is blank. Use IsBlank(x) to test and Coalesce(a, b, c) to return the first non-blank. An empty text string "" is not the same as blank; IsEmpty applies to tables.

TEXT
Coalesce(txtNickname.Text, txtName.Text, "Guest")
JS Stand-in: If, Switch and Coalesce

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Records and tables in formulas

TEXT
{Name: "Ana", City: "Lisbon"}                 // a record
Table({Name: "Ana"}, {Name: "Bo"})            // a table
First(Tasks).Title                            // field access with dot
LookUp(Tasks, ID = 5, Title)                  // find one value
CountRows(Filter(Tasks, Done = false))        // number of open tasks

Formula style tips

  • Use named formulas or With for long repeated parts: With({taxRate: 0.2}, price * (1 + taxRate)).
  • Line breaks and indentation are allowed; press Shift+Enter in the formula bar.
  • Use comments: // line and /* block */.
  • The formula bar highlights errors; read the message and the squiggle location.
  • Self, Parent and ThisItem refer to the current control, container and gallery row.

Common mistakes

  • Using == instead of =.
  • Forgetting that text positions start at 1, not 0.
  • Comparing text and numbers without Value().
  • Expecting If to have no else; with no default it returns blank.
  • Mixing locale separators: some regions use ; between arguments and , for decimals.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which operator joins two text values?

    The ampersand concatenates text in Power Fx.
  2. 2. What does Mid("Power Apps", 7, 4) return?

    Positions start at 1, so character 7 is A and four characters give Apps.
  3. 3. Which function returns the first non-blank value among its arguments?

    Coalesce is the standard way to supply a default.
  4. 4. How do you test two values for equality?

    Power Fx uses a single equals sign for comparison.

Summary

  • Power Fx is a strongly typed, Excel-like formula language.
  • Know text, number, date, logical and record/table basics.
  • If, Switch, Coalesce, IsBlank handle conditions and blanks.
  • Text positions are 1-based; = compares, & joins.

Next: Variables and collections