case(...)Returns different values based on the evaluation of boolean comparisons
Works with the following datatypes:
This function works with 2.1 and 3.0 endpoint(s). What does this mean? »
The case(...) function is a special boolean function that can be used to return different values based on the result of boolean comparisons, similar to if/then/else statements in other languages.
Instead of a fixed number of parameters, case(...) takes a sequence of boolean, value pairs. Each pair will be evaluated to see if the boolean condition is true, and if so, the specified value will be returned. If no boolean condition can be evaluated as true, the function will return null.
For example, you can use case(...) with the CMS Open Payments General Payment Data to get a single column for name based on whether the payment was for a physician or a teaching hospital:
The TryIt macro has been disabled until future notice while we upgrade this site to SODA3.
The case(...) function is also very helpful in aggregations. In this case, we’ll count the number of disputed and undisputed payments for each physician in the state of Washington:
The TryIt macro has been disabled until future notice while we upgrade this site to SODA3.
Note that in this case we wanted to make sure we returned 0 instead of null if we didn’t get a match, so the final pair passed into case(...) was true, 0.