<?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 to perform subtraction on results? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-subtraction-on-results/m-p/396506#M168792</link>
    <description>&lt;P&gt;So after you timechart command, you'll get column _time and one column for each host with name of the column being the host name (e.g. _time host1 host2 etc). How to do any operation on those fields, you'd need to use the exact field name (which is the host name), so you can either use the hardcoded name of the host like this (putting it in single quotes in the expression parts as it may have special chars)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=OS sourcetype=cpu | timechart avg(pctIdle) by host
| eval "HardCodedHostName"=100-'HardCodedHostName'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR if you want to do this for all host columns, you can use this foreach command (the &lt;CODE&gt;&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;&lt;/CODE&gt; to be used literally the way it's used here, no replacement required. see this for more details on &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.1.1/SearchReference/Foreach"&gt;foreach command&lt;/A&gt;)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=OS sourcetype=cpu | timechart avg(pctIdle) by host
| foreach * [| eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=100-'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']  [1]: 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 19 Jun 2018 16:18:30 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-06-19T16:18:30Z</dc:date>
    <item>
      <title>How to perform subtraction on results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-subtraction-on-results/m-p/396505#M168791</link>
      <description>&lt;P&gt;I'm currently using this in a search:&lt;BR /&gt;
index=OS sourcetype=cpu | timechart avg(pctIdle) by host&lt;/P&gt;

&lt;P&gt;This typically gives a result of around 96% for the host I'm running the query on.  I want to subtract that from 100 to give a result of 4%.  I know this should be simple, but I haven't got it to work yet.  Any help is appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 15:03:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-subtraction-on-results/m-p/396505#M168791</guid>
      <dc:creator>brosselle</dc:creator>
      <dc:date>2018-06-19T15:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform subtraction on results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-subtraction-on-results/m-p/396506#M168792</link>
      <description>&lt;P&gt;So after you timechart command, you'll get column _time and one column for each host with name of the column being the host name (e.g. _time host1 host2 etc). How to do any operation on those fields, you'd need to use the exact field name (which is the host name), so you can either use the hardcoded name of the host like this (putting it in single quotes in the expression parts as it may have special chars)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=OS sourcetype=cpu | timechart avg(pctIdle) by host
| eval "HardCodedHostName"=100-'HardCodedHostName'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR if you want to do this for all host columns, you can use this foreach command (the &lt;CODE&gt;&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;&lt;/CODE&gt; to be used literally the way it's used here, no replacement required. see this for more details on &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.1.1/SearchReference/Foreach"&gt;foreach command&lt;/A&gt;)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=OS sourcetype=cpu | timechart avg(pctIdle) by host
| foreach * [| eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=100-'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']  [1]: 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jun 2018 16:18:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-subtraction-on-results/m-p/396506#M168792</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-06-19T16:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform subtraction on results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-subtraction-on-results/m-p/396507#M168793</link>
      <description>&lt;P&gt;Hi @brosselle&lt;/P&gt;

&lt;P&gt;try this below query&lt;/P&gt;

&lt;P&gt;index=OS sourcetype=cpu | timechart avg(pctIdle) by host |eval calc = (100 - 'hostfieldnamefrompreviuosresults') | fields calc hostfieldnamefrompreviuosresults&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 16:23:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-subtraction-on-results/m-p/396507#M168793</guid>
      <dc:creator>PowerPacked</dc:creator>
      <dc:date>2018-06-19T16:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform subtraction on results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-subtraction-on-results/m-p/396508#M168794</link>
      <description>&lt;P&gt;Wow.  I would have never come up with this:&lt;BR /&gt;
| foreach * [| eval "&amp;lt;&amp;gt;"=100-'&amp;lt;&amp;gt;'] &lt;/P&gt;

&lt;P&gt;Worked perfectly.  Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 17:21:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-subtraction-on-results/m-p/396508#M168794</guid>
      <dc:creator>brosselle</dc:creator>
      <dc:date>2018-06-19T17:21:11Z</dc:date>
    </item>
  </channel>
</rss>

