Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 38 ยท Actions and Expressions

Power Automate Expressions: Your First Functions

Learn the Power Automate expression language: where to type expressions, functions, the at-sign syntax, logic and comparison functions, if, coalesce and safe access with question marks.

Dynamic content covers simple cases. Whenever you need to calculate, compare, format or transform a value, you use an expression. Expressions are written in the Workflow Definition Language, the same language that Azure Logic Apps use. It has no variables of its own, no loops and no statements: it is a set of functions that you combine.

Where to write expressions

In any input field, open the panel and choose the Expression tab (shown as fx). Type the function, then select Update or Add. The result appears as a purple fx token in the field.

Alternatively, type directly in the field with an @ sign for the whole value, or @{...} to embed an expression inside text:

TEXT
@concat('Hello ', triggerBody()?['name'])
Order @{triggerBody()?['orderId']} is ready

Inside the Expression tab you do not type the @.

Syntax basics

  • Functions are lowercase or camelCase and take arguments in parentheses: toUpper('abc').
  • Strings use single quotes: 'text'. To write a single quote inside, double it: 'it''s'.
  • Numbers, true, false and null need no quotes.
  • Arrays use brackets: createArray(1,2,3). Objects come from json('{"a":1}') or object literals in input JSON.
  • A dot or an index reads a property: body('Get_item')['Title']. The safe form ?['Title'] returns null if body(...) is missing instead of failing.

Function names are not case sensitive, but most people write them in camelCase as in the docs. Property names inside JSON are case sensitive.

Logic and comparison

Function Example Result
equals(a, b) equals(1, 1) true
greater(a, b) / greaterOrEquals greater(5, 3) true
less(a, b) / lessOrEquals less(2, 1) false
and(x, y) / or(x, y) and(true, false) false
not(x) not(false) true
if(test, a, b) if(equals(1,2),'yes','no') no
empty(x) empty('') true
contains(collection, value) contains('invoice','voi') true
coalesce(a, b, c) coalesce(null, '', 'x') '', see note

coalesce returns the first value that is not null; an empty string counts as not null. To skip empty strings use if(empty(x), 'default', x) instead.

Math

add, sub, mul, div, mod, min, max, rand, range. Note that div(7, 2) is integer division when both are integers (result 3), so use div(7.0, 2) or float() for 3.5. Rounding functions are limited, so people often multiply, convert with int() and divide again.

A function reference table to keep handy

Group Functions
Strings concat, substring, replace, split, toLower, toUpper, trim, indexOf, startsWith, endsWith, length
Collections first, last, length, union, intersection, take, skip, join, contains, empty
Conversion string, int, float, bool, json, xml, base64, uriComponent
Dates utcNow, addDays, formatDateTime, convertTimeZone, ticks
Workflow triggerBody, triggerOutputs, outputs, body, actions, variables, item, items

Text, dates and time zones and Arrays, objects and JSON go deeper into these groups.

Practising with a stand-in

You cannot run real expressions here, so the stand-in below is a tiny Python imitation of a handful of functions. It lets you check your understanding of how nested expressions evaluate from the inside out. It is not the real engine and does not cover edge cases.

Python Stand-in: nested functions evaluate from the inside out

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

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The safe access operator

? before an index means "if the part on the left is null, give null". Without it, reading a field of a missing object fails the run with an InvalidTemplate error.

Python Stand-in: ? returns null instead of failing

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

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Combine the safe operator with coalesce or if(empty(...)) to supply defaults.

Debugging expressions

  1. Put the expression in a Compose action, run the flow, and inspect the output.
  2. Break nested expressions into several Composes, one per layer.
  3. Read the InvalidTemplate message: it names the action and the problem.
  4. Check data types. length works on strings and arrays; add needs numbers.

Common mistakes

  • Using double quotes for strings. Use single quotes.
  • Forgetting string() when joining a number with concat, which usually works but not for every type.
  • Comparing a string '5' with a number 5. They are not equal.
  • Writing @ inside the Expression tab.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which quotation marks do expression strings use?

    String literals in the workflow expression language are written in single quotes.
  2. 2. What does coalesce(null, '', 'x') return?

    coalesce returns the first non-null value and an empty string is not null.
  3. 3. What does the ? in triggerBody()?['name'] do?

    The safe-navigation operator avoids an InvalidTemplate failure on missing data.
  4. 4. What is a good way to debug a complex expression?

    Compose actions expose intermediate results in run history.

Summary

  • Expressions are functions combined in the workflow language, typed on the Expression tab or after @.
  • Strings use single quotes; use ?[...] for safe property access.
  • Core functions: equals, greater, and, or, not, if, empty, contains, coalesce.
  • Debug using Compose and run history.

Next: Variables and Compose