Create custom column based on condition

Hi,
I am able to do this in SQL but cant figure how to do this using the UI create column feature

Here is scenario

SELECT item_count, created_on,
CASE
WHEN item_count < 1 THEN 'Failure'
ELSE 'Success'
END AS ResultDescription
FROM account_session
GROUP BY created on;
item_count

Please can any help on how to write conditonal expressions with the create column feature

Hi @watchnerd
You can use case function for Custom Columns:
https://www.metabase.com/learn/building-analytics/notebook-editor/custom-expressions.html
case([item_count] < 1, "Failure", "Success")

1 Like

@flamber amazing! thanks for the quick response! Loving my experience so far

Hi @flamber :slightly_smiling_face:

Sorry to bring up the conversation when it's closed from last year, but I have a follow up question with the case function.

I'm trying to use it in a custom column to group different User IDs. What I was trying is:
=case( [user ID] contains (12424, 12555, 456567), "Group 1", "Group 2")
With this, these 3 user IDs would be grouped in Group 1 and the rest of user IDs would be grouped in Group 2. I also tried IN and = instead of contains but anything works.

Can you help me with this? Thanks!!

@sandragrabulosa you would have to do something like case([field] = "value1" OR [field] = "value2", "foo", "bar") nested with the "contains" function https://www.metabase.com/docs/latest/users-guide/expressions-list.html#contains

1 Like

Amazing!!! Thank you so much :hugs: