Power Automate utilizes the workflow definition language used by Azure Logic Apps. Expressions in Power Automate are simple functions that transform and return data. In other words, expressions help you write formulas to manipulate data according to your needs.
Why Use Complex Expressions?
There are several reasons why writing complex expressions in Power Automate is beneficial:
- Shaping complex data: Expressions allow you to manipulate and structure data in a way that suits your requirements.
- Faster run time: Using expressions for certain tasks and steps can improve the overall speed and efficiency of your workflows.
- Reducing API calls: By utilizing expressions, you can minimize the number of API calls required, optimizing resource usage.
Examples of Actions Suited for Expressions
Expressions are particularly useful for the following actions:
- Manipulating strings: You can easily manipulate and transform text data.
- Working with dates: Expressions facilitate date-related calculations and conversions.
- Converting data types: You can convert data from one type to another using expressions.
- Performing logical functions: Expressions enable you to perform logical operations and comparisons.
- Performing mathematical calculations: Complex calculations can be executed using expressions.
- Implementing complex conditional statements: Expressions help you create advanced conditional logic.
Understanding Data Types in Power Automate
To enhance your Power Automate skills, it's important to understand the different data types within the platform.
Power Automate data types are categorized into two groups:
- Simple data types: These represent single values, such as texts and numbers. They can be used independently or as part of more complex types. Examples include strings, integers, floats, and booleans.
- Complex data types: These types represent more intricate data structures that can consist of simple types or other complex types. Examples include objects and arrays.
Simple Data Types
Simple data types are single values and include:
- String: A sequence of characters.
- Integer: A whole number value.
- Float: A numeric value with a decimal point.
- Boolean: A value that can be either true or false.
Complex Data Types
Complex data types represent more intricate data structures and include:
- Object: Contains pairs of properties and values. It can represent an item in a table, with properties analogous to column names and values representing the corresponding row's data. For example: {"ID": 1, "Title": "Row title"} represents an object with two properties: ID (numeric value 1) and Title (string value "Row title").
- Array: An ordered collection of items of the same data type. Arrays can consist of strings, integers, booleans, objects, or even other arrays.
Anatomy of a Function
To be able to write complex expressions, you need to have an in-depth understanding of functions. There are 3 parts to understanding how to use any functions:
Parameters
These are input data that a function may need to work. A function can have zero, one or multiple parameters. The kind of data a function can accept as a parameter is of course determined by the data type. Consider the image below
The addProperty function expects 3 parameters: an object, a string and a value of any type. (The parameter name is before the colon and the data type is after for each parameter).
Function of the function
To properly use a function, you need to understand what the function is capable of and how it can help you to achieve your goals. Functions are categorized in Power Automate by a general type or types of data that they manipulate. I will provide examples of the most common functions in some of the categories later in this series.
Return type
When a function is done functioning it may return data back to your flow. The data that is returned by a function is also restricted by its type. From the image above, the addProperty function returns an object. With this information, you can pass a function that returns a certain type as a parameter of another function that expects that type. This is called nesting.
Consider the expression below
equals(1,1)
- Parameters: 2 parameters of type integer with values 1. While integers are used in this example, equals can compare 2 values of any type; this may not be the case for other functions.
- Function: compares 2 values of the same type to see if they are equal or not.
- Return type: returns a value of type Boolean; true if equal, or false if otherwise.
As stated previously, we can pass the return value to a function with at least one parameter with a data type that matches the return type of this function. Nesting will be covered in the next part of this series.