Error.Record

D

T

The M Code Behind the Power Query M function Error.Record

Understanding Error.Record

Before diving into the M code behind the Error.Record function, it’s important to understand what the function does. Essentially, Error.Record allows you to create custom error messages that can be displayed when errors occur during data transformation.

For example, let’s say you have a column of data that should only contain numeric values. If there are any non-numeric values in the column, you may want to display a custom error message to alert the user. This is where Error.Record comes in.

Using Error.Record, you could create a custom error message that looks something like this:


Error.Record(“Invalid Data Type”, “The column X should only contain numeric values”)


This error message would be displayed whenever there is a non-numeric value in the column. By providing a clear and concise error message, you can help users quickly identify and resolve data transformation issues.

The M Code Behind Error.Record

Now that we understand the purpose of Error.Record, let's take a look at the M code behind the function. The syntax for Error.Record is as follows:


Error.Record(errorCode as text, details as text)


The errorCode parameter is used to specify a unique error code for the error message. This can be any text string that you choose. The details parameter is used to provide more information about the error. This could include a description of the error, the name of the column or table where the error occurred, or any other relevant details.

When an error occurs during data transformation, Power Query will evaluate any Error.Record functions that are present in the query. If an Error.Record function matches the error that occurred, the custom error message will be displayed. If there are no matching Error.Record functions, the default error message will be displayed.

Using Error.Record in Your Workflows

Now that we understand how Error.Record works, let's explore some ways that it can be used to improve your data transformation workflows.

Providing Clear Error Messages

One of the primary benefits of Error.Record is the ability to provide clear, concise error messages. By creating custom error messages that provide detailed information about the error that occurred, you can help users quickly identify and troubleshoot issues. This can save time and reduce frustration, ultimately leading to a more efficient and productive workflow.

Validating Data

Error.Record can also be used to validate data during the transformation process. For example, you could use Error.Record to check for invalid data types, missing values, or other data quality issues. By catching these issues early in the process, you can prevent downstream errors and ensure that your data is accurate and reliable.

Automating Error Handling

Finally, Error.Record can be used to automate error handling in your workflows. By creating custom error messages for common issues, you can reduce the amount of time and effort required to troubleshoot errors. Additionally, you can use Error.Record in combination with other Power Query functions to automatically correct or remove problematic data, further streamlining your workflow.

In conclusion, the Error.Record M function is a powerful tool for data transformation in Power Query. By creating custom error messages, you can provide clear and concise feedback to users, validate data, and automate error handling. Whether you're a beginner or an experienced Power Query user, understanding the M code behind Error.Record can help you improve your data transformation workflows and achieve better results.

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)