Forum Discussion

braineems's avatar
braineems
Regular Visitor
3 years ago
Solved

Switch does not support comparing values of type true/false

I want to add a new measure Batting Order but when I add it to my table chart it says function 'SWITCH' does not support coparing values of type True/False with values of type Text. consider using th...
  • AmiraBedh's avatar
    3 years ago

    It looks like you're trying to define a new measure using the DAX formula language, specifically using the `SWITCH` function to map names to batting orders.

    The issue with the code you've posted is that you're using `TRUE` as the expression for the `SWITCH` function, but then you're trying to compare it to a text value (the names of the players). The `SWITCH` function expects the first argument to be an expression that it will compare against the subsequent values in the list, so it doesn't make sense to compare a boolean `TRUE` value with text.

    Since you're trying to match a player's name, you need to reference the appropriate field or variable that holds the player's name. If, for example, you have a column named `PlayerName`, you could modify your code like this:

    ```dax
    Batting Order = SWITCH(
    [Name],
    "Jos Buttler", 1,
    "Rilee Rossouw", 2,
    "Alex Hales", 2,
    "Virat Kohli", 3,
    "Suryakumar Yadav", 4,
    "Glenn Phillips", 5,
    "Marcus Stoinis", 6,
    "Glenn Maxwell", 6,
    "Hardik Pandya", 6,
    "Sikandar Raza", 7,
    "Rashid Khan", 8,
    "Shadab Khan", 8,
    "Sam Curran", 9,
    "Shaheen Shah Afridi", 10,
    "Anrich Nortje", 11,
    BLANK() -- default case if none of the above match
    )
    ```