ERROR

How to Use the Power BI DAX function ERROR

What is the ERROR function in DAX?

The ERROR function in DAX is used to handle errors or exceptions that may occur in your calculations. The function takes two arguments: the first argument is the expression that you want to evaluate, and the second argument is the value that you want to return if the expression returns an error.

Syntax of the ERROR function

The syntax for the ERROR function is as follows:


ERROR(❰expression❱, ❰value❱)


- `❰expression❱` is the DAX expression that you want to evaluate.

- `❰value❱` is the value that you want to return if the expression returns an error.

How to use the ERROR function in Power BI

To use the ERROR function in Power BI, follow these steps:

1. Open the Power BI Desktop application and create a new report.

2. Click on the "New Measure" button in the "Modeling" tab.

3. In the formula bar, type the following formula:


Sales Error = ERROR(SUM(Sales[Amount]), 0)


In this example, we are using the ERROR function to handle any errors that may occur when we try to sum the values in the "Amount" column of the "Sales" table. If an error occurs, the function will return a value of 0.

4. Press "Enter" to evaluate the formula.

Now, you can use the "Sales Error" measure in your visuals and charts just like any other measure.

Using the ERROR function with other DAX functions

The ERROR function can be used in combination with other DAX functions to create more complex calculations. For example, you may want to use the IF function to conditionally handle errors. Here's an example:


Profit Margin = IF(SUM(Sales[Amount]) ❱ 0, DIVIDE(SUM(Sales[Profit]), SUM(Sales[Amount])), ERROR(1, 0))


In this example, we are using the IF function to first check if the sum of the values in the "Amount" column of the "Sales" table is greater than 0. If it is, we then use the DIVIDE function to calculate the profit margin. If an error occurs, the ERROR function will return a value of 0.

The ERROR function in DAX is a powerful tool that can be used to handle errors and exceptions in your calculations. By using this function, you can ensure that your calculations are accurate and that your reports and visuals are reliable. Use the syntax and examples provided in this article to get started with the ERROR function in Power BI.

Power BI DAX 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)