<?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 calculating field percentages before stats command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/calculating-field-percentages-before-stats-command/m-p/509905#M142544</link>
    <description>&lt;P&gt;index= base search | stats count, avg(ElapsedTime) as duration,&amp;nbsp; by requestName, LogType, errorMessage, HttpStatus, isValidError&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there anyway i can calculate the success percent of each requestName field based on HttpStatus values(&amp;lt;299 success and &amp;gt;299 failure) before executing stats command and then include that in the result table?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any help.&lt;/P&gt;</description>
    <pubDate>Sun, 19 Jul 2020 19:35:13 GMT</pubDate>
    <dc:creator>amerineni</dc:creator>
    <dc:date>2020-07-19T19:35:13Z</dc:date>
    <item>
      <title>calculating field percentages before stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculating-field-percentages-before-stats-command/m-p/509905#M142544</link>
      <description>&lt;P&gt;index= base search | stats count, avg(ElapsedTime) as duration,&amp;nbsp; by requestName, LogType, errorMessage, HttpStatus, isValidError&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there anyway i can calculate the success percent of each requestName field based on HttpStatus values(&amp;lt;299 success and &amp;gt;299 failure) before executing stats command and then include that in the result table?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any help.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jul 2020 19:35:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculating-field-percentages-before-stats-command/m-p/509905#M142544</guid>
      <dc:creator>amerineni</dc:creator>
      <dc:date>2020-07-19T19:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: calculating field percentages before stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculating-field-percentages-before-stats-command/m-p/509920#M142549</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;You could try this:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;index=base search 
| eval h_ok=if(HttpStatus &amp;lt; 299, 1, 0)
| eval h_nok=if(HttpStatus &amp;gt; 299, 1, 0)
| stats sum(h_ok) as h_ok, sum(h_nok) as h_nok, count, avg(ElapsedTime) as duration,  by requestName, LogType, errorMessage, HttpStatus, isValidError
| eval h_per_ok = round(h_ok/(h_ok + h_nok),2)*100, h_per_nok = round(h_nok/(h_ok+h_nok),2)
| table h_per_ok, h_per_nok, requestName, ....&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 19 Jul 2020 20:50:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculating-field-percentages-before-stats-command/m-p/509920#M142549</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2020-07-19T20:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: calculating field percentages before stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculating-field-percentages-before-stats-command/m-p/509925#M142551</link>
      <description>&lt;P&gt;thanks for the quick response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like this&lt;/P&gt;&lt;P&gt;requestName1&amp;nbsp; &amp;nbsp; &amp;nbsp;logType1&amp;nbsp; errorMessage1&lt;/P&gt;&lt;P&gt;requestName1&amp;nbsp; &amp;nbsp; &amp;nbsp;logType1&amp;nbsp; errorMessage2&lt;/P&gt;&lt;P&gt;the query you suggested returns different success percent for the above two combinations. However i want to populate a column with total success percent for "request1" not individual combinations success percents. Hope explained what i need correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm doing a sub query to calculate to percentages and then joining now. Wanted to know if there is a better way. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jul 2020 21:16:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculating-field-percentages-before-stats-command/m-p/509925#M142551</guid>
      <dc:creator>amerineni</dc:creator>
      <dc:date>2020-07-19T21:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: calculating field percentages before stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculating-field-percentages-before-stats-command/m-p/509959#M142564</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/74590"&gt;@amerineni&lt;/a&gt;&amp;nbsp; this should provide the guidance on what you need&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="HttpStatus, isValidError
200, false
200, false
201, false
305, true
202, false
400, true
500, true"
| multikv forceheader=1
| rename COMMENT AS "CHECK THE CODE FROM HERE ON"
| eval result = if(HttpStatus &amp;lt; 299, 1, 0)
| eventstats count as TotalSuccessFailure by result
| eventstats count as TotalEvents
| eval percent = round((TotalSuccessFailure / TotalEvents) * 100,1)
| rename COMMENT AS "CHECK THE CODE ABOVE HERE"
| fields HttpStatus result TotalSuccessFailure TotalEvents percent&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can than take it further and just get the score by using stats&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats values(percent) by result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2020 06:00:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculating-field-percentages-before-stats-command/m-p/509959#M142564</guid>
      <dc:creator>anmolpatel</dc:creator>
      <dc:date>2020-07-20T06:00:56Z</dc:date>
    </item>
  </channel>
</rss>

