<?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: User Query count based on conditions in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37627#M8442</link>
    <description>&lt;P&gt;Can any one answer my question?&lt;/P&gt;</description>
    <pubDate>Tue, 21 May 2013 18:03:17 GMT</pubDate>
    <dc:creator>freephoneid</dc:creator>
    <dc:date>2013-05-21T18:03:17Z</dc:date>
    <item>
      <title>User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37619#M8434</link>
      <description>&lt;P&gt;I've below line in my logs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[2013-01-15 20:06:51:641 GMT+00:00] INFO #new# userid=1234 chair_count=1 table_count=1 sofaAvailable=true
[2013-02-15 21:06:51:642 GMT+00:00] INFO userid=1234 chair_count=1 table_count=0 sofaAvailable=false
[2013-03-15 22:06:51:643 GMT+00:00] INFO #new# userid=3452 chair_count=1 table_count=1 sofaAvailable=true
[2013-04-15 23:06:51:644 GMT+00:00] INFO #new# userid=1234 chair_count=2 table_count=3 sofaAvailable=false
[2013-05-01 10:06:51:645 GMT+00:00] INFO #new# userid=3564 chair_count=1 table_count=2 sofaAvailable=true
[2013-05-05 11:06:51:646 GMT+00:00] INFO #new# userid=2443 chair_count=1 table_count=1 sofaAvailable=true
[2013-05-07 12:06:51:647 GMT+00:00] INFO #new# userid=2265 chair_count=1 table_count=1 sofaAvailable=false
[2013-05-01 10:06:51:645 GMT+00:00] INFO #new# userid=3564 chair_count=1 table_count=0 sofaAvailable=true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can any one confirm if below query is correct to get the count of all users who are having at least 1 chair &amp;amp; who are new users (by looking at tag #new#) &amp;amp; whose sofaAvailable is true?&lt;/P&gt;

&lt;P&gt;Note that if there are multiple entries for the same user in the log, then I need to take the chair count &amp;amp; table count of the latest entry only.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#new# chair_count &amp;gt; 0 | stats count

Here, the output should be 3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, can you confirm if below query is correct to get count of all users who are having at least 1 chair &amp;amp; who have at least 1 table &amp;amp; who are new users (by looking at tag #new#) &amp;amp; whose sofaAvailable is true?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#new# chair_count &amp;gt; 0 table_count &amp;gt; 0 | stats count

Here, the output should be 2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2013 02:11:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37619#M8434</guid>
      <dc:creator>freephoneid</dc:creator>
      <dc:date>2013-05-17T02:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37620#M8435</link>
      <description>&lt;P&gt;For your first search, you need to search based on the latest information for each user. &lt;BR /&gt;
You can adjust search terms order for optimization, but here is a sample search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#new# | stats latest(chair_count) as chair_count latest(table_count) as table_count latest(sofaAvailable) as sofaAvailable latest(_raw) by userid | where chair_count&amp;gt;0 and sofaAvailable="true"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For your 2nd search,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#new# | stats latest(chair_count) as chair_count latest(table_count) as table_count latest(sofaAvailable) as sofaAvailable latest(_raw) by userid | where chair_count&amp;gt;0 and table_count&amp;gt;0 and sofaAvailable="true"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;By adding "| stats" count after each earch, you can get the number of users with your criteria.&lt;/P&gt;

&lt;P&gt;For example,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$ /opt/splunk/bin/splunk search '#new# | stats latest(chair_count) as chair_count latest(table_count) as table_count latest(sofaAvailable) as sofaAvailable latest(_raw) by userid | where chair_count&amp;gt;0 and sofaAvailable="true" | stats count'

count
-----
    3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2013 03:41:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37620#M8435</guid>
      <dc:creator>melonman</dc:creator>
      <dc:date>2013-05-17T03:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37621#M8436</link>
      <description>&lt;P&gt;Thanks for the answer. I would like to know if below query is also an alternate correct answer or not for the 2nd question:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#new# chair_count &amp;gt; 0 table_count &amp;gt; 0 sofaAvailable=true | stats first(table_count) as tcount, first(sofaAvailable) as sofa first(chair_count) as ccount by userid | where sofa = "true" and tcount &amp;gt; 0 and ccount &amp;gt; 0 | stats count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If above is also correct, then which one is best in terms of performance?&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2013 04:43:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37621#M8436</guid>
      <dc:creator>freephoneid</dc:creator>
      <dc:date>2013-05-17T04:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37622#M8437</link>
      <description>&lt;P&gt;What about this search: #new# chair_count &amp;gt; 0 table_count &amp;gt; 0 sofaAvailable=true |stats latest(chair_count) as chair_count latest(table_count) as table_count latest(sofaAvailable) as sofaAvailable latest(_raw) by userid |stats count&lt;/P&gt;

&lt;P&gt;I think this will be fast as we are getting all results in first search not in second(after |)and also search result will be less as #new# chair_count &amp;gt; 0 table_count &amp;gt; 0 sofaAvailable=true and specfic than only #new#, but please give suggestions then it will be good....&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:55:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37622#M8437</guid>
      <dc:creator>kml_uvce</dc:creator>
      <dc:date>2020-09-28T13:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37623#M8438</link>
      <description>&lt;P&gt;Can any Splunk Expert comment about the performance among these 3 different answers &amp;amp; tell us which one is better?&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2013 06:30:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37623#M8438</guid>
      <dc:creator>freephoneid</dc:creator>
      <dc:date>2013-05-17T06:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37624#M8439</link>
      <description>&lt;P&gt;kml_uvce's search is faster as all unnecessary events are filtered out at the beginning. I was trying to show basic idea step by step in the search &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; also you can customize my search to do similar analysis.&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2013 07:25:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37624#M8439</guid>
      <dc:creator>melonman</dc:creator>
      <dc:date>2013-05-17T07:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37625#M8440</link>
      <description>&lt;P&gt;yes same concept I have as all events are filterd out in begining in my search &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2013 08:13:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37625#M8440</guid>
      <dc:creator>kml_uvce</dc:creator>
      <dc:date>2013-05-17T08:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37626#M8441</link>
      <description>&lt;P&gt;Quick question: The 2nd part which is "...| stats latest(chair_count) as chair_count latest(table_count) as table_count latest(sofaAvailable) as sofaAvailable latest(_raw) by userid", here, why u need to stats all 3 together? Why can't we just do "...| stats latest(chair_count) by userid | stats count"?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:56:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37626#M8441</guid>
      <dc:creator>freephoneid</dc:creator>
      <dc:date>2020-09-28T13:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37627#M8442</link>
      <description>&lt;P&gt;Can any one answer my question?&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2013 18:03:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37627#M8442</guid>
      <dc:creator>freephoneid</dc:creator>
      <dc:date>2013-05-21T18:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37628#M8443</link>
      <description>&lt;P&gt;Quick question: The 2nd part which is &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| stats latest(chair_count) as chair_count latest(table_count) as table_count latest(sofaAvailable) as sofaAvailable latest(_raw) by userid
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;here, why u need to stats all 3 together? Why can't we just do as shown below?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| stats latest(chair_count) by userid | stats count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 May 2013 18:04:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37628#M8443</guid>
      <dc:creator>freephoneid</dc:creator>
      <dc:date>2013-05-21T18:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: User Query count based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37629#M8444</link>
      <description>&lt;P&gt;try this also&lt;/P&gt;

&lt;P&gt;...| dedup userid | stats count&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2013 02:22:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-Query-count-based-on-conditions/m-p/37629#M8444</guid>
      <dc:creator>kml_uvce</dc:creator>
      <dc:date>2013-05-22T02:22:46Z</dc:date>
    </item>
  </channel>
</rss>

