<?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 can I do a sum of count for if statement? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342145#M101378</link>
    <description>&lt;P&gt;In the eval command expressions (and where command too), if a field name contains spaces, you need to enclose them in single quotes not double quotes. With double quotes, they are treated as literal string instead of fields. You did it correctly in line 2 (replace command) but missed in line three. Correcting that would resolve your issue.&lt;/P&gt;

&lt;P&gt;Like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="monthlycdr"
| eval "Disconnect Info"=replace('Disconnect Info' ,"\"","")
| eval "Failure Rate" = if(match('Disconnect Info',"(?i)Failed Attempt"),1,0)
| stats sum("Failure Rate")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Nov 2017 19:08:27 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-11-02T19:08:27Z</dc:date>
    <item>
      <title>How can I do a sum of count for if statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342144#M101377</link>
      <description>&lt;P&gt;When I do a stats count by a specific column. The count for each of them work. Here is the picture:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3769i77DBFABEF850973F/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;But when I actually try to count only the Failed Attempt call. The result is 0. Did I do something wrong here?&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3770i51DD86DE3B098675/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 18:56:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342144#M101377</guid>
      <dc:creator>tamduong16</dc:creator>
      <dc:date>2017-11-02T18:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a sum of count for if statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342145#M101378</link>
      <description>&lt;P&gt;In the eval command expressions (and where command too), if a field name contains spaces, you need to enclose them in single quotes not double quotes. With double quotes, they are treated as literal string instead of fields. You did it correctly in line 2 (replace command) but missed in line three. Correcting that would resolve your issue.&lt;/P&gt;

&lt;P&gt;Like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="monthlycdr"
| eval "Disconnect Info"=replace('Disconnect Info' ,"\"","")
| eval "Failure Rate" = if(match('Disconnect Info',"(?i)Failed Attempt"),1,0)
| stats sum("Failure Rate")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2017 19:08:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342145#M101378</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-11-02T19:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a sum of count for if statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342146#M101379</link>
      <description>&lt;P&gt;I think following is the only query required. &lt;CODE&gt;| eval "Disconnect Info"=replace('Disconnect Info' ,"\"","")&lt;/CODE&gt; before stats is required only if double quotes may be present between "Failed Attempt" pattern being matched.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="monthlycdr"
|  stats count(eval(match('Disconnect Info',"(?i)^Failed Attempt"))) as "Failed Attempt"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2017 19:17:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342146#M101379</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-02T19:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a sum of count for if statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342147#M101380</link>
      <description>&lt;P&gt;can you avoid the spaces? SPL works better, generally, without them.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=monthlycdr
|eval DisconnectInfo=replace('Disconnect Info',"\"","")
|eval "FailureRate"=if(match(DisconnectInfo,"(?i)Failed Attempt"),1,0)
|stats sum(FailureRate) as "Failure Rate"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2017 19:29:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342147#M101380</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-11-02T19:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a sum of count for if statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342148#M101381</link>
      <description>&lt;P&gt;thanks guys&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 19:54:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-sum-of-count-for-if-statement/m-p/342148#M101381</guid>
      <dc:creator>tamduong16</dc:creator>
      <dc:date>2017-11-02T19:54:00Z</dc:date>
    </item>
  </channel>
</rss>

