How to use Power BI DAX Logical Functions with examples?. Microsoft Power BI DAX provides various Logical Functions such as IF Statement, AND, OR, NOT, IN, TRUE, FALSE, IFERROR, SWITCH, etc.

To demonstrate these Power BI DAX Logical functions, we use the below-shown data. As you can see, there are 15 records in this table.

## Power BI DAX Logical Functions

The following series of examples shows the list of DAX Logical Functions.

### DAX IF Logical Function

The Power BI DAX If function checks whether the given expression is True or False. The syntax of the DAX If Function is

IF(Expression, True_Info, False_Info)

As you can see from the above syntax, this Power BI DAX IF function accepts three arguments: the first argument is the Boolean expression (which returns true or false). If the expression results TRUE, then the second argument return; otherwise, the third argument will return.

To demonstrate these DAX logical IF functions in Power BI, we have to use Calculated. To create a column, please click on the New Column option under the Home tab, or Modeling tab.

We renamed the default column name as IfExample. As you can see from the below screenshot, while I was typing, the IntelliSense is showing the suggestions.

For this DAX Logical Functions demo purpose, we use the Sales column.

By clicking the enter or any key, a new column created. And the final Code is

IfExample = IF(EmployeeSales[Sales] > 3000, "Good", "Bad")

The above DAX IF function checks whether the Sales amount of each column is greater than 3000 or not. If true, then column returns Good; otherwise, it returns Bad.

Let me add this column to the table that we created earlier. Please refer to Create Table Report article to understand the steps involved in creating a table

### DAX Nested IF Function

In Power BI, you can use the DAX Nested If concept. I mean, one If statement inside another. The below DAX Nested IF function checks whether the Sales amount of each column is less than 1000 or not. If true then the column returns Very Bad otherwise, it enters into Nested If

NestedIfEx = IF(EmployeeSales[Sales] < 1000, "Very Bad", IF(EmployeeSales[Sales] > 3000, "Good", "Average" ))

Let me add this Nested column to this table.

### DAX Logical AND Function

The Power BI DAX Logical AND function check multiple expressions. The syntax of the DAX AND Function is

AND(Condition 1, Condition 2)

As you can see from the above syntax, the DAX AND function accepts two arguments: If both the conditions are True, then it returns True. Otherwise, it returns False.

Let me create a column to check whether the Sales of each column is greater than Average, and Yearly Income is greater than 70000. If both these conditions are true, then the column returns a Good Job. Otherwise, it returns Bad Job into a column

AndSales = IF(AND(EmployeeSales[Sales] > AVERAGE(EmployeeSales[Sales]), EmployeeSales[YearlyIncome] >= 70000), "Good Job", "Bad Job")

### DAX OR Function

The Power BI DAX OR function is like either or statement in English, which is useful to check multiple expressions. The DAX OR Function syntax is

OR(Condition 1, Condition 2)

As you can see from the above DAX OR function syntax: If both the conditions are False, then it returns False; otherwise, it returns True.

Let me create a column to check whether the Sales is less than Average, or Yearly Income is greater than equal to 90000. If both these conditions are false, then the function returns Doing Good; otherwise, it returns Watchlist into a column

OrSales = IF(OR(EmployeeSales[Sales] < AVERAGE(EmployeeSales[Sales]), EmployeeSales[YearlyIncome] >= 90000), "Watchlist", "Doing Good")

Let me add both the Power BI And Function and Or Function columns to the below-shown table.

### DAX NOT Function

The Power BI DAX NOT function converts True to false and False to True. I mean, it returns the opposite result. The syntax of the DAX NOT Function is

NOT(Condition)

The below statement returns False if Sales is greater than 2000; otherwise, it returns True.

NotSale = NOT(IF(EmployeeSales[Sales] > 2000, "TRUE", "FALSE")

Let me add this Not Function column to this table

### DAX IN Function

The Power BI DAX IN function restricts the calculation to specified columns. For example, you can calculate the sum of sales for temporary Employees. The syntax of DAX IN Function is as shown below:

Column IN {field1, field2,...,fieldN}

The below statement calculate the Sum of Sales for the employees whose education is Education, Bachelors, or Masters Degree. Remember, this is a Measure

SalesIN = CALCULATE(SUM(EmployeeSales[YearlyIncome]) , 'EmployeeSales'[Education] IN {"Education", "Bachelors", "Masters Degree"})

Let me create a Card using this Measure. Please refer to Create a Card and Format Card articles to understand the steps involved in creating and formatting cards.

### DAX TRUE Function

The Power BI DAX logical TRUE function returns logical true. The below statement returns True if Sales is greater than Average Sale; otherwise, it returns False

TRUESale = IF(EmployeeSales[Sales] > AVERAGE(EmployeeSales[Sales]), TRUE(), FALSE() )

### Power BI DAX Logical FALSE Function

The DAX FALSE function returns logical false. The below code returns False if Sales are less than 2500. Otherwise, it returns True

FalseSale = IF(EmployeeSales[Sales] < 2500, FALSE(), TRUE() )

Let me add True Function, False Function result to the table report

### DAX IFERROR Function

The Power BI DAX IFERROR function is very useful to handle arithmetic overflow or any other errors. It simply performs the calculation and returns the result, if there is an error, then it returns the value inside the second argument.

The syntax of the DAX IFERROR Function is

IFERROR(Calculation, Value_If_Error_Occurs)

The below statement returns 100 if an error occurs. Indeed, all the records throw an error because we are dividing them 0

ErrorSale = IFERROR(EmployeeSales[Sales]/0, 100)

Let me add Iferror column result to the table report

### DAX SWITCH Function

The Power BI DAX SWITCH function helps you to return multiple options. For example, the DAX IF function returns either True or false. However, you can use this switch case for multiple results.

The syntax of the DAX Switch Function is as shown below:

SWITCH(Expression, Option 1, Result 1, Option 2, Result 2, ....., ElseResult)

If the Month of Hire date is 1, then the below statement returns January, 2 means February, 3 means March, 4 means April, 5 means May, and 12 means December otherwise, Unknown.

SwitchMonth = SWITCH(MONTH(EmployeeSales[HireDate]), 1, "January", 2, "February", 3, "March", 4, "April", 5, "May", 12, "December", "Unknown")

let me add this Power BI DAX Switch function result column to this table report

Comments are closed.