<?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 Finding the Values from multiple event with a single key in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395983#M114958</link>
    <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;

&lt;P&gt;Through inputcsv and outputcsv, i finally able to consolidate the data in a single CSV. Now I need to create another CSV with the events with a single key. My inputcsv has data in the following format:-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Ticket  |   Main_Ticket |  TYPE  | STATUS  |   END_DATE
  A2345A    | A2345A   |     MAIN    |   IN Work  | 2018-09-12
  A2345A001  | A2345A     |   SUB    |   Closed   | 2018-07-03
  Z2995A    | A2345A     |   PEER   |   Closed   |  2018-07-23
  A2345A002 |  A2345A   |    SUB    |   In Work   |2018-08-12
  B4321A    | B4321A   |     MAIN    |   IN Work  | 2018-09-12
  B4321A001  | B4321A     |   SUB    |   Closed   | 2018-07-11
  Z3495A    | B4321A     |   PEER   |   Closed   |  2018-07-19
  B4321A002 |  B4321A   |    SUB    |   In Work   |2018-08-15
  C9854A    | C9854A   |     MAIN    |   Closed  | 2018-07-12
  C9854A001  | C9854A     |   SUB    |   Closed   | 2018-06-15
  Z8749A    | C9854A     |   PEER   |  Closed   |  2018-06-23
  C9854A002 |  C9854A   |    SUB    |   Closed   |2018-06-29
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I need to find the first "In Work"SUB or PEER ticket for each Main_Ticekt. The result may look like the following. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Main_Ticket | PEER_SUB_IN_Work | PEER_SUB_TN |  PEER_SUB_ENDDATE
A2345A  | SUB  | A2345A002 | 2018-08-12
B4321A | PEER | Z3495A | 018-08-12
C9854A | Closed | Closed |  2018-07-12
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So I am trying to get something like for each loop with the key filed "Main_Ticket" , find last IN Work SUB/PEER ticket and END_Date of that SUB/PEER TIcket. If all SUB/PEER tickets are CLOSED, It should return the MAIN Ticket Type value.  Once I have the values, I can easily save it to outputcsv. &lt;/P&gt;

&lt;P&gt;As of now, I am downloading the CSVs and doing it with VB. Is it possible with Splunk? &lt;/P&gt;

&lt;P&gt;Thanks for your help and I apologize for such a long post. &lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 20:49:14 GMT</pubDate>
    <dc:creator>Chandras11</dc:creator>
    <dc:date>2020-09-29T20:49:14Z</dc:date>
    <item>
      <title>Finding the Values from multiple event with a single key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395983#M114958</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;

&lt;P&gt;Through inputcsv and outputcsv, i finally able to consolidate the data in a single CSV. Now I need to create another CSV with the events with a single key. My inputcsv has data in the following format:-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Ticket  |   Main_Ticket |  TYPE  | STATUS  |   END_DATE
  A2345A    | A2345A   |     MAIN    |   IN Work  | 2018-09-12
  A2345A001  | A2345A     |   SUB    |   Closed   | 2018-07-03
  Z2995A    | A2345A     |   PEER   |   Closed   |  2018-07-23
  A2345A002 |  A2345A   |    SUB    |   In Work   |2018-08-12
  B4321A    | B4321A   |     MAIN    |   IN Work  | 2018-09-12
  B4321A001  | B4321A     |   SUB    |   Closed   | 2018-07-11
  Z3495A    | B4321A     |   PEER   |   Closed   |  2018-07-19
  B4321A002 |  B4321A   |    SUB    |   In Work   |2018-08-15
  C9854A    | C9854A   |     MAIN    |   Closed  | 2018-07-12
  C9854A001  | C9854A     |   SUB    |   Closed   | 2018-06-15
  Z8749A    | C9854A     |   PEER   |  Closed   |  2018-06-23
  C9854A002 |  C9854A   |    SUB    |   Closed   |2018-06-29
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I need to find the first "In Work"SUB or PEER ticket for each Main_Ticekt. The result may look like the following. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Main_Ticket | PEER_SUB_IN_Work | PEER_SUB_TN |  PEER_SUB_ENDDATE
A2345A  | SUB  | A2345A002 | 2018-08-12
B4321A | PEER | Z3495A | 018-08-12
C9854A | Closed | Closed |  2018-07-12
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So I am trying to get something like for each loop with the key filed "Main_Ticket" , find last IN Work SUB/PEER ticket and END_Date of that SUB/PEER TIcket. If all SUB/PEER tickets are CLOSED, It should return the MAIN Ticket Type value.  Once I have the values, I can easily save it to outputcsv. &lt;/P&gt;

&lt;P&gt;As of now, I am downloading the CSVs and doing it with VB. Is it possible with Splunk? &lt;/P&gt;

&lt;P&gt;Thanks for your help and I apologize for such a long post. &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:49:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395983#M114958</guid>
      <dc:creator>Chandras11</dc:creator>
      <dc:date>2020-09-29T20:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Values from multiple event with a single key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395984#M114959</link>
      <description>&lt;P&gt;not sure if I understand correctly..&lt;BR /&gt;
for main ticket &lt;CODE&gt;B4321A&lt;/CODE&gt; in result it should be &lt;CODE&gt;B4321A002&lt;/CODE&gt;  in &lt;CODE&gt;PEER_SUB_IN_Work&lt;/CODE&gt;  if you wanted  last IN Work SUB/PEER ticket ..is it correct?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 15:46:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395984#M114959</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-08-08T15:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Values from multiple event with a single key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395985#M114960</link>
      <description>&lt;P&gt;Yes... Thats true.... The Last "In work" ticket. Because that will be the actual ticket phase for each main ticket.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 16:25:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395985#M114960</guid>
      <dc:creator>Chandras11</dc:creator>
      <dc:date>2018-08-08T16:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Values from multiple event with a single key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395986#M114961</link>
      <description>&lt;P&gt;Well, that's a good idea... I can remove all closed ticket if the Main ticket is closed. Afterward, there is no need to check for example C9854A here. Just need to check the Main_TIckets in status "IN Work" and then find the last "IN Work" SUB or PEER Ticket.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 16:28:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395986#M114961</guid>
      <dc:creator>Chandras11</dc:creator>
      <dc:date>2018-08-08T16:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Values from multiple event with a single key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395987#M114962</link>
      <description>&lt;P&gt;yes&lt;BR /&gt;
so you can try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|where STATUS!="Closed"|stats last(Main_Ticket) as Main,last(Ticket) as Ticket , last(TYPE) as TYPE ,last(END_DATE) as END_DATE  by Main_Ticket
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|where STATUS="In Work"|stats last(Main_Ticket) as Main,last(Ticket) as Ticket , last(TYPE) as TYPE ,last(END_DATE) as END_DATE  by Main_Ticket
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Aug 2018 17:01:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395987#M114962</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-08-08T17:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Values from multiple event with a single key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395988#M114963</link>
      <description>&lt;P&gt;Thanks for the answer. It worked. However, I have a very small doubt here. In the stats - by can we also sort the events based on the end date. For example, it should automatically sort based on PEER/SUB Ticket End Date and then take the Last value from there. &lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 07:35:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395988#M114963</guid>
      <dc:creator>Chandras11</dc:creator>
      <dc:date>2018-08-09T07:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Values from multiple event with a single key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395989#M114964</link>
      <description>&lt;P&gt;@Chandras11 - Here's run-anywhere code for your sample data with one potential solution...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval mydata="A2345A,A2345A,MAIN,IN Work,2018-09-12!!!!A2345A001,A2345A,SUB,Closed,2018-07-03!!!!Z2995A,A2345A,PEER,Closed,2018-07-23!!!!A2345A002,A2345A,SUB,In Work,2018-08-12!!!!B4321A,B4321A,MAIN,IN Work,2018-09-12!!!!B4321A001,B4321A,SUB,Closed,2018-07-11!!!!Z3495A,B4321A,PEER,Closed,2018-07-19!!!!B4321A002,B4321A,SUB,In Work,2018-08-15!!!!C9854A,C9854A,MAIN,Closed,2018-07-12!!!!C9854A001,C9854A,SUB,Closed,2018-06-15!!!!Z8749A,C9854A,PEER,Closed,2018-06-23!!!!C9854A002,C9854A,SUB,Closed,2018-06-29"
| makemv delim="!!!!" mydata
| mvexpand mydata
| makemv delim="," mydata
| eval Ticket=mvindex(mydata,0)
| eval Main_Ticket=mvindex(mydata,1)
| eval TYPE=mvindex(mydata,2)
| eval STATUS=mvindex(mydata,3)
| eval END_DATE=mvindex(mydata,4)
| table Ticket Main_Ticket TYPE STATUS END_DATE
| rename COMMENT as "The above just enters your test data"

| rename COMMENT as "Get rid of all closed sub-items, calculate the last sub date for open items"
| where TYPE="MAIN" OR STATUS != "Closed"
| eventstats max(eval(case(TYPE!="MAIN",END_DATE))) as MaxSubEnd by Main_Ticket

| rename COMMENT as "Allow closed main items, or non-closed non-main items that have the latest end date for their main ticket."
| where isnull(MaxSubEnd) OR (TYPE!="MAIN" AND MaxSubEnd=END_DATE) 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Aug 2018 06:36:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Values-from-multiple-event-with-a-single-key/m-p/395989#M114964</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-08-11T06:36:16Z</dc:date>
    </item>
  </channel>
</rss>

