How to create a custom column with filters to retrieve a value according to conditions

Hello, I would like to create a custom column but taken into account "natively" by Metabase, my sql query would be:

SELECT case when trim(substring(comment, 3,4)) = 'pcs' then substring(comment,1,2) else 1 end as NbPcs,*
FROM [dbDEFAUL*T].[dbo].[DFTLACR]
where week >= 202235
order by id desc

How make that in metabase ? i try with Custom expressions but the expression "when / then" doesn't exist

To summarize, in my "comment" column I have three types of data and I want to retrieve a number which is the quantity:

Possible data type:

"7 pcs -" -> must become an integer of "7"
"GRAIN TROTTEMENT STRIPE" -> must become an integer of "1"
and nothing -> must become an integer of "1"

thanks in advance ! :slight_smile:

1 Like

Thank you I had already tried once with the case but I had done it wrong, now it's all good, I had written my request incorrectly! :slight_smile: