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

# How to Create a Histogram

> Create histograms using the Histogram chart type or a bar chart with numeric dimensions and binning.

A histogram shows the **distribution** of a numeric variable — for example, how many orders fall into each price range, or how customers are distributed across age brackets.

***

## When to Use a Histogram

* You have a **numeric column** (e.g., price, age, quantity, score) and want to see how many rows fall into each range (bin).
* You want a **count** (or similar aggregate) per bin, not individual values.

***

## Option 1: Histogram Chart Type

If **Histogram** is available in the chart type list:

1. Create or edit a metric.
2. Select **Histogram** as the chart type.
3. Add a **numeric dimension** (the column you want to bin, e.g., `order_amount`).
4. Add a **measure** (e.g., Count).
5. The product may **automatically create bins** from the numeric dimension.

If bins are not as expected (e.g., too many or too few), see Option 2 for manual control.

***

## Option 2: Bar Chart with Numeric Dimension

For more control over binning, use a **Bar chart**:

1. Create a **binned column** in your dataset using SQL:
   ```sql theme={"dark"}
   SELECT
     FLOOR(order_amount / 50) * 50 AS price_bucket,
     COUNT(*) AS order_count
   FROM orders
   GROUP BY price_bucket
   ORDER BY price_bucket
   ```
   This creates buckets of 50 (e.g., 0-49, 50-99, 100-149).

2. Use the binned column (e.g., `price_bucket`) as the **X-axis dimension**.

3. Use the count as the **Y-axis measure**.

4. Select **Bar chart** as the visualization type.

***

## Why "Count + Bar" Might Not Look Like a Histogram

A histogram needs **one bar per bin** with a **count per bin**. Common issues:

* **No dimension added**: If you only add a count measure without a dimension, you get a single bar. Add a dimension that represents the bins.
* **Non-numeric dimension**: If your dimension is categorical (not numeric), the chart shows categories instead of ranges. Use a numeric column or create bins in SQL.
* **Group By has no options**: Ensure your metric has at least one **dimension** and one **measure**. Some aggregation choices (e.g., window functions like `PERCENTILE_CONT`) do not collapse rows into groups and may leave Group By empty.

***

## Summary

| Goal                     | What to do                                                                     |
| ------------------------ | ------------------------------------------------------------------------------ |
| Use Histogram chart type | Select Histogram, add numeric dimension + measure (e.g., Count).               |
| Use Bar chart            | Create bins in SQL (e.g., `FLOOR(col/10)*10`), use as X-axis, Count as Y-axis. |
| Bins not automatic?      | Create bins in SQL or a calculated column, then use as dimension.              |
| Group By empty?          | Ensure you have at least one dimension and one aggregate measure.              |
