<?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: Why won't count match when using tstats? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-won-t-count-match-when-using-tstats/m-p/641377#M222212</link>
    <description>&lt;P&gt;Hi.&amp;nbsp; When you run tstats count by prefix(cod-data=) you end up getting counts for each value of cod-data.&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;0&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;&amp;lt;count of 0s&amp;gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;1&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;&amp;lt;count of 1s&amp;gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;n&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;&amp;lt;count of ns&amp;gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;And then&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;|eval Success=if(COD_data="0"&amp;nbsp; OR COD_data="", "Success", null())&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;|stats count(Success) as Successlogs&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;That will identify the fields where COD_data = 0 as Success&lt;BR /&gt;Finally the count with Count the number of rows of Success.. which = 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So something like&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;|tstats count where index=app-cod-idx&amp;nbsp; &amp;nbsp;host_ip=11.123.345.23&amp;nbsp; sourcetype=code:logs by PREFIX(cod-data=)&lt;BR /&gt;|rename cod-data= as COD_data&lt;BR /&gt;|where isnotnull(COD_data)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;| stats sum(eval(if(COD_data="0",count,0))) AS SuccessLogs, sum(eval(if(COD_data!="0",count,0))) AS FailedLogs,&amp;nbsp; sum(count) as totalcount&lt;BR /&gt;&lt;BR /&gt;The key is that you want to sum the count&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Apr 2023 06:21:16 GMT</pubDate>
    <dc:creator>burwell</dc:creator>
    <dc:date>2023-04-26T06:21:16Z</dc:date>
    <item>
      <title>Why won't count match when using tstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-won-t-count-match-when-using-tstats/m-p/641353#M222208</link>
      <description>&lt;P&gt;When compared to original query with tstats query success, failed&amp;nbsp; and total count is not matching.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;original query:&lt;BR /&gt;index=app-cod-idx&amp;nbsp; &amp;nbsp;host_ip=11.123.345.23&amp;nbsp; sourcetype=code:logs&lt;BR /&gt;|rex field =_raw "\|presentdata\:(?&amp;lt;COD_data&amp;gt;.*\|"&lt;BR /&gt;|where isnotnull(COD_data)&lt;BR /&gt;|eval Success=if(COD_data="0"&amp;nbsp; OR COD_data="", "Success", null())&lt;BR /&gt;|eval Failed=if(COD_data!="0", "Failed", null())&lt;BR /&gt;|stats count(Success) as Successlogs count(Failed ) as Failedlogs&amp;nbsp; count(COD_data) as totalcount&lt;/P&gt;
&lt;P&gt;OUTPUT:&lt;/P&gt;
&lt;TABLE border="1" width="34.983229961321655%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;Successlogs&lt;/TD&gt;
&lt;TD width="25%"&gt;Failedlogs&lt;/TD&gt;
&lt;TD width="1.2936610608020729%"&gt;totalcount&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;14&lt;/TD&gt;
&lt;TD width="25%"&gt;10&lt;/TD&gt;
&lt;TD width="1.2936610608020729%"&gt;24&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tstats query:&lt;/P&gt;
&lt;P&gt;|tstats count where index=app-cod-idx&amp;nbsp; &amp;nbsp;host_ip=11.123.345.23&amp;nbsp; sourcetype=code:logs by PREFIX(cod-data=)&lt;BR /&gt;|rename cod-data= as COD_data&lt;BR /&gt;|where isnotnull(COD_data)&lt;BR /&gt;|eval Success=if(COD_data="0"&amp;nbsp; OR COD_data="", "Success", null())&lt;BR /&gt;|eval Failed=if(COD_data!="0", "Failed", null())&lt;BR /&gt;|stats count(Success) as Successlogs count(Failed ) as Failedlogs&amp;nbsp; count(COD_data) as totalcount&lt;/P&gt;
&lt;P&gt;OUTPUT:&lt;/P&gt;
&lt;TABLE border="1" width="34.983229961321655%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%" height="24px"&gt;Successlogs&lt;/TD&gt;
&lt;TD width="25%" height="24px"&gt;Failedlogs&lt;/TD&gt;
&lt;TD width="1.2936610608020729%" height="24px"&gt;totalcount&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="24px"&gt;1&lt;/TD&gt;
&lt;TD width="25%" height="24px"&gt;0&lt;/TD&gt;
&lt;TD width="1.2936610608020729%" height="24px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 01:06:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-won-t-count-match-when-using-tstats/m-p/641353#M222208</guid>
      <dc:creator>mahesh27</dc:creator>
      <dc:date>2023-04-26T01:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why won't count match when using tstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-won-t-count-match-when-using-tstats/m-p/641373#M222209</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249143"&gt;@mahesh27&lt;/a&gt;&amp;nbsp;- I think that could be due to your extraction is different in both search:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;|rex field =_raw "\|presentdata\:(?&amp;lt;COD_data&amp;gt;.*\|"&lt;/LI&gt;&lt;LI&gt;PREFIX(cod-data=)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One starts with &lt;STRONG&gt;presentdata:&lt;/STRONG&gt; and second starts with &lt;STRONG&gt;cod-data=&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;But cannot tell more without looking at actual events.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps!!!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 06:02:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-won-t-count-match-when-using-tstats/m-p/641373#M222209</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2023-04-26T06:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why won't count match when using tstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-won-t-count-match-when-using-tstats/m-p/641377#M222212</link>
      <description>&lt;P&gt;Hi.&amp;nbsp; When you run tstats count by prefix(cod-data=) you end up getting counts for each value of cod-data.&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;0&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;&amp;lt;count of 0s&amp;gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;1&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;&amp;lt;count of 1s&amp;gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;n&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;&amp;lt;count of ns&amp;gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;And then&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;|eval Success=if(COD_data="0"&amp;nbsp; OR COD_data="", "Success", null())&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;|stats count(Success) as Successlogs&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;That will identify the fields where COD_data = 0 as Success&lt;BR /&gt;Finally the count with Count the number of rows of Success.. which = 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So something like&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;|tstats count where index=app-cod-idx&amp;nbsp; &amp;nbsp;host_ip=11.123.345.23&amp;nbsp; sourcetype=code:logs by PREFIX(cod-data=)&lt;BR /&gt;|rename cod-data= as COD_data&lt;BR /&gt;|where isnotnull(COD_data)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;| stats sum(eval(if(COD_data="0",count,0))) AS SuccessLogs, sum(eval(if(COD_data!="0",count,0))) AS FailedLogs,&amp;nbsp; sum(count) as totalcount&lt;BR /&gt;&lt;BR /&gt;The key is that you want to sum the count&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 06:21:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-won-t-count-match-when-using-tstats/m-p/641377#M222212</guid>
      <dc:creator>burwell</dc:creator>
      <dc:date>2023-04-26T06:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why won't count match when using tstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-won-t-count-match-when-using-tstats/m-p/641378#M222213</link>
      <description>&lt;P&gt;Apart from &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/93915"&gt;@VatsalJagani&lt;/a&gt; already pointed out, each of your searches works differently. The "raw" search extracts fields from events, then does stats count. The tstats search counts splitting by different values of the cod-data field. So even if your extractions matched in both of your searches, if cod-data field had always the same value, your "raw" search would extract and count all occurrences of that field but tstats would only give you one value at the beginning. And then you'd count that value (not sum!) so you'd end up with just 1 as the result.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 06:23:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-won-t-count-match-when-using-tstats/m-p/641378#M222213</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-04-26T06:23:08Z</dc:date>
    </item>
  </channel>
</rss>

