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

BFFF893A-02A4-427A-A071-CF91AEEFA741.png

79E2828A-3D4E-41EF-9641-3906E4984E50.png

0 1 49
1 REPLY 1

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.