Need help with LookML REPLACE

hi, I’m attempting to create a custom field to replace all state names (such as ‘New York’) with their respective 2-letter abbreviations (such as ‘NY’).

I’m brand new to LookML, and when writing my expression, it successfully works when I only include 1 replace function, but how will I link 50 (one for each state) together? When I type my 2nd entry, I get an “Expression incomplete” error

Hi Chingle!

I think what you’re looking for is the case function. It can take as many arguments as you like. So it would look something like this:

case (
when( ${state} = “Arkansas”, “AR”),
when( ${state} = “North Carolina”, “NC”),

“not a state”
)

Alternatively, you may want to look into custom grouping, which allows you to make these case-style statements right in the explore without having to write code.

1 Like