<?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 Conditional count on two values in a single field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Conditional-count-on-two-values-in-a-single-field/m-p/35013#M7693</link>
    <description>&lt;P&gt;I'm attempting to do a conditional count directly in a stats function. I want a list by application / version that displays a count of errors  and a count of exceptions. I believe I need  a conditional count, however filtering my data in the search will not work for my data.&lt;/P&gt;

&lt;P&gt;I have a field Severity which contains Errors,Info,Warnings. Severity=Error includes both Exceptions and stuff we classify as an Error. We have another field ExceptionType which if not null, we know that the Severity=Error is really an exception not just a normal error. I want to count the Errors that are not exceptions, and the Exceptions separately. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search Severity="Error" | eval ErrorSeverity=if(isnotnull(ExceptionType),"Exception","Error") | stats count(ErrorSeverity=Exception) as Exception, count(ErrorSeverity=Error) as Error by Application, Version
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output should look something like this:&lt;BR /&gt;
Application     Version      Exception       Error&lt;BR /&gt;
App1            2.2.23          5              3&lt;BR /&gt;
App1            2.4.23          1              9&lt;BR /&gt;
App2            1.39.33         29             0&lt;BR /&gt;
App3            1.39.33         0              54&lt;/P&gt;

&lt;P&gt;I should never see both the Error and Exception count = 0, everything should be one or the other since both are classified as Severity="Error"&lt;/P&gt;</description>
    <pubDate>Wed, 15 May 2013 16:29:27 GMT</pubDate>
    <dc:creator>rmichel876</dc:creator>
    <dc:date>2013-05-15T16:29:27Z</dc:date>
    <item>
      <title>Conditional count on two values in a single field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-count-on-two-values-in-a-single-field/m-p/35013#M7693</link>
      <description>&lt;P&gt;I'm attempting to do a conditional count directly in a stats function. I want a list by application / version that displays a count of errors  and a count of exceptions. I believe I need  a conditional count, however filtering my data in the search will not work for my data.&lt;/P&gt;

&lt;P&gt;I have a field Severity which contains Errors,Info,Warnings. Severity=Error includes both Exceptions and stuff we classify as an Error. We have another field ExceptionType which if not null, we know that the Severity=Error is really an exception not just a normal error. I want to count the Errors that are not exceptions, and the Exceptions separately. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search Severity="Error" | eval ErrorSeverity=if(isnotnull(ExceptionType),"Exception","Error") | stats count(ErrorSeverity=Exception) as Exception, count(ErrorSeverity=Error) as Error by Application, Version
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output should look something like this:&lt;BR /&gt;
Application     Version      Exception       Error&lt;BR /&gt;
App1            2.2.23          5              3&lt;BR /&gt;
App1            2.4.23          1              9&lt;BR /&gt;
App2            1.39.33         29             0&lt;BR /&gt;
App3            1.39.33         0              54&lt;/P&gt;

&lt;P&gt;I should never see both the Error and Exception count = 0, everything should be one or the other since both are classified as Severity="Error"&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2013 16:29:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-count-on-two-values-in-a-single-field/m-p/35013#M7693</guid>
      <dc:creator>rmichel876</dc:creator>
      <dc:date>2013-05-15T16:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional count on two values in a single field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-count-on-two-values-in-a-single-field/m-p/35014#M7694</link>
      <description>&lt;P&gt;count() isn't smart enough to do conditional logic, so you need to put your try-hard hat on and do it upstream.&lt;/P&gt;

&lt;P&gt;Severity="Error" | eval Exception=if(isnotnull(ExceptionType),"1",null()) | eval Error=if(isnull(ExceptionType),"1",null()) | stats count(Exception) as Exception, count(Error) as Error by Application, Version&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2013 17:42:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-count-on-two-values-in-a-single-field/m-p/35014#M7694</guid>
      <dc:creator>tiberious726</dc:creator>
      <dc:date>2013-05-15T17:42:18Z</dc:date>
    </item>
  </channel>
</rss>

