# Do histograms support custom bin sizes (besides a single range)?

**URL:** <https://community.dynatrace.com/t/do-histograms-support-custom-bin-sizes-besides-a-single-range/54040>\
**Category:** DQL\
**Tags:** dql, dashboards\
**Created:** [November 10, 2025, 9:54pm UTC](https://community.dynatrace.com/t/do-histograms-support-custom-bin-sizes-besides-a-single-range/54040 "2025-11-10T21:54:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdouds](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mdouds](https://community.dynatrace.com/u/mdouds)\
**Post date:** [November 10, 2025, 9:54pm UTC](https://community.dynatrace.com/t/do-histograms-support-custom-bin-sizes-besides-a-single-range/54040/1 "2025-11-10T21:54:30Z")

</div>

For example, if I want a dashboard histogram chart for span durations, I can use the below dql to show bins of 100ms each:

```auto
fetch spans
| summarize count(), by:{range(duration, 100ms)}

```

Instead, can we create custom buckets, like 0-250ms, 250-500ms, 500ms-1s, 1s - 3s, etc.?

---

<div class="post-metadata">

**Author:** ![t\_pawlak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/t_pawlak/32/14991_2.png) [@t\_pawlak](https://community.dynatrace.com/u/t_pawlak)\
**Post date:** [November 11, 2025, 12:26pm UTC](https://community.dynatrace.com/t/do-histograms-support-custom-bin-sizes-besides-a-single-range/54040/2 "2025-11-11T12:26:39Z")

</div>

Yes — but not with range(). range(x, step) only makes equal-width bins. For custom buckets (0–250 ms, 250–500 ms, 500 ms–1 s, 1–3 s, …), build the buckets yourself via conditions and then group by that label.

Try this:

```markup
fetch spans
| fieldsAdd
  bucket =
    if(duration < 250ms, then: "0–250 ms", else:
      if(duration < 500ms, then: "250–500 ms", else:
        if(duration < 1s, then: "500 ms–1 s", else:
          if(duration < 3s, then: "1–3 s", else: "≥3 s")
        )
      )
    ),
  bucket_idx =
    if(duration < 250ms, then: 1, else:
      if(duration < 500ms, then: 2, else:
        if(duration < 1s, then: 3, else:
          if(duration < 3s, then: 4, else: 5)
        )
      )
    )
| summarize spans = count(), by: { bucket, bucket_idx }
| sort bucket_idx asc
| fieldsRemove bucket_idx

```

you should recive this:

 ![t_pawlak_0-1762863986836.png](https://global.discourse-cdn.com/dynatrace/original/3X/0/e/0ef32e71ffe0bea57b816e8a847c3f89d0b31717.png)

---

<div class="post-metadata">

**Author:** ![mdouds](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mdouds](https://community.dynatrace.com/u/mdouds)\
**Post date:** [November 11, 2025, 2:56pm UTC](https://community.dynatrace.com/t/do-histograms-support-custom-bin-sizes-besides-a-single-range/54040/3 "2025-11-11T14:56:57Z")

</div>

Awesome, thanks! I started exploring this same method, but instead of using a separate `bucket_idx` to handle the sorting, I only used millisecond-based buckets with a mix of substring and type conversion, like this:

```auto
fieldsAdd firstNum = toLong(substring(bucket,from:0,to:indexOf(bucket,"ms")))
| summarize by:{bucket, firstNum}, count()
| sort firstNum
| fieldsRemove firstNum

```

Your approach is great because I can use any unit in my bucket names.
