当前位置:网站首页>Bi-sql and & or & in

Bi-sql and & or & in

2022-06-24 04:47:00 Powerbi white tea

AND function & OR function  & IN function

AND function 、OR Functions and IN Functions can be understood as WHERE The complement of function , Of course, it can also be used with other filter functions .

  • WHERE Function is to execute a query according to a qualified condition , But only a single condition is supported ;
  • AND A function is a case where both constraints are true , Execute the query ;
  • OR A function is a function of two qualifications, one of which holds , Just execute the query ;
  • IN Function can be understood as OR Function upgrade , Provide multiple values , The value in this interval , Both execute queries .

The application of the three , stay DAX The same is true for functions , There are also AND、OR、IN function , But in DAX These three functions are usually collocated FILTER Function USES , And there are differences in grammar .

Basic grammar

AND grammar :

SELECT  Column name  FROM  The name of the table  WHERE  Column name  =  Conditions 1 AND  Column name  = Conditions 2

OR grammar :

SELECT  Column name  FROM  The name of the table  WHERE  Column name  =  Conditions 1 OR  Column name  = Conditions 2

IN grammar :

SELECT  Column name  FROM  The name of the table  WHERE  Column name  IN ( Conditions 1, Conditions 2,...)

Using examples

Case data :

In the local database , There is a name “TEST” The database of , There is a name “ Sales details ” Case data for .

Example 1:

Set the branch as “M shop ” And the trade name is “ door curtain ” Data imported to PowerBI.

SELECT
      *
      FROM
       Sales details 
      WHERE
       The branch where you are 
      =N'M shop '
      AND
       Name of commodity 
      =N' door curtain '

give the result as follows :

Example 2:

Set the branch as “M shop ” Or the branch is “A shop ” Data imported to PowerBI.

SELECT
      *
      FROM
       Sales details 
      WHERE
       The branch where you are 
      =N'M shop '
      OR
       The branch where you are 
      =N'A shop '

give the result as follows :

Example 3:

Set the branch as “M shop ”、“A shop ”、“C shop ”、“H shop ” Data imported to PowerBI.

SELECT
      *
      FROM
       Sales details 
      WHERE
       The branch where you are 
      IN 
      (N'M shop ',N'A shop ',N'C shop ',N'H shop ')

give the result as follows :

Of course ,AND、OR and IN The three can also be combined to expand the scope .

I won't repeat it here , Interested partners can try it by themselves .

This is white tea , One PowerBI Beginners .

原网站

版权声明
本文为[Powerbi white tea]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/09/20210904093735190q.html