Forum Discussion
ERROR() triggered in SWITCH() Function for no reason
- 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.
Dear harshnathani,
thanks for the answer!
This is a good solution when you use it in a measure, where you can actually see the "error" in a visualization.
I am using this primarily in calculated columns. That "error" would get lost somewhere in thousands of rows without me noticing. Also, it is not possible if Result1/2 are in the number format because the switch statement will produce inconsistent data types.
Why can I not use the error() function there ?