<?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 Timeseries regression - trend line in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Timeseries-regression-trend-line/m-p/294040#M3117</link>
    <description>&lt;P&gt;&amp;nbsp;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=""&gt;I needed to display the trend of a time series using a mathematical regression. Since DQL doesn’t provide an out-of-the-box function for this today, I implemented it with the following DQL query.&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;timeseries y=avg(dt.host.cpu.usage)&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;// N = nombre de points non-null&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd n = arraySize(arrayRemoveNulls(y))&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;// Sommes pour la régression (on ignore les slots où y[] est null)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd sumY = arraySum(y),&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sumX = arraySum(iCollectArray(if(isNotNull(y[]), iIndex()))),&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sumXX = arraySum(iCollectArray(if(isNotNull(y[]), toDouble(iIndex()) * toDouble(iIndex())))),&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sumXY = arraySum(iCollectArray(if(isNotNull(y[]), toDouble(iIndex()) * toDouble(y[]))))&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;// Coefficients slope/intercept&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd denom = (n * sumXX - sumX * sumX)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd slope = if(denom != 0, (n * sumXY - sumX * sumY) / denom)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd intercept = if(n != 0, (sumY - slope * sumX) / n)&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;// Série trend (même longueur que y, nulls conservés aux mêmes positions)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd trend = iCollectArray(if(isNotNull(y[]), intercept + slope * toDouble(iIndex())))&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;// Output: 2 courbes (y + trend)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fields timeframe, interval, y, trend&lt;/EM&gt;&lt;/P&gt;
&lt;P class=""&gt;Hopefully this is useful to others—and maybe it could even become an out-of-the-box DQL function in the future.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="image.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31853i6C0F640E858DF01B/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 03 Feb 2026 07:42:47 GMT</pubDate>
    <dc:creator>J01am</dc:creator>
    <dc:date>2026-02-03T07:42:47Z</dc:date>
    <item>
      <title>Timeseries regression - trend line</title>
      <link>https://community.dynatrace.com/t5/DQL/Timeseries-regression-trend-line/m-p/294040#M3117</link>
      <description>&lt;P&gt;&amp;nbsp;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=""&gt;I needed to display the trend of a time series using a mathematical regression. Since DQL doesn’t provide an out-of-the-box function for this today, I implemented it with the following DQL query.&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;timeseries y=avg(dt.host.cpu.usage)&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;// N = nombre de points non-null&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd n = arraySize(arrayRemoveNulls(y))&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;// Sommes pour la régression (on ignore les slots où y[] est null)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd sumY = arraySum(y),&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sumX = arraySum(iCollectArray(if(isNotNull(y[]), iIndex()))),&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sumXX = arraySum(iCollectArray(if(isNotNull(y[]), toDouble(iIndex()) * toDouble(iIndex())))),&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sumXY = arraySum(iCollectArray(if(isNotNull(y[]), toDouble(iIndex()) * toDouble(y[]))))&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;// Coefficients slope/intercept&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd denom = (n * sumXX - sumX * sumX)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd slope = if(denom != 0, (n * sumXY - sumX * sumY) / denom)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd intercept = if(n != 0, (sumY - slope * sumX) / n)&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;// Série trend (même longueur que y, nulls conservés aux mêmes positions)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fieldsAdd trend = iCollectArray(if(isNotNull(y[]), intercept + slope * toDouble(iIndex())))&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;// Output: 2 courbes (y + trend)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| fields timeframe, interval, y, trend&lt;/EM&gt;&lt;/P&gt;
&lt;P class=""&gt;Hopefully this is useful to others—and maybe it could even become an out-of-the-box DQL function in the future.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="image.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31853i6C0F640E858DF01B/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 03 Feb 2026 07:42:47 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Timeseries-regression-trend-line/m-p/294040#M3117</guid>
      <dc:creator>J01am</dc:creator>
      <dc:date>2026-02-03T07:42:47Z</dc:date>
    </item>
  </channel>
</rss>

