## Introduction

**Power BI** comes with the powerful formula language **Data Analysis Expression (DAX)** which allows the implementation of custom calculations. There are numerous operators and functions available in **DAX**. One essential **DAX** function is the `IF`

function which is used for conditional calculations. In this tutorial, we will explore the `IF`

function** **and show you how to use it.

## Data

The data for this tutorial comes from an Excel file. In the following tutorial, we explain how to import Data from an Excel file into **Power BI**:

We have loaded the data into **Power BI** without executing any transformations. The data looks as follows:

Now, let's explore how the **DAX** function `IF`

works and how to use it.

## Syntax

The `IF`

function is used to return different values based on a specific condition. It checks a given condition and returns a specific value if the condition is TRUE. If the condition is FALSE, an alternative value is returned. The syntax of the `IF`

function looks as follows:

`IF(<logical_test>, <result_if_true>, <result_if_false>)`

Let's look at the components in detail:

`<logical_test>` |
Any condition that can be TRUE or FALSE. |

`<result_if_true>` |
The value that is returned if the condition is TRUE. |

`<result_if_false>` |
The value that is returned if the condition is FALSE. |

It is also possible to nest `IF`

functions in other `IF`

functions. This allows several conditions to be checked in sequence.

## Example

Now, let's perform an example calculation with the `IF`

function. In our example, we want to make a categorization based on the credit points.

There will be the following four classes:

**Excellent**: If the credit points are equal to or greater than 90.**Good**: If the credit points are between 70 and 89.**Average**: If the credit points are between 50 and 69.**Poor**: If the credit points are below 50.

To implement this classification logic, we need three nested `IF`

functions.

First, we create a new **calculated column**.

We name the **calculated column** "PerformanceStatus" and enter the **DAX** code.

Let's consider the **DAX** formula in detail:

```
PerformanceStatus =
IF(student[creditpoints]>= 90,
"Excellent",
IF(student[creditpoints] >= 70,
"Good",
IF(student[creditpoints] >= 50,
"Average",
"Poor"
)
)
)
```

As soon as the calculation is applied, we see the result in the column "PerformanceStatus":

We can see that there is a result for each student.

## Conclusion

Congratulations! Now you are one step closer to become an **AI Expert**. You have learned how the `IF`

function works and how to use it. You have also seen how to nest `IF`

functions in other `IF`

functions. Try it yourself!

Also check out our Instagram page. We appreciate your like or comment. Feel free to share this post with your friends.