<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Do histograms support custom bin sizes (besides a single range)? in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Do-histograms-support-custom-bin-sizes-besides-a-single-range/m-p/289317#M2764</link>
    <description>&lt;P&gt;For example, if I want a dashboard histogram chart for span durations, I can use the below dql to show bins of 100ms each:&lt;/P&gt;
&lt;PRE&gt;fetch spans&lt;BR /&gt;| summarize count(), by:{range(duration, 100ms)}&lt;/PRE&gt;
&lt;P&gt;Instead, can we create custom buckets, like 0-250ms, 250-500ms, 500ms-1s, 1s - 3s, etc.?&lt;/P&gt;</description>
    <pubDate>Mon, 17 Nov 2025 10:35:25 GMT</pubDate>
    <dc:creator>mdouds</dc:creator>
    <dc:date>2025-11-17T10:35:25Z</dc:date>
    <item>
      <title>Do histograms support custom bin sizes (besides a single range)?</title>
      <link>https://community.dynatrace.com/t5/DQL/Do-histograms-support-custom-bin-sizes-besides-a-single-range/m-p/289317#M2764</link>
      <description>&lt;P&gt;For example, if I want a dashboard histogram chart for span durations, I can use the below dql to show bins of 100ms each:&lt;/P&gt;
&lt;PRE&gt;fetch spans&lt;BR /&gt;| summarize count(), by:{range(duration, 100ms)}&lt;/PRE&gt;
&lt;P&gt;Instead, can we create custom buckets, like 0-250ms, 250-500ms, 500ms-1s, 1s - 3s, etc.?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Nov 2025 10:35:25 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Do-histograms-support-custom-bin-sizes-besides-a-single-range/m-p/289317#M2764</guid>
      <dc:creator>mdouds</dc:creator>
      <dc:date>2025-11-17T10:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Do histograms support custom bin sizes (besides a single range)?</title>
      <link>https://community.dynatrace.com/t5/DQL/Do-histograms-support-custom-bin-sizes-besides-a-single-range/m-p/289341#M2765</link>
      <description>&lt;P&gt;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.&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch spans
| fieldsAdd
  bucket =
    if(duration &amp;lt; 250ms, then: "0–250 ms", else:
      if(duration &amp;lt; 500ms, then: "250–500 ms", else:
        if(duration &amp;lt; 1s,   then: "500 ms–1 s", else:
          if(duration &amp;lt; 3s, then: "1–3 s", else: "≥3 s")
        )
      )
    ),
  bucket_idx =
    if(duration &amp;lt; 250ms, then: 1, else:
      if(duration &amp;lt; 500ms, then: 2, else:
        if(duration &amp;lt; 1s,   then: 3, else:
          if(duration &amp;lt; 3s, then: 4, else: 5)
        )
      )
    )
| summarize spans = count(), by: { bucket, bucket_idx }
| sort bucket_idx asc
| fieldsRemove bucket_idx&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;you should recive this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="t_pawlak_0-1762863986836.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/30875iF46CA1E9BB28BAA2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="t_pawlak_0-1762863986836.png" alt="t_pawlak_0-1762863986836.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Nov 2025 12:26:39 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Do-histograms-support-custom-bin-sizes-besides-a-single-range/m-p/289341#M2765</guid>
      <dc:creator>t_pawlak</dc:creator>
      <dc:date>2025-11-11T12:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Do histograms support custom bin sizes (besides a single range)?</title>
      <link>https://community.dynatrace.com/t5/DQL/Do-histograms-support-custom-bin-sizes-besides-a-single-range/m-p/289363#M2766</link>
      <description>&lt;P&gt;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:&lt;/P&gt;&lt;PRE&gt;fieldsAdd firstNum = toLong(substring(bucket,from:0,to:indexOf(bucket,"ms")))&lt;BR /&gt;| summarize by:{bucket, firstNum}, count()&lt;BR /&gt;| sort firstNum&lt;BR /&gt;| fieldsRemove firstNum&lt;/PRE&gt;&lt;P&gt;Your approach is great because I can use any unit in my bucket names.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Nov 2025 14:56:57 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Do-histograms-support-custom-bin-sizes-besides-a-single-range/m-p/289363#M2766</guid>
      <dc:creator>mdouds</dc:creator>
      <dc:date>2025-11-11T14:56:57Z</dc:date>
    </item>
  </channel>
</rss>

