<?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 How to show only certain results in the statistics (by hiding some search results)? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-show-only-certain-results-in-the-statistics-by-hiding/m-p/313710#M93913</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I would like to hide the following results in bold and only have the final eval statement show. I am only doing the calculations for the last eval statement. &lt;/P&gt;

&lt;P&gt;source="Dataset_Finance.csv" host="sample" index="dataintegration" sourcetype="SampleFinance" ObjectAccount="4*" OR ObjectAccount="5*"&lt;BR /&gt;
| eval &lt;STRONG&gt;Sales&lt;/STRONG&gt;=if(ObjectAccount="411010",DomesticAmount,0), Costs=if(like(ObjectAccount,"5%"),DomesticAmount,0)&lt;BR /&gt;
| stats sum(Sales) as &lt;STRONG&gt;Sales&lt;/STRONG&gt;, sum(Costs) as &lt;STRONG&gt;Costs&lt;/STRONG&gt; &lt;BR /&gt;
| eval &lt;STRONG&gt;CM&lt;/STRONG&gt;=Sales+Costs &lt;BR /&gt;
| eval CMPer=(CM/Sales)*100&lt;/P&gt;

&lt;P&gt;Also, I noticed that I can not put a by statement after the eval, should I only include it in the stats section and how will I be able to categorize the CMPer by another value? &lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 16:18:52 GMT</pubDate>
    <dc:creator>tonahoyos</dc:creator>
    <dc:date>2020-09-29T16:18:52Z</dc:date>
    <item>
      <title>How to show only certain results in the statistics (by hiding some search results)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-show-only-certain-results-in-the-statistics-by-hiding/m-p/313710#M93913</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I would like to hide the following results in bold and only have the final eval statement show. I am only doing the calculations for the last eval statement. &lt;/P&gt;

&lt;P&gt;source="Dataset_Finance.csv" host="sample" index="dataintegration" sourcetype="SampleFinance" ObjectAccount="4*" OR ObjectAccount="5*"&lt;BR /&gt;
| eval &lt;STRONG&gt;Sales&lt;/STRONG&gt;=if(ObjectAccount="411010",DomesticAmount,0), Costs=if(like(ObjectAccount,"5%"),DomesticAmount,0)&lt;BR /&gt;
| stats sum(Sales) as &lt;STRONG&gt;Sales&lt;/STRONG&gt;, sum(Costs) as &lt;STRONG&gt;Costs&lt;/STRONG&gt; &lt;BR /&gt;
| eval &lt;STRONG&gt;CM&lt;/STRONG&gt;=Sales+Costs &lt;BR /&gt;
| eval CMPer=(CM/Sales)*100&lt;/P&gt;

&lt;P&gt;Also, I noticed that I can not put a by statement after the eval, should I only include it in the stats section and how will I be able to categorize the CMPer by another value? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:18:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-show-only-certain-results-in-the-statistics-by-hiding/m-p/313710#M93913</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2020-09-29T16:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to show only certain results in the statistics (by hiding some search results)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-show-only-certain-results-in-the-statistics-by-hiding/m-p/313711#M93914</link>
      <description>&lt;P&gt;@tonahoyos, I think you need to reevaluate what you are trying to perform with your query.&lt;/P&gt;

&lt;P&gt;1) Your base search is looking for all ObjectAccount starting with &lt;CODE&gt;4*&lt;/CODE&gt;, however, in your stats you are performing a sum of &lt;CODE&gt;DomesticAmount&lt;/CODE&gt; only for ObjectAccount &lt;CODE&gt;411010&lt;/CODE&gt; for calculating &lt;CODE&gt;Sales&lt;/CODE&gt;. &lt;CODE&gt;Remaining are set to 0.&lt;/CODE&gt; So you should ideally filter for &lt;CODE&gt;ObjectAccount="411010"&lt;/CODE&gt; in base search rather than &lt;CODE&gt;"4*"&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;2) Also if you are calculating percent for Sales and Costs and you are converting Sales for everything other than ObjectAccount &lt;CODE&gt;411010&lt;/CODE&gt; as 0, then you will not be able to calculate percent for other Accounts. Percent calculation is indicating that you need only one Account 411010, unless I am misinterpreting the provided information.&lt;/P&gt;

&lt;P&gt;3) As a performance tuning tip you should perform eval after stats command. Also &lt;CODE&gt;by&lt;/CODE&gt; is applicable on transforming commands like &lt;CODE&gt;stats&lt;/CODE&gt;not on eval. The eval command is for expression evaluations like a=b+c etc.&lt;/P&gt;

&lt;P&gt;Having said that you can use &lt;CODE&gt;table&lt;/CODE&gt; or &lt;CODE&gt;fields&lt;/CODE&gt; command to retain only the fields you require in final table. Please try out the following query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="Dataset_Finance.csv" host="sample" index="dataintegration" sourcetype="SampleFinance" ObjectAccount="411010" OR ObjectAccount="5*"
| stats sum(DomesticAmount) as Sales, sum(DomesticAmount) as Costs by ObjectAccount
| eval Sales=if(ObjectAccount="411010",Sales,0), Costs=if(match(ObjectAccount,"^5"),Costs,0)
| eval CM=Sales+Costs 
| eval CMPer=(CM/Sales)*100
| table ObjectAccount CMPer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Notice above that :&lt;BR /&gt;
1) I have filtered only ObjectAccount="411010" in my base search.&lt;BR /&gt;
2) I have used &lt;CODE&gt;by ObjectAccount&lt;/CODE&gt; in stats function. &lt;BR /&gt;
3) Also the eval for Sales and Cost is after eval. &lt;BR /&gt;
4) Cost uses &lt;CODE&gt;match()&lt;/CODE&gt; function to use regular expression based pattern matching to find any ObjectAccount starting with 5.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;If you want to use your own query, you just need to add the following command to your existing search (since you do not have ObjectAccount in your stats&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table CMPer
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Oct 2017 15:42:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-show-only-certain-results-in-the-statistics-by-hiding/m-p/313711#M93914</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-16T15:42:51Z</dc:date>
    </item>
  </channel>
</rss>

