<?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: Where clause with eval and stats in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113835#M30049</link>
    <description>&lt;P&gt;The answer I gave above will give you what you want.&lt;/P&gt;</description>
    <pubDate>Tue, 19 May 2015 13:23:51 GMT</pubDate>
    <dc:creator>aweitzman</dc:creator>
    <dc:date>2015-05-19T13:23:51Z</dc:date>
    <item>
      <title>Where clause with eval and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113831#M30045</link>
      <description>&lt;P&gt;Hi All.&lt;BR /&gt;
I want to calculate percent of Total revenue in Rural and Urban areas.&lt;BR /&gt;
The columns i have are Total_Revenue and PLACEMENT with values 0 and 1 where 0 represents Rural and 1 represents Urban.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype="Customer_Churn" 
  | eventstats sum(Total_Revenue) as fin_rev
  | eventstats sum(Total_Revenue) as rural_rev where PLACEMENT=0
  | eventstats sum(Total_Revenue) aa urban_rev where PLACEMENT=1
  | eval REVENUE=rur_rev*100/urban_rev by PLACEMENT
  | replace 0 with Rural in PLACEMENT 
  | replace 1 with Urban in PLACEMENT
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the above query doesnt get executed. please improvise that.&lt;/P&gt;

&lt;P&gt;Thanks a lot in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2015 12:49:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113831#M30045</guid>
      <dc:creator>SanthoshSreshta</dc:creator>
      <dc:date>2015-05-19T12:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause with eval and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113832#M30046</link>
      <description>&lt;P&gt;I don't think you can put a &lt;CODE&gt;where&lt;/CODE&gt; statement inside of &lt;CODE&gt;eventstats&lt;/CODE&gt; like that.  Instead, try using &lt;CODE&gt;eval&lt;/CODE&gt; to create two new fields based on the value of PLACEMENT which you can then use &lt;CODE&gt;eventstats&lt;/CODE&gt; on.  Also, your &lt;CODE&gt;eval&lt;/CODE&gt; statement for REVENUE uses a &lt;CODE&gt;rur_rev&lt;/CODE&gt; field; should that be &lt;CODE&gt;rural_rev&lt;/CODE&gt; instead?  Something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="Customer_Churn" 
| eval Placement0Revenue=if(PLACEMENT="0", Total_Revenue, null())
| eval Placement1Revenue=if(PLACEMENT="1", Total_Revenue, null())
| eventstats sum(Total_Revenue) as fin_rev
| eventstats sum(Placement0Revenue) as rural_rev
| eventstats sum(Placement1Revenue) as urban_rev 
| eval REVENUE=rural_rev*100/urban_rev by PLACEMENT
| replace 0 with Rural in PLACEMENT 
| replace 1 with Urban in PLACEMENT
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There may be a more elegant way of accomplishing what you need, but I think this will work.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2015 13:06:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113832#M30046</guid>
      <dc:creator>wpreston</dc:creator>
      <dc:date>2015-05-19T13:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause with eval and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113833#M30047</link>
      <description>&lt;P&gt;I think you're making this harder than it needs to be. Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype="Customer_Churn" 
   | stats sum(Total_Revenue) as rev by PLACEMENT
   | eventstats sum(rev) as fin_rev
   | eval REVENUE = rev*100/fin_rev
   | table PLACEMENT REVENUE
   | replace 0 with Rural in PLACEMENT
   | replace 1 with Urban in PLACEMENT
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;stats&lt;/CODE&gt; will separate the sums for you; there's no need to compute them separately. Once that's done, you can use &lt;CODE&gt;eventstats&lt;/CODE&gt; to get the overall total, since you're just summing everything.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2015 13:14:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113833#M30047</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2015-05-19T13:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause with eval and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113834#M30048</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/174276"&gt;@wpreston&lt;/a&gt; Yes, I have missed that. I have corrected and checked it now.&lt;BR /&gt;
the code i have written is wrong anyways. can you please guide me in displaying the total_revenue percentage of each placement. the formula is REVENUE=rural_rev*100/fin_rev. this i have missed in above code. by this it is showing same values for both placements.&lt;BR /&gt;
Can you please correct it.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:59:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113834#M30048</guid>
      <dc:creator>SanthoshSreshta</dc:creator>
      <dc:date>2020-09-28T19:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause with eval and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113835#M30049</link>
      <description>&lt;P&gt;The answer I gave above will give you what you want.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2015 13:23:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113835#M30049</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2015-05-19T13:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause with eval and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113836#M30050</link>
      <description>&lt;P&gt;wow.!!&lt;BR /&gt;
you made it so simple in the first attempt itself. &lt;BR /&gt;
I have same type of requirement with churn also. can you guide me in solving that. both should be in same query. &lt;BR /&gt;
i will post a fresh one.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2015 13:25:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113836#M30050</guid>
      <dc:creator>SanthoshSreshta</dc:creator>
      <dc:date>2015-05-19T13:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause with eval and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113837#M30051</link>
      <description>&lt;P&gt;yes, i got it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2015 13:30:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113837#M30051</guid>
      <dc:creator>SanthoshSreshta</dc:creator>
      <dc:date>2015-05-19T13:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause with eval and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113838#M30052</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="Customer_Churn" | stats sum(Total_Revenue) as revenue by PLACEMENT | replace "0" with "rural_rev" in PLACEMENT | replace "1" with "urban_rev" in PLACEMENT | untable PLACEMENT revenue value | xyseries revenue PLACEMENT value | eval REVENUE=rur_rev*100/urban_rev
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 May 2015 14:30:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113838#M30052</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-05-19T14:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause with eval and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113839#M30053</link>
      <description>&lt;P&gt;Mine should be far more efficient than the other answer.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2015 14:32:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Where-clause-with-eval-and-stats/m-p/113839#M30053</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-05-19T14:32:33Z</dc:date>
    </item>
  </channel>
</rss>

