<?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: How do you do a trend calculation with a plus sign? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412298#M167142</link>
    <description>&lt;P&gt;Hi ,&lt;/P&gt;

&lt;P&gt;You can use the below statement before table command in your code-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval  percPercentProcessorTime_AVG=printf("%+4d",percPercentProcessorTime_AVG)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 09 Oct 2018 14:44:32 GMT</pubDate>
    <dc:creator>Vijeta</dc:creator>
    <dc:date>2018-10-09T14:44:32Z</dc:date>
    <item>
      <title>How do you do a trend calculation with a plus sign?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412297#M167141</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;

&lt;P&gt;With the code below, i calculate a % trend between values. When the result of the trend is negative, a negative % is displayed. Perfect, but when the % is positive, I need to have, for example, +150% instead 150% .&lt;/P&gt;

&lt;P&gt;Could you help me please?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="windows-wmi" sourcetype="wmi:CPUload" (Name="mfetp/*" OR Name="mcshield/*") Name="mfetp*"   
| rex field=Name "^(?&amp;lt;Service&amp;gt;[^\/]+)[\/]"
| head 10
| stats avg(PercentProcessorTime) as CPU_PercentProcessorTime_AVG, avg(Timestamp_Sys100NS) as CPU_Timestamp_Sys100NS_AVG
| appendcols  
[ search index="windows-wmi" sourcetype="wmi:CPUload"    (Name="mfetp/*" OR Name="mcshield/*") Name="mfetp*"   
| rex field=Name "^(?&amp;lt;Service&amp;gt;[^\/]+)[\/]"
| head 10
| stats avg(PercentProcessorTime) as CPU_PercentProcessorTime_AVG2, avg(Timestamp_Sys100NS) as CPU_Timestamp_Sys100NS_AVG2]
| foreach CPU_*_AVG [
| eval perc&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;_AVG=case('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'=='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;2',0, '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'&amp;gt;'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;2', "-"
.round(('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'/'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;2')*100,2), true(), "+".round(('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;2'/'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')*100,2))]

| table percPercentProcessorTime_AVG, percTimestamp_Sys100NS_AVG 

| rename percPercentProcessorTime_AVG as ProcessorTime_Trend, percTimestamp_Sys100NS_AVG as Timestamp_Sys100NS_Trend
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:29:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412297#M167141</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2018-10-09T14:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do you do a trend calculation with a plus sign?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412298#M167142</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;

&lt;P&gt;You can use the below statement before table command in your code-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval  percPercentProcessorTime_AVG=printf("%+4d",percPercentProcessorTime_AVG)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:44:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412298#M167142</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2018-10-09T14:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do you do a trend calculation with a plus sign?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412299#M167143</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;You can use regular expression to check if there is a minus sign or not, and if not, add the plus sign to your percentage.&lt;BR /&gt;
Below a working example :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval temp = split("150%;-97%",";")
| mvexpand temp
| rex field=temp "^(?&amp;lt;sign&amp;gt;.)"
| eval temp = if(sign="-",temp,"+".temp)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first 3 lines are only there to generate example data.&lt;/P&gt;

&lt;P&gt;Let me know &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;KailA&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 15:21:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412299#M167143</guid>
      <dc:creator>KailA</dc:creator>
      <dc:date>2018-10-09T15:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do you do a trend calculation with a plus sign?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412300#M167144</link>
      <description>&lt;P&gt;hi @jip31&lt;/P&gt;

&lt;P&gt;Did the answer below solve your problem? If so, please resolve this post by approving it! &lt;BR /&gt;
If your problem is still not solved, keep us updated so that someone else can help ya. Thanks for posting!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 22:47:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412300#M167144</guid>
      <dc:creator>mstjohn_splunk</dc:creator>
      <dc:date>2018-10-09T22:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do you do a trend calculation with a plus sign?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412301#M167145</link>
      <description>&lt;P&gt;hi thanks&lt;BR /&gt;
what does exactly mean "%+4d" please?&lt;BR /&gt;
if i want to adapt my code i just have to do :&lt;/P&gt;

&lt;P&gt;| eval percPercentProcessorTime_AVG=printf("%+4d",percPercentProcessorTime_AVG)&lt;BR /&gt;
| eval percTimestamp_Sys100NS_AVG =printf("%+4d", percTimestamp_Sys100NS_AVG)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:32:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412301#M167145</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2020-09-29T21:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do you do a trend calculation with a plus sign?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412302#M167146</link>
      <description>&lt;P&gt;This is a format, when you give a plus in printf, it displays + for numbers without sign and - for numbers with -ve sign. 4 is the precision of digits. This should work for your code.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 14:39:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412302#M167146</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2018-10-10T14:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do you do a trend calculation with a plus sign?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412303#M167147</link>
      <description>&lt;P&gt;thanks a lot&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 06:13:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-do-a-trend-calculation-with-a-plus-sign/m-p/412303#M167147</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2018-10-11T06:13:47Z</dc:date>
    </item>
  </channel>
</rss>

