> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omni.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Binning and grouping custom fields

> Bin and group custom fields with Omni's handy custom calculation accelerators.

Omni offers some accelerators for common custom calculations. To bin or group strings or values, select "Group" from the field picker menu. String values can be grouped into grouplets, including a left over bucket for remaining values:

<img src="https://mintcdn.com/omni-e7402367/VJSO_TqxWchd4y9s/images/docs/querying-and-sql/assets/images/string_binning-af973a539a9136efacd00f0afda813d2.png?fit=max&auto=format&n=VJSO_TqxWchd4y9s&q=85&s=8615f49cc750f2dcb6b25ef8ac668af8" alt="" width="2144" height="1430" data-path="images/docs/querying-and-sql/assets/images/string_binning-af973a539a9136efacd00f0afda813d2.png" />

Numbers can be binned using a comma delimited list of values. Omni will auto-generate bins based upon the max value and a proportional split, but the boundaries can also be applied by hand:

<img src="https://mintcdn.com/omni-e7402367/VJSO_TqxWchd4y9s/images/docs/querying-and-sql/assets/images/number_binning-af311f8c38689ce6213c5e09a3e88588.png?fit=max&auto=format&n=VJSO_TqxWchd4y9s&q=85&s=8996cbe57fbcea81f689900d5c62c593" alt="" width="2148" height="1432" data-path="images/docs/querying-and-sql/assets/images/number_binning-af311f8c38689ce6213c5e09a3e88588.png" />

As with other custom fields, explicit names or views can be applied alongside descriptions.

## Binning and regrouping aggregates

A common workflow is looking at a distribution and then trying to understand patterns in the aggregation - percent of users by lifetime orders; distribution of brands by count of SKUs, distribution of sessions or activities by user.

For these analyses we can use saved views and binning to share distribution of aggregates. We got through the following multi-stage analysis to do this with UI, and we'll share an alternative in SQL.

### Setup

1. Build baseline query where we want to analyze distribution. Here we'll look at lifetime orders per user:

<img src="https://mintcdn.com/omni-e7402367/VJSO_TqxWchd4y9s/images/docs/querying-and-sql/assets/images/user_lifetime_orders-782443c49c5693ac3ba7aaef27071900.png?fit=max&auto=format&n=VJSO_TqxWchd4y9s&q=85&s=14574d9ce8053c84ecb47e204f4698b9" alt="" width="2172" height="1490" data-path="images/docs/querying-and-sql/assets/images/user_lifetime_orders-782443c49c5693ac3ba7aaef27071900.png" />

2. Save a [query view](/analyze-explore/saved-views). Note Omni will strip the limit from the query view in order to retain the full data set.
3. Navigate to All Views & Fields to find our new table
4. Bin our aggregate (per section above)
5. Query and visualize:

<img src="https://mintcdn.com/omni-e7402367/VJSO_TqxWchd4y9s/images/docs/querying-and-sql/assets/images/lifetime_order_distribution-5c759ec7f63f15c1f8528c3e36af8d5d.png?fit=max&auto=format&n=VJSO_TqxWchd4y9s&q=85&s=2c838eb07f90e2a25624567476d4de46" alt="" width="2162" height="1490" data-path="images/docs/querying-and-sql/assets/images/lifetime_order_distribution-5c759ec7f63f15c1f8528c3e36af8d5d.png" />

<img src="https://mintcdn.com/omni-e7402367/VJSO_TqxWchd4y9s/images/docs/querying-and-sql/assets/images/lifetime_order_distribution_binned-82b790b75e74e0121e28771401be6353.png?fit=max&auto=format&n=VJSO_TqxWchd4y9s&q=85&s=5b99e7e2691c6f90090fe55698b5a8aa" alt="" width="2166" height="1490" data-path="images/docs/querying-and-sql/assets/images/lifetime_order_distribution_binned-82b790b75e74e0121e28771401be6353.png" />

As alternative path involves simply wrapping our first query in SQL, and inserting our own case statements. This is quicker, but will be more rigid if we need to adjust the underlying query. It is also a very simple approach to single-level re-aggregation (ie. wrap a sub-query in parentheses and count the number of rows).

<img src="https://mintcdn.com/omni-e7402367/VJSO_TqxWchd4y9s/images/docs/querying-and-sql/assets/images/quick_requery-da23d37f2c4f8eba7edc46999e803dc5.png?fit=max&auto=format&n=VJSO_TqxWchd4y9s&q=85&s=1d8015d7f2bbb78b92be3571a7f7064a" alt="" width="2172" height="1484" data-path="images/docs/querying-and-sql/assets/images/quick_requery-da23d37f2c4f8eba7edc46999e803dc5.png" />

<img src="https://mintcdn.com/omni-e7402367/VJSO_TqxWchd4y9s/images/docs/querying-and-sql/assets/images/sql_binning-4eb8d60326f8109f29fc05c1fc34bfd5.png?fit=max&auto=format&n=VJSO_TqxWchd4y9s&q=85&s=59d0e2252b41e7f9914e07a33142eebb" alt="" width="1676" height="780" data-path="images/docs/querying-and-sql/assets/images/sql_binning-4eb8d60326f8109f29fc05c1fc34bfd5.png" />
