<?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: Count items satisfying a condition in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Count-items-satisfying-a-condition/m-p/299566#M90261</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Number of regular users (login &amp;gt;=5 times)&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... event=login| stats count by user | where count&amp;gt;=5 | stats count as "Number of regular users"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Number of open_page events done by regular users&lt;/STRONG&gt;&lt;BR /&gt;
To list regular users with corresponding open_page events&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... event=login OR event=open_page | chart count by user event | where login&amp;gt;=5 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To list total count of oepn_page events by regular users&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... event=login OR event=open_page | chart count by user event | where login&amp;gt;=5 | stats sum(open_page) as "Total open_page events by regular users"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Proportion of close_page per user type (regular vs occasional)&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... event=login OR event=close_page | chart count by user event | eval user_type=if(count&amp;gt;=5, "regular", "occasional") | eval temp=1 | chart sum(close_page) over temp by user_type | eval "Close_page Ratio(regular/occational)"=regular/occasional
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 09 Jan 2018 19:19:23 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-01-09T19:19:23Z</dc:date>
    <item>
      <title>Count items satisfying a condition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-items-satisfying-a-condition/m-p/299564#M90259</link>
      <description>&lt;P&gt;I have a event created each time a user does an action in my system (e.g. login, open_page, close_page).&lt;BR /&gt;
I need to do statistics based on the user regularity: a regular user logins more than 5 times or more over a period, the others are occasional.&lt;/P&gt;

&lt;P&gt;I use the query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... event=login| stats count by user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which returns the following :&lt;BR /&gt;
User A: 10&lt;BR /&gt;
User B: 7&lt;BR /&gt;
User C: 3&lt;BR /&gt;
User &lt;span class="lia-unicode-emoji" title=":anguished_face:"&gt;😧&lt;/span&gt; 5&lt;/P&gt;

&lt;P&gt;I am trying to obtain the following:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Number of regular users (login &amp;gt;=5 times)&lt;/LI&gt;
&lt;LI&gt;Number of open_page events done by regular users&lt;/LI&gt;
&lt;LI&gt;Proportion of close_page per user type (regular vs occasional)&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Thanks for the help!!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:35:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-items-satisfying-a-condition/m-p/299564#M90259</guid>
      <dc:creator>feridamana</dc:creator>
      <dc:date>2020-09-29T17:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Count items satisfying a condition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-items-satisfying-a-condition/m-p/299565#M90260</link>
      <description>&lt;P&gt;How about this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... event="login" OR event="open_page" OR event="close_page"
| stats count(eval(event="login")) AS login_count 
  count(eval(event="open_page")) AS open_page_count 
  count(eval(event="close_page")) AS close_page_count BY user 
| eval user_type=if(login_count&amp;gt;=5, "regular", "occasional")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That should give you a table with the necessary stats and categorizations to calculate all three!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2018 18:21:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-items-satisfying-a-condition/m-p/299565#M90260</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-01-09T18:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count items satisfying a condition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-items-satisfying-a-condition/m-p/299566#M90261</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Number of regular users (login &amp;gt;=5 times)&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... event=login| stats count by user | where count&amp;gt;=5 | stats count as "Number of regular users"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Number of open_page events done by regular users&lt;/STRONG&gt;&lt;BR /&gt;
To list regular users with corresponding open_page events&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... event=login OR event=open_page | chart count by user event | where login&amp;gt;=5 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To list total count of oepn_page events by regular users&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... event=login OR event=open_page | chart count by user event | where login&amp;gt;=5 | stats sum(open_page) as "Total open_page events by regular users"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Proportion of close_page per user type (regular vs occasional)&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... event=login OR event=close_page | chart count by user event | eval user_type=if(count&amp;gt;=5, "regular", "occasional") | eval temp=1 | chart sum(close_page) over temp by user_type | eval "Close_page Ratio(regular/occational)"=regular/occasional
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jan 2018 19:19:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-items-satisfying-a-condition/m-p/299566#M90261</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-01-09T19:19:23Z</dc:date>
    </item>
  </channel>
</rss>

