Action.Sequence is a Power Query M function that creates an action to execute a list of actions in sequence, returning the result of the final action.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Action.Sequence( actions as list ) as any
Description
Creates an action that executes the sequence of elements in actions in order.
Each element of actions is either an action or a function that returns an action. An element in the list is executed only after all of the elements preceding it in the list are executed. In the case of an element that is a function, “executed” means that the function is evaluated and the action it returns is executed.
If an element of the list is a function then it must be either a 0 or 1-argument function that returns an action. The result of the execution of the preceding element is provided as the input to the function if it is a 1-argument function. The initial result (i.e. the result available to the first function in the sequence) is null.
Any element in the list that depends on a side effect or result of executing a preceding element must be expressed using a function.
The result of Action.Sequence is the result of executing the last element in the list (or null if the sequence is empty).
NOTE: A function in the list is not guaranteed to observe the side effects from the execution of the preceding elements in the list if the function references variables declared outside of its body (due to capture of free variables when the function is constructed). To ensure that updated data is observed by the function after an earlier element in the list executes, use an expression or function that directly accesses the affected data sources.
Examples
Creates an action that, when executed, will execute the first action ( which returns "hello" ), combine its result with the string "world!" to create a second action, and then execute the second action to produce a result of "hello world!".
Action.Sequence( {
Action.Return( "Hello" ),
( result ) => Action.Return( result & " " & "world!" )
} )
Here’s an example from Ben Gribaudo that sequences two TableAction operations:
let
Data = Sql.Database("server", "database"){[Name="SomeTable"]}[Data],
FilteredTable = Table.SelectRows(Data, each [ID] < 5),
UpdateAction1 =
TableAction.UpdateRows(
Table.SelectRows(Data, each [ID] < 5),
{"Column1", each [Column2] }
),
UpdateAction2 =
TableAction.UpdateRows(
Table.SelectRows(Data, each [ID] > 8),
{"Column1", each "Revised" }
)
in
Action.Sequence({UpdateAction1, UpdateAction2})
Related articles
Learn more about Action.Sequence in the following articles:
- M Mysteries: The Mysterious Type Action—An M-Internal Means to Write Data Modifications to External Systems
In his article “M Mysteries: The Mysterious Type Action,” Ben Gribaudo explores Power Query’s hidden capability to perform data modifications—such as inserts, updates, and deletes—using the undocumented ‘action’ type. Although Power Query is primarily designed for data retrieval and transformation, Gribaudo reveals that it possesses internal functions that can interact with external data sources to modify data. These functions, however, are not intended for general use and require the Power Query SDK for implementation. » Read more
Related functions
Other functions related to Action.Sequence are:
- Action.DoNothing
- Action.Return
- Action.Try
- Action.View
- Action.ViewError
- Action.ViewFunction
- Action.WithErrorContext
2023-2026 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy