<?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 is there a discrepancy when grouping  by a variable vs searching? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297640#M89822</link>
    <description>&lt;P&gt;In the table, it should appear only once, with a count of 10.  &lt;/P&gt;</description>
    <pubDate>Thu, 06 Jul 2017 16:53:45 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-07-06T16:53:45Z</dc:date>
    <item>
      <title>Why is there a discrepancy when grouping  by a variable vs searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297632#M89814</link>
      <description>&lt;P&gt;I want to see how many times a user has accessed a database in a given time period.  I used &lt;/P&gt;

&lt;P&gt;sourcetype= h1 | stats count by database, user | sort -count|stats list(count), values(database) by user&lt;/P&gt;

&lt;P&gt;However, after running a search for specific users, the numbers that come up from the above line, do not match up with the number of search results I find by searching for specific users. Is there a reason for the discrepancy ?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 15:41:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297632#M89814</guid>
      <dc:creator>psangli</dc:creator>
      <dc:date>2017-07-06T15:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there a discrepancy when grouping  by a variable vs searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297633#M89815</link>
      <description>&lt;P&gt;Please give an example of the other search (with the username obfuscated)&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 15:50:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297633#M89815</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-06T15:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there a discrepancy when grouping  by a variable vs searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297634#M89816</link>
      <description>&lt;P&gt;sourcetype="h1" user = "user1" database = bdp&lt;/P&gt;

&lt;P&gt;In the search, bdp appears 10 times. But in the table, it only appears once.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 15:54:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297634#M89816</guid>
      <dc:creator>psangli</dc:creator>
      <dc:date>2017-07-06T15:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there a discrepancy when grouping  by a variable vs searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297635#M89817</link>
      <description>&lt;P&gt;A) I don't see anything obvious - you probably (?) don't have over 10K users / databases combinations, but there is a default maximum number of records returned from &lt;CODE&gt;sort&lt;/CODE&gt;, so you should get in the habit of using &lt;CODE&gt;sort 0&lt;/CODE&gt; instead of  plain&lt;CODE&gt;sort&lt;/CODE&gt;.  &lt;/P&gt;

&lt;P&gt;B) Also, when trying to compare two versions, always snap to the beginning and end of a time period, so you have a fixed set of results between the two to compare on. &lt;/P&gt;

&lt;P&gt;C) Always rename &lt;CODE&gt;count&lt;/CODE&gt;, because occasionally it will bite you when a later &lt;CODE&gt;stats&lt;/CODE&gt;-type command or &lt;CODE&gt;timechart&lt;/CODE&gt; gets confused.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Try this and compare to see if it fixes your issue....&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-1d@d latest=@d sourcetype= h1 
| stats count as countbydb by database, user    
| sort 0 - countbydb
| stats sum(countbydb) as theTotalCount, list(countbydb) as theCounts, values(database) as theDBs by user
| where user=="myselecteduser"

earliest=-1d@d latest=@d sourcetype= h1 user="myselecteduser"
| stats count as theTotalCount, values(database) as theDBs by user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If not, then consider something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-1d@d latest=@d sourcetype= h1 
| stats count as countbydb by database, user  
| eval DBandCount  = database." - ".countbydb  
| stats sum(countbydb) as theTotalCount, values(DBandCount) as theDBs by user
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jul 2017 16:03:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297635#M89817</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-06T16:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there a discrepancy when grouping  by a variable vs searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297636#M89818</link>
      <description>&lt;P&gt;I believe the&lt;BR /&gt;
sort -count &lt;BR /&gt;
part is wrong. It sorts the number of databases, but does not move the name along with it. The names stay in the same order.  How would I go about fixing that?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 16:21:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297636#M89818</guid>
      <dc:creator>psangli</dc:creator>
      <dc:date>2017-07-06T16:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there a discrepancy when grouping  by a variable vs searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297637#M89819</link>
      <description>&lt;P&gt;Use the by clause with sort.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 16:38:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297637#M89819</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-06T16:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there a discrepancy when grouping  by a variable vs searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297638#M89820</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;sourcetype="h1" | stats count as countbydb by database, user |sort by countbydb |stats list(countbydb), values(database) by user 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;is what I am using. It does not affect the user column. I tried placing the sort by countbydb at the end, but that does not work either.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 16:44:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297638#M89820</guid>
      <dc:creator>psangli</dc:creator>
      <dc:date>2017-07-06T16:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there a discrepancy when grouping  by a variable vs searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297639#M89821</link>
      <description>&lt;P&gt;Instead of &lt;CODE&gt;values(database)&lt;/CODE&gt; use &lt;CODE&gt;list(database)&lt;/CODE&gt; to retain the record order.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 16:52:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297639#M89821</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-06T16:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there a discrepancy when grouping  by a variable vs searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297640#M89822</link>
      <description>&lt;P&gt;In the table, it should appear only once, with a count of 10.  &lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 16:53:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297640#M89822</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-06T16:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there a discrepancy when grouping  by a variable vs searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297641#M89823</link>
      <description>&lt;P&gt;That works! Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 16:55:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-a-discrepancy-when-grouping-by-a-variable-vs/m-p/297641#M89823</guid>
      <dc:creator>psangli</dc:creator>
      <dc:date>2017-07-06T16:55:14Z</dc:date>
    </item>
  </channel>
</rss>

