<?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 I create a derived field using two searches? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451904#M127963</link>
    <description>&lt;P&gt;This code worked without error when I plugged in my values and it returned exactly what I was looking for.  Well done!&lt;/P&gt;</description>
    <pubDate>Fri, 07 Sep 2018 16:17:01 GMT</pubDate>
    <dc:creator>SlothB77</dc:creator>
    <dc:date>2018-09-07T16:17:01Z</dc:date>
    <item>
      <title>How do I create a derived field using two searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451900#M127959</link>
      <description>&lt;P&gt;I want to create a derived field using a search string like so:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;(host=HostA sourcetype="SourceTypeA" counter="CounterA" avg(ValueA)) /&lt;BR /&gt;
(host=HostA sourcetype="SourceTypeA" counter="CounterB" avg(ValueB))&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;This divides the average &lt;EM&gt;value&lt;/EM&gt; when counter=CounterA by the average &lt;EM&gt;value&lt;/EM&gt; when counter=CounterB.  I get an error when I plug this search string into the Splunk dynamic search.&lt;/P&gt;

&lt;P&gt;I tried this alternative version:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;host=Host sourcetype=SourceType counter=CounterA avg(Value) by GroupByField as numerator&lt;BR /&gt;
counter=CounterB avg(ValueB) by GroupByField as denominator |&lt;BR /&gt;&lt;BR /&gt;
eval quotient= numerator/denominator | &lt;BR /&gt;
table GroupByField, quotient&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;but no luck.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 15:42:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451900#M127959</guid>
      <dc:creator>SlothB77</dc:creator>
      <dc:date>2018-09-07T15:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a derived field using two searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451901#M127960</link>
      <description>&lt;P&gt;Hi @SlothB77,&lt;/P&gt;

&lt;P&gt;please provide us some sample data and an expected output with further clarification on what you are expecting to do. &lt;/P&gt;

&lt;P&gt;Unfortunately your SPL is just a mess. And I can't figure out what you are trying to do.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 16:01:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451901#M127960</guid>
      <dc:creator>horsefez</dc:creator>
      <dc:date>2018-09-07T16:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a derived field using two searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451902#M127961</link>
      <description>&lt;P&gt;Hi @SlothB77,&lt;/P&gt;

&lt;P&gt;I just throw a random suggestion out there. &lt;/P&gt;

&lt;P&gt;How about:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=HostA sourcetype="SourceTypeA"
| stats avg(ValueA) AS average_valueA, avg(ValueB) AS average_valueB by counter
| stats values(*) as *
| ratio=average_valueA/average_valueB
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Props go to @DalJeanis for help on the last two lines!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 16:09:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451902#M127961</guid>
      <dc:creator>horsefez</dc:creator>
      <dc:date>2018-09-07T16:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a derived field using two searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451903#M127962</link>
      <description>&lt;P&gt;@SlothB77,&lt;BR /&gt;
Try,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=Host sourcetype=SourceType |stats avg(eval(if(counter=CounterA,ValueA,null()))) as numerator,
                                       avg(eval(if(counter=CounterB,ValueB,null()))) as denominator 
                                       by GroupByField 
|eval quotient= numerator/denominator
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Sep 2018 16:11:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451903#M127962</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-09-07T16:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a derived field using two searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451904#M127963</link>
      <description>&lt;P&gt;This code worked without error when I plugged in my values and it returned exactly what I was looking for.  Well done!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 16:17:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-create-a-derived-field-using-two-searches/m-p/451904#M127963</guid>
      <dc:creator>SlothB77</dc:creator>
      <dc:date>2018-09-07T16:17:01Z</dc:date>
    </item>
  </channel>
</rss>

