<?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: Splunk HELP - How to stats based on each value in array field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-HELP-How-to-stats-based-on-each-value-in-array-field/m-p/496664#M194696</link>
    <description>&lt;P&gt;The &lt;CODE&gt;stats&lt;/CODE&gt; command is &lt;CODE&gt;multi-value&lt;/CODE&gt; friendly as-is so just do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count BY ktf2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, assuming that the arrays are exactly as you posted and not already &lt;CODE&gt;multi-valued&lt;/CODE&gt; fields, you can do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval ktf2="[Background_Criteria,Profile_Criteria] [Background_Criteria,Profile_Criteria,keyword] [Rating_Criteria]"
| makemv ktf2
| mvexpand ktf2

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| rex field=ktf2 mode=sed "s/[\[\]]//g"
| eval ktf2=split(ktf2, ",")
| stats count BY ktf2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 Dec 2019 07:10:45 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-12-04T07:10:45Z</dc:date>
    <item>
      <title>Splunk HELP - How to stats based on each value in array field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-HELP-How-to-stats-based-on-each-value-in-array-field/m-p/496663#M194695</link>
      <description>&lt;P&gt;Hi Team, &lt;/P&gt;

&lt;P&gt;I have several fields which values are array. For example,&lt;/P&gt;

&lt;P&gt;event1:  ktf2="[Background_Criteria,Profile_Criteria]"&lt;BR /&gt;
event2:  ktf2="[Background_Criteria,Profile_Criteria, keyword]"&lt;BR /&gt;
event3: ktf2="[Rating_Criteria]"&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Question: How to stats based on the each element of ktf2 value??&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;My Expected Stats Result is:&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Criteria, Count&lt;/STRONG&gt;&lt;BR /&gt;
Background_Criteria, 2&lt;BR /&gt;
Profile_Criteria, 2&lt;BR /&gt;
keyword, 1&lt;BR /&gt;
Rating_Criteria, 1&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:11:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-HELP-How-to-stats-based-on-each-value-in-array-field/m-p/496663#M194695</guid>
      <dc:creator>cheriemilk</dc:creator>
      <dc:date>2020-09-30T03:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk HELP - How to stats based on each value in array field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-HELP-How-to-stats-based-on-each-value-in-array-field/m-p/496664#M194696</link>
      <description>&lt;P&gt;The &lt;CODE&gt;stats&lt;/CODE&gt; command is &lt;CODE&gt;multi-value&lt;/CODE&gt; friendly as-is so just do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count BY ktf2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, assuming that the arrays are exactly as you posted and not already &lt;CODE&gt;multi-valued&lt;/CODE&gt; fields, you can do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval ktf2="[Background_Criteria,Profile_Criteria] [Background_Criteria,Profile_Criteria,keyword] [Rating_Criteria]"
| makemv ktf2
| mvexpand ktf2

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| rex field=ktf2 mode=sed "s/[\[\]]//g"
| eval ktf2=split(ktf2, ",")
| stats count BY ktf2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 07:10:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-HELP-How-to-stats-based-on-each-value-in-array-field/m-p/496664#M194696</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-04T07:10:45Z</dc:date>
    </item>
  </channel>
</rss>

