<?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 Compare search fields to add another field if they match in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-fields-to-add-another-field-if-they-match/m-p/288378#M87300</link>
    <description>&lt;P&gt;So at the moment I have a simple search &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=index sourcetype="sourcetype"  host1 OR host2 | table hour day month AvgCpuPerc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this returns results like &lt;BR /&gt;
18:00 12th Friday June 22%&lt;BR /&gt;
18:00 12th Friday June 48%&lt;BR /&gt;
17:00 12th Friday June 19%&lt;BR /&gt;
17:00 12th Friday June 41%&lt;/P&gt;

&lt;P&gt;What I would like to do, is have the results like this, but instead of having duplicate dates, have only one result for each date with the AvgCpuPerc column added, to give a result like this&lt;/P&gt;

&lt;P&gt;18:00 12th Friday June 70%&lt;BR /&gt;
17:00 12th Friday June 60%&lt;/P&gt;

&lt;P&gt;How do I do this? &lt;/P&gt;</description>
    <pubDate>Tue, 04 Jul 2017 07:39:40 GMT</pubDate>
    <dc:creator>danielsavage</dc:creator>
    <dc:date>2017-07-04T07:39:40Z</dc:date>
    <item>
      <title>Compare search fields to add another field if they match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-fields-to-add-another-field-if-they-match/m-p/288378#M87300</link>
      <description>&lt;P&gt;So at the moment I have a simple search &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=index sourcetype="sourcetype"  host1 OR host2 | table hour day month AvgCpuPerc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this returns results like &lt;BR /&gt;
18:00 12th Friday June 22%&lt;BR /&gt;
18:00 12th Friday June 48%&lt;BR /&gt;
17:00 12th Friday June 19%&lt;BR /&gt;
17:00 12th Friday June 41%&lt;/P&gt;

&lt;P&gt;What I would like to do, is have the results like this, but instead of having duplicate dates, have only one result for each date with the AvgCpuPerc column added, to give a result like this&lt;/P&gt;

&lt;P&gt;18:00 12th Friday June 70%&lt;BR /&gt;
17:00 12th Friday June 60%&lt;/P&gt;

&lt;P&gt;How do I do this? &lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2017 07:39:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-fields-to-add-another-field-if-they-match/m-p/288378#M87300</guid>
      <dc:creator>danielsavage</dc:creator>
      <dc:date>2017-07-04T07:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Compare search fields to add another field if they match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-fields-to-add-another-field-if-they-match/m-p/288379#M87301</link>
      <description>&lt;P&gt;Try this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=index sourcetype="sourcetype"  host1 OR host2 | stats sum(AvgCpuPerc) as AvgCpuPerc by hour day month | table hour date month AvgCpuPerc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the '%' character is part of the data then it will have to be removed for the &lt;CODE&gt;stats&lt;/CODE&gt; command to work.  Like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=index sourcetype="sourcetype"  host1 OR host2  | eval AvgCpuPerc=trim(AvgCpuPerc,"%") |  stats sum(AvgCpuPerc) as AvgCpuPerc by hour day month | eval AvgCpuPerc=AvgCpuPerc."%" | table hour date month AvgCpuPerc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jul 2017 15:06:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-fields-to-add-another-field-if-they-match/m-p/288379#M87301</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-07-04T15:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Compare search fields to add another field if they match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-search-fields-to-add-another-field-if-they-match/m-p/288380#M87302</link>
      <description>&lt;P&gt;hello there, &lt;BR /&gt;
looks like in your example you summed the percentages when saying you want average,&lt;BR /&gt;
regardless, use stats command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=index sourcetype="sourcetype"  host1 OR host2 |stats avg(AvgCpuPerc) as hour_avg sum(AvgCpuPerc) as hour_sum by hour day month AvgCpuPerc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2017 15:10:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-search-fields-to-add-another-field-if-they-match/m-p/288380#M87302</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2017-07-04T15:10:03Z</dc:date>
    </item>
  </channel>
</rss>

