Article

DAX Language - AND and OR Functions

DAX Language - AND and OR Functions


A.Baddane | Posted on April 10, 21

AND Function

 Description:

The AND function checks whether all arguments are TRUE, and returns TRUE if all arguments are TRUE.

 Return Value:

AND returns a single boolean value depending on the combination of values that you test.

 Syntax:

AND( <Logical1>,<Logical2> )
  • Description of the parameters:

 

PARAMETER

DESCRIPTION

Logical1

The logical values to test

Logical2

The logical values to test

 

 Example:

As an example, we would like to create a measure that returns "Good" if the sales amount is greater than 100.000.000 and the quantity is greater than 400.000 otherwise Blank. We can achieve this using the following formula:

AND_Measure = 
IF( 
    AND(SUM(Sales[SalesAmount])>100000000,SUM(Sales[SalesQuantity])>400000),
    "Good",
    BLANK()
   )

The AND function accepts only two arguments. In case there are three or more conditions to evaluate use the operator '&&'. By adding a third condition to the previous formula, it now becomes:

Measure = 
IF(
    SUM(Sales[SalesAmount])>100000000
        && SUM(Sales[SalesQuantity])>400000
        && SUM(Sales[UnitPrice])>20000,          
    "Good",
    BLANK()
  )

 

OR Function

 Description:

The OR function checks whether one of the arguments is TRUE to return TRUE. The function returns FALSE if both arguments are FALSE.

 Return Value:

OR returns a single boolean value depending on the combination of values that you test.

 Syntax:

OR( <Logical1>,<Logical2> )
  • Description of the parameters:

 

PARAMETER

DESCRIPTION

Logical1

The logical values to test

Logical2

The logical values to test

 

 Example:

We will use the previous example, but this time we want to display "Good" if the sales amount is greater than 100.000.000 or the quantity is greater than 400.000 otherwise Blank. We can achieve this using the following formula:

AND_Measure = 
IF( 
    OR(SUM(Sales[SalesAmount])>100000000,SUM(Sales[SalesQuantity])>400000),
    "Good",
    BLANK()
   )

The OR function accepts only two arguments. In case there are three or more conditions to evaluate use the operator '||'. By adding a third condition to the previous formula, it now becomes:

Measure = 
IF(
    SUM(Sales[SalesAmount])>100000000
        || SUM(Sales[SalesQuantity])>400000
        || SUM(Sales[UnitPrice])>20000,          
    "Good",
    BLANK()
  )

 

Related Video:

 


(0) Comments

There is no comment

Leave a Comment
Add to favorite
Categories
Recent Posts
Filter column based on a list in Power Query
A.Baddane | April 05, 23

Sometimes when you work within power query, you need to filt...Read More


Use HTML in Power BI - Part 2
A.Baddane | July 05, 22

In the first blog post about using HTML in Power BI Desktop,...Read More


Use HTML in Power BI
A.Baddane | Feb. 21, 22

In this blog post, I will show you how to use HTML to create...Read More


Covid-19 Report
A.Baddane | Nov. 23, 21

The COVID-19 pandemic, also known as the coronavirus pandemi...Read More