Forum Discussion

JoachimSA's avatar
JoachimSA
Icon for Helper II rankHelper II
4 years ago
Solved

ERROR() triggered in SWITCH() Function for no reason

Hi everybody,   I am currently trying to add some meaningfull error messages to my code to help me figure out quickly what is wrong if i.e. new data "break" my logic. For this I mostly use Switch:...
  • v-xiaotang's avatar
    4 years ago

    Hi JoachimSA 

    You can use if() function instead of switch().

    Because, for Switch() function, all result expressions and the else expression must be of the same data type.

    for IF() function, it can return a variant data type if value_if_true and value_if_false are of different data types, but the function attempts to return a single data type if both value_if_true and value_if_false are of numeric data types. In the latter case, the IF function will implicitly convert data types to accommodate both values.

     

    The error() function will give the specific error prompt and stop the calculation when the conditions are met. 

    The reason is the expression should not return processed values when encountering specific errors, these values are incorrect, it should generate invalid reports instead of unreliable numbers that may be considered correct. Also, that will lead to unnecessary resources waste.

     

     

    Best Regards,

    Community Support Team _Tang

    If this post helps, please consider Accept it as the solution to help the other members find it more quickly.