Custom fields: why is not working

Hello,

If you put the code “(CAST(dateadd(‘day’, CAST(0 AS long), now()) AS date)-birth_date)/365.25”, to calculate an age in a native SQL Question it works, but if I put the same code in custom field in custom question, it doesn’t work.

Why?

We would prefer to use the custom question over native sql, but the custom field doesn’t seem to accept everything. Is this normal or is it a defect ?

Thanks

Hi @Tania
Because the Custom Expressions are not functions in your database, but Metabase functions.
https://www.metabase.com/learn/building-analytics/notebook-editor/custom-expressions.html

Hi @flamber

So we have to use SQL native question. Thanks a lot for the answer.

@Tania There’s a request for handling date/time in Custom Expressions, which would allow what you are trying to do with SQL:
https://github.com/metabase/metabase/issues/11330 - upvote by clicking :+1: on the first post