<?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: Counts in stats command not working the way I expected in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Counts-in-stats-command-not-working-the-way-I-expected/m-p/345098#M102241</link>
    <description>&lt;P&gt;Your aggregation was done based on customerId and it seems one Account ID was associated with multiple customerId hence you get 3 different rows (one for each customerId) with same Account ID. May be do a second aggregation by aid, like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=wholesale_app   [search index="wholesale_app"  product=* CustomAnalytic Properties.index=33 (refreshWsCVRToken OR obtainWsCVRToken) |table clientSessionId] customerId OR (refreshWsCVRToken OR obtainWsCVRToken)|rex "(?&amp;lt;accountid&amp;gt;\w+)..,..customerId"|rex "sites.\d+.(?&amp;lt;token_type&amp;gt;\w+)"|stats values(accountid) as aid count(eval(token_type="refreshWsCVRToken")) as rcount count(eval(token_type="obtainWsCVRToken")) as ocount by clientSessionId 
|where aid!="" AND isnotnull(aid) AND len(aid)&amp;lt;=15
| stats sum(*count) as *count by aid  |sort -rcount |rename aid as "Account ID" rcount as "Refresh token" ocount as "Obtain token"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 02 Feb 2018 20:53:41 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-02-02T20:53:41Z</dc:date>
    <item>
      <title>Counts in stats command not working the way I expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Counts-in-stats-command-not-working-the-way-I-expected/m-p/345097#M102240</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have this query.  It "works" (well mostly).  What I'm confused about is the resulting stat table&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=wholesale_app   [search index="wholesale_app"  product=* CustomAnalytic Properties.index=33 (refreshWsCVRToken OR obtainWsCVRToken) |table clientSessionId] customerId OR (refreshWsCVRToken OR obtainWsCVRToken)|rex "(?&amp;lt;accountid&amp;gt;\w+)..,..customerId"|rex "sites.\d+.(?&amp;lt;token_type&amp;gt;\w+)"|stats values(accountid) as aid count(eval(token_type="refreshWsCVRToken")) as rcount count(eval(token_type="obtainWsCVRToken")) as ocount by clientSessionId  |sort -Count|fields - clientSessionId|where aid!=""|where len(aid)&amp;lt;=15 |rename aid as "Account ID" rcount as "Refresh token" ocount as "Obtain token"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Resulting stats table.  I see three entries for the same account number with 1 as the count.  I'd like 1 entry for the account but with a count of 3.  Any thoughts?&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/4267iDA2AC32E503DBA87/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>Fri, 02 Feb 2018 20:43:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Counts-in-stats-command-not-working-the-way-I-expected/m-p/345097#M102240</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-02-02T20:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Counts in stats command not working the way I expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Counts-in-stats-command-not-working-the-way-I-expected/m-p/345098#M102241</link>
      <description>&lt;P&gt;Your aggregation was done based on customerId and it seems one Account ID was associated with multiple customerId hence you get 3 different rows (one for each customerId) with same Account ID. May be do a second aggregation by aid, like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=wholesale_app   [search index="wholesale_app"  product=* CustomAnalytic Properties.index=33 (refreshWsCVRToken OR obtainWsCVRToken) |table clientSessionId] customerId OR (refreshWsCVRToken OR obtainWsCVRToken)|rex "(?&amp;lt;accountid&amp;gt;\w+)..,..customerId"|rex "sites.\d+.(?&amp;lt;token_type&amp;gt;\w+)"|stats values(accountid) as aid count(eval(token_type="refreshWsCVRToken")) as rcount count(eval(token_type="obtainWsCVRToken")) as ocount by clientSessionId 
|where aid!="" AND isnotnull(aid) AND len(aid)&amp;lt;=15
| stats sum(*count) as *count by aid  |sort -rcount |rename aid as "Account ID" rcount as "Refresh token" ocount as "Obtain token"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Feb 2018 20:53:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Counts-in-stats-command-not-working-the-way-I-expected/m-p/345098#M102241</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-02T20:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Counts in stats command not working the way I expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Counts-in-stats-command-not-working-the-way-I-expected/m-p/345099#M102242</link>
      <description>&lt;P&gt;Wow, one day when I grow up I want to be able to do what you do &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks again Somesoni2!!!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 20:56:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Counts-in-stats-command-not-working-the-way-I-expected/m-p/345099#M102242</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-02-02T20:56:40Z</dc:date>
    </item>
  </channel>
</rss>

