Forum Discussion

msksenthil's avatar
msksenthil
Icon for Helper III rankHelper III
4 years ago

Swapping tables in SWITCH DAX

I am trying to pass the tables based on another value. But it was showing an error when giving on it.

 

 

Any help, please?

5 Replies

  • Hi msksenthil 

    What exactly are you trying to do?  I don't understand how/why you are testing values and what to return.

    It doesn't look like your SWITCH statements are correct.

    The syntax is 

     

    SWITCH
    ( 
    
    VALUE_TO_TEST,
    
    CONDITION_1, VALUE_TO_RETURN,
    
    CONDITION_2, VALUE_TO_RETURN,
    
    ....
    
    DEFAULT_VALUE_TO_RETURN
    )
    

     

     

    So you might typically use it like this

     

    SWITCH
    (
    TRUE,
    
    _var < 5 , "Less than 5",
    
    _var < 10 , "Less than 10",
    
    .....
    
    "Greater than 100"
    )

     

     

    Regards

    Phil

  • PhilipTreacy 

     

    I trying to swap the TABLES (multiple values like column) instead of value (single value) bases on the TRUE() condition

  • Hi msksenthil 

    But the first parameter in your SWITCH isn't TRUE so how's it doing any comparison?  How are you intending to compare tables?  What is in these tables?

    Can you share your file please.

    Regards

    Phil

    • msksenthil's avatar
      msksenthil
      Icon for Helper III rankHelper III

      PhilipTreacy Sorry, I can't share the file beacuse of the sensitivity. 

      Variable _a3 might be any one of values {1,3,4}

      And, I have 3 calculated tables _a4, _a6 and _a7

      I want to return

      _a4 table if _a3=1, 

      _a6 table if _a3 = 3

      else

      _a7 table

       

      Hope it clears my requirement

  • Hi msksenthil 

    OK, well, SWITCH can only return scalar values, not tables.  Perhaps you can rewrite your code so that the measure returns a value that indicates which table to use?

    Regards

    Phil