Action.Try is a Power Query M function that creates an action to execute another action, catching any errors and returning an error record or the result.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Action.Try( action as any ) as any
Description
Creates an action that executes action
, catches any errors that occur while executing the action, and returns a record containing a HasError
field and either a Value
or Error
field depending on whether the action executed successfully.
Examples
Creates an action that will try the execution of a second action that throws an error. The result of the Try
action is the error record:
[HasError = true, Error = [Reason = "Expression.Error", Message = "Error!", Detail = ]
Action.Try( Action.Sequence( {() => Action.Return( error "Error!" )} ) )
Creates an action that will try the execution of a second action that returns a result. The result of the Try
action is a success record:
[HasError = false, Value = "Success!"]
Action.Try( Action.Sequence( {() => Action.Return( "Success!" )} ) )
Related articles
Learn more about Action.Try 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.Try are:
- Action.DoNothing
- Action.Return
- Action.Sequence
- Action.View
- Action.ViewError
- Action.ViewFunction
- Action.WithErrorContext
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy