<?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 Re: help for calculating a trend in a table panel in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502983#M195250</link>
    <description>&lt;P&gt;last question : is it possible to have + between the Trend when the Trend is positive??&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2019 15:05:08 GMT</pubDate>
    <dc:creator>jip31</dc:creator>
    <dc:date>2019-12-10T15:05:08Z</dc:date>
    <item>
      <title>help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502976#M195243</link>
      <description>&lt;P&gt;hello&lt;/P&gt;

&lt;P&gt;from the code below, i would like to be able to add a new colum in my table panel which calculate the percentage trend between the previous count and the next count for each line&lt;BR /&gt;
Example&lt;/P&gt;

&lt;P&gt;Month    count Trend&lt;BR /&gt;
January  200  --&lt;BR /&gt;
February 300 +34%&lt;BR /&gt;
March 100   -66%&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="toto" sourcetype="tutu" assigned_group="titi" 
| dedup incident_number 
| eval Month=strftime(_time,"%Y-%m") 
| stats count by Month 
| sort -Month
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;thanks for your help&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 08:48:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502976#M195243</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-10T08:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502977#M195244</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index="toto" sourcetype="tutu" assigned_group="titi" &lt;BR /&gt;
 | dedup incident_number &lt;BR /&gt;
 | eval Month=strftime(_time,"%Y-%m") &lt;BR /&gt;
 | stats count by Month &lt;BR /&gt;
 | sort -Month&lt;BR /&gt;
 | delta count as Diff &lt;BR /&gt;
 | eval percentageTrend =(Diff/count)*100&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 09:12:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502977#M195244</guid>
      <dc:creator>jitendragupta</dc:creator>
      <dc:date>2019-12-10T09:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502978#M195245</link>
      <description>&lt;P&gt;Are your example numbers what you want?&lt;/P&gt;

&lt;P&gt;Between Jan and Feb&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;300 is 50% more than 200 (b &amp;gt; a)&lt;/LI&gt;
&lt;LI&gt;200 is 33.3% less than 300 (a &amp;lt; b)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;by between Feb and Mar&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;300 is 200% more than 100 (a &amp;gt; b)&lt;/LI&gt;
&lt;LI&gt;100 is 66% less than 200 (b &amp;lt; a)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;so in your example are you looking to show, &lt;/P&gt;

&lt;P&gt;a) when negative, what % the smaller value is of the larger value&lt;BR /&gt;
b) when positive, what % the difference between the values is of the larger value&lt;/P&gt;

&lt;P&gt;or something else.&lt;/P&gt;

&lt;P&gt;Note that the sort -Month will sort in reverse chronological order, so with the %Y-%m your order will be March,Feb,Jan. Naturally if you then use delta, that will give different results.&lt;/P&gt;

&lt;P&gt;So you could use&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Month=strftime(_time,"%Y-%m") 
| stats count by Month 
| sort Month
| eval diff=0
| delta count as diff
| eval percentage=round(diff/count*100,0) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note that if you change the sort order the delta values are different. In the ascending sort, then change from 300 to 100 shows -200%.&lt;/P&gt;

&lt;P&gt;So it sort of depends if Feb in your example is needed to show &lt;/P&gt;

&lt;P&gt;a) Feb is a 50% growth over Jan&lt;BR /&gt;
b) Jan was 33% lower than Feb&lt;/P&gt;

&lt;P&gt;but to give you your example, you would have to do&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| sort Month 
| eval diff=0 
| delta count as diff
| eval percentage=round(if(diff&amp;gt;0,diff/count*100,diff/(count-diff)*100),0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;NB: Ascending sort&lt;/P&gt;

&lt;P&gt;Run anywhere example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| rename COMMENT as "Setting up data to show example" 
| eval f="2019-01,200#2019-02,300#2019-03,100" 
| makemv delim="#" f 
| mvexpand f 
| rex field=f "(?&amp;lt;Month&amp;gt;[^,]*),(?&amp;lt;count&amp;gt;.*)" 
| fields - f, _time 
| sort Month 
| eval diff=0 
| delta count as diff
| eval percentage=round(if(diff&amp;gt;0,diff/count*100,diff/(count-diff)*100),0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Dec 2019 09:58:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502978#M195245</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2019-12-10T09:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502979#M195246</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults count=2 
| streamstats count 
| eval _time = if (count==2,relative_time(_time,"-1y@month"), _time) 
| makecontinuous span=1d 
| eval incident_number="incedent_number_".(random() % 25 + 1)
| bin span=1month _time
| stats dc(incident_number) as count by _time
| eval Month=strftime(_time,"%B, %y") 
| delta count as diff
| eval Trend=(diff / count * 100)."%"
| table Month count Trend
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is &lt;CODE&gt;Month&lt;/CODE&gt; in this format?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 12:35:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502979#M195246</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-10T12:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502980#M195247</link>
      <description>&lt;P&gt;thanks it works but  the calculation of the percentageTrend is strange &lt;BR /&gt;
to my mind its not Diff/ count but (count-1/count)*100?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 14:19:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502980#M195247</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-10T14:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502981#M195248</link>
      <description>&lt;P&gt;Thanks it seems to be good&lt;BR /&gt;
Month format is &lt;span class="lia-unicode-emoji" title=":neutral_face:"&gt;😐&lt;/span&gt; eval Month=strftime(_time,"%Y-%m") &lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 14:20:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502981#M195248</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-10T14:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502982#M195249</link>
      <description>&lt;P&gt;hi perfect demonstration but for the percentage calculation i have the same question asked to &lt;BR /&gt;
jitendragupta&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 14:27:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502982#M195249</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-10T14:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502983#M195250</link>
      <description>&lt;P&gt;last question : is it possible to have + between the Trend when the Trend is positive??&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 15:05:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502983#M195250</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-10T15:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502984#M195251</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults count=2 
| streamstats count 
| eval _time = if (count==2,relative_time(_time,"-2y@month"), _time) 
| makecontinuous span=1d 
| eval incident_number="incedent_number_".(random() % 25 + 1) 
| bin span=1month _time 
| stats dc(incident_number) as count by _time 
| eval Month=strftime(_time,"%Y-%m") 
| delta count as diff 
| eval Trend=(diff / count * 100) 
| autoregress Trend as Trend_diff 
| eval positive_diff=if(Trend &amp;gt;= 0 , Trend - Trend_diff,NULL) 
| eval Trend=Trend."%", Trend_diff=positive_diff."%" 
| table Month count Trend Trend_diff
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is this it?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 19:40:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502984#M195251</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-10T19:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502985#M195252</link>
      <description>&lt;P&gt;yes thanks&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 08:54:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502985#M195252</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-13T08:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502986#M195253</link>
      <description>&lt;P&gt;please accept the answer &lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 11:42:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502986#M195253</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-13T11:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: help for calculating a trend in a table panel</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502987#M195254</link>
      <description>&lt;P&gt;I guess you need to express what the percentage is that you wish to see&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 08:27:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-for-calculating-a-trend-in-a-table-panel/m-p/502987#M195254</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2019-12-18T08:27:12Z</dc:date>
    </item>
  </channel>
</rss>

