<?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: Group multiple Keys and count the values by status and table the results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342184#M161320</link>
    <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Updated&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(CMD=LOOK OR CMD=BOOK) 
 | eval temp=CMD."##".STAT
 | fields temp ITEM*
 | untable temp Key Item
 | rex field=temp "(?&amp;lt;CMD&amp;gt;.+)##(?&amp;lt;STAT&amp;gt;.+)"
 | table CMD Item STAT | where (CMD="BOOK" AND STAT=1) OR (STAT&amp;gt;=1 AND CMD="LOOK") | chart count over Item by CMD
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Run anywhere sample (first 3 lines are to generate sample data)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1| eval temp="CMD=LOOK ITEM1=APPLE ITEM2=APPLE ITEM3=ORANGE STAT=0##CMD=LOOK ITEM1=APPLE ITEM2=ORANGE ITEM3=ORANGE STAT=2##CMD=BOOK ITEM=APPLE STAT=1##CMD=BOOK ITEM=ORANGE STAT=0" | table temp | makemv temp delim="##" | mvexpand temp | rename temp as _raw | extract 
| eval temp=CMD."##".STAT
 | fields temp ITEM*
 | untable temp Key Item
 | rex field=temp "(?&amp;lt;CMD&amp;gt;.+)##(?&amp;lt;STAT&amp;gt;.+)"
 | table CMD Item STAT | where (CMD="BOOK" AND STAT=1) OR (STAT&amp;gt;=1 AND CMD="LOOK") | chart count over Item by CMD
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 20 Apr 2017 16:27:03 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-04-20T16:27:03Z</dc:date>
    <item>
      <title>Group multiple Keys and count the values by status and table the results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342183#M161319</link>
      <description>&lt;P&gt;Good day,&lt;BR /&gt;
i have the follwing key values:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;CMD=LOOK ITEM1=APPLE ITEM2=APPLE ITEM3=ORANGE STAT=0
CMD=LOOK ITEM1=APPLE ITEM2=ORANGE ITEM3=ORANGE STAT=2
CMD=BOOK ITEM=APPLE STAT=1
CMD=BOOK ITEM=ORANGE STAT=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As a result i'm looking for a table like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Item   | Look | Book 
APPLE  | 1    | 1    
ORANGE | 2    | 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I was tying the following search but that doesn't get me anywhere&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(CMD=LOOK OR CMD=BOOK) |
eval ITEM=coalesce(ITEM1,ITEM2,ITEM3)  |
stats count(eval("STAT=1 AND CMD=BOOK")) as Book count(eval("STAT&amp;gt;=1 AND CMD=LOOK")) as Look by ITEM
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any help is appreciated, thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 16:06:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342183#M161319</guid>
      <dc:creator>mkrauss1</dc:creator>
      <dc:date>2017-04-20T16:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Group multiple Keys and count the values by status and table the results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342184#M161320</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Updated&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(CMD=LOOK OR CMD=BOOK) 
 | eval temp=CMD."##".STAT
 | fields temp ITEM*
 | untable temp Key Item
 | rex field=temp "(?&amp;lt;CMD&amp;gt;.+)##(?&amp;lt;STAT&amp;gt;.+)"
 | table CMD Item STAT | where (CMD="BOOK" AND STAT=1) OR (STAT&amp;gt;=1 AND CMD="LOOK") | chart count over Item by CMD
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Run anywhere sample (first 3 lines are to generate sample data)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1| eval temp="CMD=LOOK ITEM1=APPLE ITEM2=APPLE ITEM3=ORANGE STAT=0##CMD=LOOK ITEM1=APPLE ITEM2=ORANGE ITEM3=ORANGE STAT=2##CMD=BOOK ITEM=APPLE STAT=1##CMD=BOOK ITEM=ORANGE STAT=0" | table temp | makemv temp delim="##" | mvexpand temp | rename temp as _raw | extract 
| eval temp=CMD."##".STAT
 | fields temp ITEM*
 | untable temp Key Item
 | rex field=temp "(?&amp;lt;CMD&amp;gt;.+)##(?&amp;lt;STAT&amp;gt;.+)"
 | table CMD Item STAT | where (CMD="BOOK" AND STAT=1) OR (STAT&amp;gt;=1 AND CMD="LOOK") | chart count over Item by CMD
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Apr 2017 16:27:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342184#M161320</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-04-20T16:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Group multiple Keys and count the values by status and table the results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342185#M161321</link>
      <description>&lt;P&gt;@somesoni2, I think this is not exactly working.  Here's some test code to get the test data into the format I believe you are expecting...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval mydata="CMD=LOOK ITEM1=APPLE ITEM2=APPLE ITEM3=ORANGE STAT=0!!!!CMD=LOOK ITEM1=APPLE ITEM2=ORANGE ITEM3=ORANGE STAT=2!!!! CMD=BOOK ITEM=APPLE STAT=1!!!! CMD=BOOK ITEM=ORANGE STAT=0"
| makemv delim="!!!!" mydata 
| mvexpand mydata 
| streamstats count as recno
| eval _raw = mydata, _time=now() 
| table _time _raw recno
| rex field=_raw "CMD=(?&amp;lt;CMD&amp;gt;\w+)"
| rex field=_raw "STAT=(?&amp;lt;STAT&amp;gt;\d+)"
| rex field=_raw max_match=0 "(?&amp;lt;ItemList&amp;gt;ITEM[^=]*=\w+)"
| mvexpand ItemList
| rex field=ItemList max_match=0 "(?&amp;lt;ItemName&amp;gt;ITEM[^=]*)=(?&amp;lt;Item&amp;gt;\w+)"
| eval {ItemName}=Item
| table _time recno CMD STAT ITEM*
| stats values(*) as * by recno
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Apr 2017 16:56:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342185#M161321</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-04-20T16:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: Group multiple Keys and count the values by status and table the results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342186#M161322</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval raw="CMD=LOOK ITEM1=APPLE ITEM2=APPLE ITEM3=ORANGE STAT=0::CMD=LOOK ITEM1=APPLE ITEM2=ORANGE ITEM3=ORANGE STAT=2::CMD=BOOK ITEM=APPLE STAT=1::CMD=BOOK ITEM=ORANGE STAT=0"
| makemv delim="::" raw 
| mvexpand raw 
| rename raw AS _raw 
| fields - _time 
| rex "^CMD=(?&amp;lt;CMD&amp;gt;\S+)\s+ITEM=(?&amp;lt;ITEM&amp;gt;\S+)\s+STAT=(?&amp;lt;STAT&amp;gt;.*)"
| rex "^CMD=(?&amp;lt;CMD&amp;gt;\S+)\s+ITEM1=(?&amp;lt;ITEM1&amp;gt;\S+)\s+ITEM2=(?&amp;lt;ITEM2&amp;gt;\S+)\s+ITEM3=(?&amp;lt;ITEM3&amp;gt;\S+)\s+STAT=(?&amp;lt;STAT&amp;gt;.*)"

| rename COMMENT AS "Everything above fakes your events; everything below is your solution"

| search (STAT=1 AND CMD=BOOK) OR (STAT&amp;gt;=1 AND CMD=LOOK)
| table CMD ITEM ITEM1 ITEM2 ITEM3

| fillnull value=":"
| eval ITEMS=ITEM.":".ITEM1.":".ITEM2.":".ITEM3
| makemv delim=":" ITEMS
| chart count OVER ITEMS BY CMD
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Apr 2017 17:07:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342186#M161322</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-20T17:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: Group multiple Keys and count the values by status and table the results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342187#M161323</link>
      <description>&lt;P&gt;Thanks again @DalJeanis, I overlooked his value calculation logic. Fixed now.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 18:45:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342187#M161323</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-04-20T18:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: Group multiple Keys and count the values by status and table the results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342188#M161324</link>
      <description>&lt;P&gt;This is exactly doing what i'm looking for. Great, many thanks for this.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 08:02:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-multiple-Keys-and-count-the-values-by-status-and-table-the/m-p/342188#M161324</guid>
      <dc:creator>mkrauss1</dc:creator>
      <dc:date>2017-04-21T08:02:54Z</dc:date>
    </item>
  </channel>
</rss>

