<?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 Append a column based on conditions in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Append-a-column-based-on-conditions/m-p/312867#M93650</link>
    <description>&lt;P&gt;I have a log file as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;** Time  Event_Type          Event_Name**
-------------------------------------------------------------
time1  Event              Event1
time2  Event              Event2
time3  Event              Event3
time4  DBError          SQLErrCode1
time5  DBError          SQLErrCode2
time6  Event              Event4
time7  Event              Event5
time8  DBError          SQLErrCode3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;....&lt;BR /&gt;
In the above logs, each DBError is caused by the Event just before that DBError&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Requirement is I need a result as below:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;time4  DBError  SQLErrCode1 Event3
time5  DBError  SQLErrCode2 Event3
time8  DBError  SQLErrCode3 Event5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Appreciate your help ...&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2017 17:46:32 GMT</pubDate>
    <dc:creator>rojit</dc:creator>
    <dc:date>2017-11-27T17:46:32Z</dc:date>
    <item>
      <title>Append a column based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Append-a-column-based-on-conditions/m-p/312867#M93650</link>
      <description>&lt;P&gt;I have a log file as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;** Time  Event_Type          Event_Name**
-------------------------------------------------------------
time1  Event              Event1
time2  Event              Event2
time3  Event              Event3
time4  DBError          SQLErrCode1
time5  DBError          SQLErrCode2
time6  Event              Event4
time7  Event              Event5
time8  DBError          SQLErrCode3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;....&lt;BR /&gt;
In the above logs, each DBError is caused by the Event just before that DBError&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Requirement is I need a result as below:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;time4  DBError  SQLErrCode1 Event3
time5  DBError  SQLErrCode2 Event3
time8  DBError  SQLErrCode3 Event5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Appreciate your help ...&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 17:46:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Append-a-column-based-on-conditions/m-p/312867#M93650</guid>
      <dc:creator>rojit</dc:creator>
      <dc:date>2017-11-27T17:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Append a column based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Append-a-column-based-on-conditions/m-p/312868#M93651</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search giving columns Time, Event_Type, Event_Name
| streamstats current=f window=1 values(Event_Name) as prev_EventName 
| where Event_Type="DBError" 
| filldown prev_EventName
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR (in case above doesn't work due to event ordering)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search giving columns Time, Event_Type, Event_Name
| reverse | streamstats current=f window=1 values(Event_Name) as prev_EventName 
| where Event_Type="DBError" 
| filldown prev_EventName
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Nov 2017 19:43:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Append-a-column-based-on-conditions/m-p/312868#M93651</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-11-27T19:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: Append a column based on conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Append-a-column-based-on-conditions/m-p/312869#M93652</link>
      <description>&lt;P&gt;Thanks for the response..&lt;BR /&gt;
Well, my question is partially answered here.&lt;/P&gt;

&lt;P&gt;From the above solutions, I am getting the results for time5 as&lt;BR /&gt;
time5  DBError  SQLErrCode2 SQLErrCode1 &lt;/P&gt;

&lt;P&gt;whereas I am expecting&lt;BR /&gt;
time5  DBError  SQLErrCode2 Event3&lt;/P&gt;

&lt;P&gt;For time4 and time8, its coming as expected&lt;BR /&gt;
(Edited the dataset lil bit for getting it more clear)&lt;/P&gt;

&lt;P&gt;I would like to know whether we can add conditions to streamstats?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 17:04:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Append-a-column-based-on-conditions/m-p/312869#M93652</guid>
      <dc:creator>rojit</dc:creator>
      <dc:date>2017-11-28T17:04:12Z</dc:date>
    </item>
  </channel>
</rss>

