Is there a modulus / mod operator in Metabase?

I have a field in my DB which stores an integer between 1-12. This determines the AB test group the user is in: odd means group A, even means group B.

There seems to be no simple way of calculating which group the user is in. Ideally I would create a custom column with the values "ODD" or "EVEN".

How do I do this in Metabase?

Hi @caspii
You can with Custom Expressions:
case([Field] / 2 = floor([Field] / 2), "Even", "Odd")

Great thanks! :sunflower:

Are there plans to add a mod operator?

@caspii What operator? Please provide context - perhaps a link.

Modulus is often written as % or mod or modulo or similar. See:

It's super helpful for identifying even/odd or every other row in a result set.

You are welcome to open a feature request:

What @smurray said. I think it's a basic computer operation that should be supported by Metabase.

I'll add a feature request.

PS Metabase is a fantastic tool. Thanks for making it.


1 Like

@caspii Remember to upvote issues by clicking :+1: on the first post of an issue.

The reason why it's not possible is because Custom Expressions are not a real programming language. There are a lot of functionality we want to add, but it has been quite difficult to just get to the state it's currently in. But we will add a lot more in the future.

1 Like