<?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: How to get the count of a specific value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592568#M206250</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/240033"&gt;@apignata&lt;/a&gt;&amp;nbsp;- use the solution given by&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use &lt;STRONG&gt;single quotes&lt;/STRONG&gt; instead of double quotes when you want to specify column/field names. (except with rename command)&lt;/P&gt;&lt;P&gt;The bouble quote is for value/string.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Apr 2022 05:51:34 GMT</pubDate>
    <dc:creator>VatsalJagani</dc:creator>
    <dc:date>2022-04-06T05:51:34Z</dc:date>
    <item>
      <title>How to get the count of a specific value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592561#M206245</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="apignata_0-1649220874433.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/18955iF8DBD08E5E4F2CDF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="apignata_0-1649220874433.png" alt="apignata_0-1649220874433.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How would you return the count of only the Reachable devices?&lt;BR /&gt;In the picture above you would return 8.&lt;/P&gt;&lt;P&gt;When using the query below I receive a result of 0&lt;/P&gt;&lt;PRE&gt;| stats count("SWITCHES_AND_HUBS{}.reachability_status"=REACHABLE)&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2022 05:11:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592561#M206245</guid>
      <dc:creator>apignata</dc:creator>
      <dc:date>2022-04-06T05:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the count of a specific value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592562#M206246</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/240033"&gt;@apignata&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try eval in count function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;YOUR_SEARCH
| stats count(eval('SWITCHES_AND_HUBS{}.reachability_status'=="REACHABLE")) as Count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please refer below link for more.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/latest/Search/Usestatswithevalexpressionsandfunctions" target="_blank"&gt;https://docs.splunk.com/Documentation/SplunkCloud/latest/Search/Usestatswithevalexpressionsandfunctions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 05:39:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592562#M206246</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-04-06T05:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the count of a specific value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592568#M206250</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/240033"&gt;@apignata&lt;/a&gt;&amp;nbsp;- use the solution given by&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use &lt;STRONG&gt;single quotes&lt;/STRONG&gt; instead of double quotes when you want to specify column/field names. (except with rename command)&lt;/P&gt;&lt;P&gt;The bouble quote is for value/string.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 05:51:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592568#M206250</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2022-04-06T05:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the count of a specific value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592606#M206267</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/240033"&gt;@apignata&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I'd rename the field and use quotes in the eval:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rename "SWITCHES_AND_HUBS{}.reachability_status" AS reachability_status
| stats count(eval(reachability_status="REACHABLE")) AS reachable&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 08:19:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592606#M206267</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-04-06T08:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the count of a specific value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592776#M206337</link>
      <description>&lt;P&gt;Thanks for providing the info on eval.&lt;/P&gt;&lt;P&gt;When running the query I noticed the count is showing 413 instead of the expected 3,312.&lt;BR /&gt;Do you have any insight?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="apignata_1-1649281796189.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/18973i7080209011BEDB6C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="apignata_1-1649281796189.png" alt="apignata_1-1649281796189.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="apignata_2-1649281817312.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/18974i018703AB7EC2AE81/image-size/medium?v=v2&amp;amp;px=400" role="button" title="apignata_2-1649281817312.png" alt="apignata_2-1649281817312.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here is an example of the data:&lt;BR /&gt;- The data is in JSON format&lt;BR /&gt;- Example of one event below&lt;BR /&gt;- Run through a script to create multiple events in a day about the updated status&lt;/P&gt;&lt;P&gt;"SWITCHES_AND_HUBS": [&lt;BR /&gt;{&lt;BR /&gt;"name": "test1",&lt;BR /&gt;"reachability_status": "REACHABLE"&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"name": "test2",&lt;BR /&gt;"reachability_status": "UNREACHABLE"&lt;BR /&gt;},&lt;BR /&gt;&lt;BR /&gt;To get the info on the latest event, can I use below to filter the data? Or would stats latest/last be better?&lt;/P&gt;&lt;PRE&gt;| head 1 &lt;/PRE&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 22:00:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592776#M206337</guid>
      <dc:creator>apignata</dc:creator>
      <dc:date>2022-04-06T22:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the count of a specific value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592815#M206348</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/240033"&gt;@apignata&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats count(eval('SWITCHES_AND_HUBS{}.reachability_status'=="REACHABLE"))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above count command consider an event as one count if &amp;nbsp;eval condition get passed. As you have multivalued filed, means multiple&amp;nbsp;reachability_status values in single events, this command is showing you &lt;STRONG&gt;413&lt;/STRONG&gt; count from &lt;STRONG&gt;1239&lt;/STRONG&gt; events. &amp;nbsp;As you have 3312&amp;nbsp;&lt;STRONG&gt;REACHABLE &lt;/STRONG&gt;status then we should consider all values as separate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please try below search for your case?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;YOUR_SEARCH 
| stats count(eval('SWITCHES_AND_HUBS{}.reachability_status'=="REACHABLE")) as REACHABLE, count(eval('SWITCHES_AND_HUBS{}.reachability_status'=="UNREACHABLE")) as UNREACHABLE&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Sample Search :&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="{\"SWITCHES_AND_HUBS\": [{\"name\": \"test1\",\"reachability_status\": \"REACHABLE\"},{\"name\": \"test2\",\"reachability_status\": \"UNREACHABLE\"},{\"name\": \"test3\",\"reachability_status\": \"UNREACHABLE\"},{\"name\": \"test4\",\"reachability_status\": \"UNREACHABLE\"}]}" 
| kv
|mvexpand SWITCHES_AND_HUBS{}.reachability_status
| stats count(eval('SWITCHES_AND_HUBS{}.reachability_status'=="REACHABLE")) as REACHABLE, count(eval('SWITCHES_AND_HUBS{}.reachability_status'=="UNREACHABLE")) as UNREACHABLE&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 04:41:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592815#M206348</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-04-07T04:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the count of a specific value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592982#M206393</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;Thank you for the reply. The sample search helped me understand how I could use mvexpand to expand the values of SWITCHES_AND_HUBS{}.reachability_status field into separate events. Then use the count(eval() to get the result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 19:47:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-a-specific-value/m-p/592982#M206393</guid>
      <dc:creator>apignata</dc:creator>
      <dc:date>2022-04-07T19:47:19Z</dc:date>
    </item>
  </channel>
</rss>

