Mod / Modulus operator as a custom expression
Nobody has claimed this yet.
- Dominant language
- Clojure
- Stars
- 49.3k
- Forks
- 6.8k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 653
Description
**Is your feature request related to a problem? Please describe.**
Yes, I wasn't able to do what I wanted. [See here](https://discourse.metabase.com/t/is-there-a-modulus-mod-operator-in-metabase/16747)
> 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".
**Describe the solution you'd like**
I'd like to see a modulo operator (Python uses '%')
Instead of
```CountIf([Split Test Group Session] = 2 OR [Split Test Group Session] = 4 OR [Split Test Group Session] = 6 OR [Split Test Group Session] = 8 OR [Split Test Group Session] = 10 OR [Split Test Group Session] = 12)```
I would write
```CountIf([Split Test Group Session] % 2 = 2)```
**Describe alternatives you've considered**
It is possible to use workaround with a Custom Column and then using that in the CountIf, but they are ugly.
`case([Field] / 2 = floor([Field] / 2), "Even", "Odd")`
**How important is this feature to you?**
Not super important. But I was very surprised that Metabase was not capable of this. It's a basic logical operator supported by many programming languages.
:arrow_down: Please click the :+1: reaction instead of leaving a `+1` or `update?` comment
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how Metabase custom expressions handle arithmetic, comparisons, and CountIf, using the examples in the issue as behavioral references. Done means a modulo operator is accepted in custom expressions and supports the demonstrated odd/even grouping use case, with coverage for representative integer values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- analytics
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100