Forum Discussion

Peter_23's avatar
Peter_23
Advocate V
1 year ago
Solved

IN operator

Hi there, I have a dude with this expression: IN , e.g. how many values its accepting? 

It's similar to SQL: You can specify up to 1000 expressions in expression_list.

 

One example:

 

 

EVALUATE
VAR ID_values = CALCULATEBLE (VALUES ( USER[ID] ), USER[COUNTRY] = "US" )

RETURN SWITCH ( TRUE, FACT[ID_USER] IN ID_values, TRUE() )

 

 

 

I mean if this tabler USER it contains 1M of record and filterint to US is 200K , is this possible to the IN operator support all records.

 

 

Thanks in advance.

  • Hey Peter_23 

    I initially confused the concepts 😅. EXISTS is a logical operator in SQL, used to check the existence of rows in a subquery. However, there is no direct EXISTS function in DAX.

    In DAX, similar logic can be achieved by using functions like CALCULATE combined with COUNTROWS to check if specific conditions are met.


    Here’s a cleaner version of your query:

    EVALUATE
    VAR MatchCheck =
    CALCULATE(
    COUNTROWS(USER),
    USER[ID] = FACT[ID_USER],
    USER[COUNTRY] = "US"
    )

    RETURN
    SWITCH(
    TRUE(),
    MatchCheck > 0, TRUE(),
    FALSE()
    )

5 Replies

  • Hey Peter_23 ,

    The IN operator is a CONTAINSROW  function behind the scenes, and because of that, does not have a fixed limit.

    However, performance depends on the size of the data model, relationships and available memory. In large models, IN could lead to performance issues if not optimized.

    Maybe you can use a different approach :

    EVALUATE
    VAR MatchCheck =
    EXISTS(
    USER,
    USER[ID] = FACT[ID_USER] && USER[COUNTRY] = "US"
    )

    RETURN
    SWITCH(TRUE,
    MatchCheck, TRUE(),
    FALSE()
    )

     

    • EXISTS checks if a combination of USER[ID] and USER[COUNTRY] exists for FACT[ID_USER].
    • Simpler and optimized for large datasets.

     

     

    • Peter_23's avatar
      Peter_23
      Advocate V

      Oh, you're right! marcelsmaglhaes 

       

      Remarks
      
          Except syntax, the IN operator and CONTAINSROW function are functionally equivalent.

       

      and what do you mean with "EXISTS" ? I guess command.. 🤔

      • marcelsmaglhaes's avatar
        marcelsmaglhaes
        Super User

        Hey Peter_23 

        I initially confused the concepts 😅. EXISTS is a logical operator in SQL, used to check the existence of rows in a subquery. However, there is no direct EXISTS function in DAX.

        In DAX, similar logic can be achieved by using functions like CALCULATE combined with COUNTROWS to check if specific conditions are met.


        Here’s a cleaner version of your query:

        EVALUATE
        VAR MatchCheck =
        CALCULATE(
        COUNTROWS(USER),
        USER[ID] = FACT[ID_USER],
        USER[COUNTRY] = "US"
        )

        RETURN
        SWITCH(
        TRUE(),
        MatchCheck > 0, TRUE(),
        FALSE()
        )