Value.ViewError

D

T

The M Code Behind the Power Query M function Value.ViewError

Understanding the Value.ViewError Function

The Value.ViewError function is used to display detailed error messages when a query encounters an error. This function is particularly useful when you are working with complex queries that contain multiple transformations. When an error occurs, the Value.ViewError function is called, and a detailed error message is displayed.

The syntax for the Value.ViewError function is as follows:


Value.ViewError(error as any, optional message as nullable text)


The error parameter is mandatory and represents the error that occurred. The message parameter is optional and represents a custom message that can be displayed along with the error message.

Analyzing the M Code Behind Value.ViewError

Behind the scenes, the Value.ViewError function uses a combination of M functions to display the error message. Let’s take a closer look at the M code behind the Value.ViewError function.

The Error Function

The Error function is a built-in M function that is used to generate an error. The syntax for the Error function is as follows:


Error(message as text, optional value as any) as any


The message parameter is mandatory and represents the error message. The value parameter is optional and represents a custom value that can be associated with the error.

The Error function is used in combination with the Try…Otherwise statement to detect and handle errors in Power Query.

The Try…Otherwise Statement

The Try…Otherwise statement is used to detect and handle errors in Power Query. The syntax for the Try…Otherwise statement is as follows:


try expression otherwise expression


The expression parameter represents the operation that is being performed. If an error occurs during the expression, the otherwise expression is executed.

The Try…Otherwise statement is used in combination with the Error function to detect and handle errors in Power Query.

The DetailMessage Function

The DetailMessage function is a built-in M function that is used to extract the error message from an error. The syntax for the DetailMessage function is as follows:


DetailMessage(error as any) as text


The error parameter is mandatory and represents the error from which to extract the message.

The DetailMessage function is used in combination with the Error function to extract the error message and display it using the Value.ViewError function.

The Value.Metadata Function

The Value.Metadata function is a built-in M function that is used to extract metadata from a value. The syntax for the Value.Metadata function is as follows:


Value.Metadata(value as any) as record


The value parameter is mandatory and represents the value from which to extract metadata.

The Value.Metadata function is used in combination with the DetailMessage function to extract the error message metadata and display it using the Value.ViewError function.

The Value.ViewError function is a powerful tool for displaying detailed error messages when a query encounters an error. Behind the scenes, the Value.ViewError function uses a combination of M functions to display the error message. By understanding the M code behind the Value.ViewError function, you can gain a deeper understanding of how Power Query works and how to troubleshoot issues when they arise.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)