Custom Binning Ranges
Hi Tom (and Team). We would love the ability to bin by custom ranges. We currently can only set a static number, which can lead to some pretty non-standard groupings of data.
EG: For Age, we'd like to be able to create the following bins: 0-17, 18-25, 26-35, 36-45, etc... Since under 18 is a common age range to group together, the bins we have to used are 0-17, 18-34, 35-52, etc..., which isn't a terribly standard age range to group data by.
![](https://secure.gravatar.com/avatar/3a4cc1523441c5f1e8c03700edd765b9?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)
-
AdminTom (Product Manager, MongoDB) commented
Hi Brian -
That's a good idea. We will be looking at enhancing binning next year so I'll see if we can do something along those lines.
In the meantime, it is possible to achieve what you're looking for with a calculated field. For example you could create a field with a definition like this:
{
$switch: {
branches: [
{ case: { $lt: [ '$age, 18 ] }, then: "0-18" },
{ case: { $lt: [ '$age', 30 ] }, then: "18-30" },
],
default: "30+"
}
}One thing to consider is that the resulting labels will be strings, so you'll need to choose names that put them in the right order with an alphabetical sort.