<?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 Delta Conditional Statement? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422674#M121365</link>
    <description>&lt;P&gt;Good Morning Everyone, &lt;/P&gt;

&lt;P&gt;Is it possible to use delta with a conditional statement? &lt;/P&gt;

&lt;P&gt;As in: &lt;STRONG&gt;Only&lt;/STRONG&gt; give me the &lt;STRONG&gt;delta&lt;/STRONG&gt; p=1 &lt;STRONG&gt;if&lt;/STRONG&gt; field1=xyz&lt;/P&gt;

&lt;P&gt;Thank you in advance &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;This is how the data currently looks.&lt;/EM&gt;&lt;/STRONG&gt; &lt;BR /&gt;
I only want the delta between the very first event with a new status and the event that immediately follows it. The result can be output to a new field. &lt;/P&gt;

&lt;P&gt;So in essence: If the status is new then I want the delta between that event and the event immediately after it (# 1 &amp;amp; 2 in the example) &lt;/P&gt;

&lt;P&gt;Difference.......Difference Duration.........First Createdby Date.........First Modifiedby Date...........Status&lt;BR /&gt;
0.000...................00:00:00.000.....................1554766782.......................1554766782...................New&lt;BR /&gt;
&lt;STRONG&gt;66383.000...........18:26:23.000.....................1554766782.......................1554833165..................*(null)&lt;/STRONG&gt;*&lt;BR /&gt;
67674.000...........18:47:54.000.....................1554766782.......................1554834456...................&lt;EM&gt;(null)&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;I only want the delta between the very first event with a new status and the event that immediately follows it. The result can be output to a new field. &lt;/P&gt;

&lt;P&gt;So in essence: If the status is new then I want the delta between that event and the event immediately after it (# 1 &amp;amp; 2 in the example)  &lt;/P&gt;</description>
    <pubDate>Tue, 23 Apr 2019 17:31:54 GMT</pubDate>
    <dc:creator>ryhluc01</dc:creator>
    <dc:date>2019-04-23T17:31:54Z</dc:date>
    <item>
      <title>Delta Conditional Statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422674#M121365</link>
      <description>&lt;P&gt;Good Morning Everyone, &lt;/P&gt;

&lt;P&gt;Is it possible to use delta with a conditional statement? &lt;/P&gt;

&lt;P&gt;As in: &lt;STRONG&gt;Only&lt;/STRONG&gt; give me the &lt;STRONG&gt;delta&lt;/STRONG&gt; p=1 &lt;STRONG&gt;if&lt;/STRONG&gt; field1=xyz&lt;/P&gt;

&lt;P&gt;Thank you in advance &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;This is how the data currently looks.&lt;/EM&gt;&lt;/STRONG&gt; &lt;BR /&gt;
I only want the delta between the very first event with a new status and the event that immediately follows it. The result can be output to a new field. &lt;/P&gt;

&lt;P&gt;So in essence: If the status is new then I want the delta between that event and the event immediately after it (# 1 &amp;amp; 2 in the example) &lt;/P&gt;

&lt;P&gt;Difference.......Difference Duration.........First Createdby Date.........First Modifiedby Date...........Status&lt;BR /&gt;
0.000...................00:00:00.000.....................1554766782.......................1554766782...................New&lt;BR /&gt;
&lt;STRONG&gt;66383.000...........18:26:23.000.....................1554766782.......................1554833165..................*(null)&lt;/STRONG&gt;*&lt;BR /&gt;
67674.000...........18:47:54.000.....................1554766782.......................1554834456...................&lt;EM&gt;(null)&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;I only want the delta between the very first event with a new status and the event that immediately follows it. The result can be output to a new field. &lt;/P&gt;

&lt;P&gt;So in essence: If the status is new then I want the delta between that event and the event immediately after it (# 1 &amp;amp; 2 in the example)  &lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 17:31:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422674#M121365</guid>
      <dc:creator>ryhluc01</dc:creator>
      <dc:date>2019-04-23T17:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Conditional Statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422675#M121366</link>
      <description>&lt;P&gt;Could you provide little more details with some sample data and corresponding expected output?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 17:41:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422675#M121366</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-04-23T17:41:52Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Conditional Statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422676#M121367</link>
      <description>&lt;P&gt;@somesoni2 Sure. &lt;/P&gt;

&lt;P&gt;This is how the data currently looks. &lt;BR /&gt;
What I am asking is to only calculate the delta for the events directly after the event with the new status (bolded event). &lt;BR /&gt;
So basically, I want the first modified event directly after the event was first created. &lt;/P&gt;

&lt;P&gt;Difference.......Difference Duration.........First Createdby Date.........First Modifiedby Date...........Status&lt;BR /&gt;
0.000...................00:00:00.000.....................1554766782.......................1554766782...................New&lt;BR /&gt;
&lt;STRONG&gt;66383.000...........18:26:23.000.....................1554766782.......................1554833165..................*(null)&lt;/STRONG&gt;*&lt;BR /&gt;
67674.000...........18:47:54.000.....................1554766782.......................1554834456...................&lt;EM&gt;(null)&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 18:12:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422676#M121367</guid>
      <dc:creator>ryhluc01</dc:creator>
      <dc:date>2019-04-23T18:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Conditional Statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422677#M121368</link>
      <description>&lt;P&gt;So what should be the output (new field??) with difference between 2nd and 3rd event only?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 18:35:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422677#M121368</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-04-23T18:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Conditional Statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422678#M121369</link>
      <description>&lt;P&gt;@somesoni2 Apologies, I just re-read my response to you and I can see that I worded that incorrectly : ) &lt;/P&gt;

&lt;P&gt;I only want the delta between the very first event with a new status and the event that immediately follows it. The result can be output to a new field. &lt;/P&gt;

&lt;P&gt;So in essence: If the status is new then I want the delta between that event and the event immediately after it (# 1 &amp;amp; 2 in the example)  &lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 18:51:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422678#M121369</guid>
      <dc:creator>ryhluc01</dc:creator>
      <dc:date>2019-04-23T18:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Conditional Statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422679#M121370</link>
      <description>&lt;P&gt;Hi  @ryhluc01,&lt;/P&gt;

&lt;P&gt;You can compare the previous event with the current event using a combination of &lt;CODE&gt;streamstats current=f&lt;/CODE&gt; and  last()&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval raw="Difference=0.000, DifferenceDuration=00:00:00.000,FirstCreatedByDate=1554766782,FirstModifiedByDate=1554766782,Status=New ###
Difference=66383.000, DifferenceDuration=18:26:23.000,FirstCreatedByDate=1554766782,FirstModifiedByDate=1554833165, Status= ###
Difference=67674.000, DifferenceDuration=18:47:54.000,FirstCreatedByDate=1554766782,FirstModifiedByDate=1554834456, Status="
 | makemv delim="###" raw
| mvexpand raw 
| rename raw  as  _raw 
| extract

| eval Comment = "----- This will create a delta field if the previous Status field was 'New' ----"
| fillnull value="blank" Status
| streamstats current=false last(Status) as PrevStatus
| eval Delta=if(PrevStatus=="New" AND Status=="blank",DifferenceDuration,null)
| eval Status=if(Status=="blank",null,Status)
| fields - PrevStatus - Comment
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The start of this search just generates your dummy data. The second part works like this:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Fill all the blank status fields with a value ("blank") This will get undone later&lt;/LI&gt;
&lt;LI&gt;Use streamstats to get the previous Status value, and put it in the current event&lt;/LI&gt;
&lt;LI&gt;Create a delta field, and set it to the duration only if the previous status was 'New'&lt;/LI&gt;
&lt;LI&gt;Clean up - remove the 'blank' values and delete the PrevStatus and Comment fields.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Does that do what you were looking for? &lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 02:20:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422679#M121370</guid>
      <dc:creator>spavin</dc:creator>
      <dc:date>2019-04-24T02:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Conditional Statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422680#M121371</link>
      <description>&lt;P&gt;As other people have said, you can recreate the function of &lt;CODE&gt;delta&lt;/CODE&gt; by using &lt;CODE&gt;streamstats&lt;/CODE&gt; in many ways which gives you the benefit of many other logical controls.  You might try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval raw="Difference=0.000,Difference_Duration=00:00:00.000,First_Createdby_Date=1554766782,First_Modifiedby_Date=1554766782,Status=New Difference=66383.000,Difference_Duration=18:26:23.000,First_Createdby_Date=1554766782,First_Modifiedby_Date=1554833165 Difference=67674.000,Difference_Duration=18:47:54.000,First_Createdby_Date=1554766782,First_Modifiedby_Date=1554834456"
| makemv raw
| mvexpand raw
| rename raw AS _raw
| kv
| eval _time = First_Modifiedby_Date, host="foo"
| sort 0 - _time

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| streamstats count(eval(Status="New")) AS SessionID BY host
| dedup 2 host SessionID
| stats range(First_Modifiedby_Date) AS p BY host
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 Apr 2019 04:59:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422680#M121371</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-04-28T04:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Conditional Statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422681#M121372</link>
      <description>&lt;P&gt;Wow thank you! I'll have to give this a try this week &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 13:44:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422681#M121372</guid>
      <dc:creator>ryhluc01</dc:creator>
      <dc:date>2019-04-30T13:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Delta Conditional Statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422682#M121373</link>
      <description>&lt;P&gt;Thanks! You guys are so helpful! I am going to try these out this week &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 13:45:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Delta-Conditional-Statement/m-p/422682#M121373</guid>
      <dc:creator>ryhluc01</dc:creator>
      <dc:date>2019-04-30T13:45:27Z</dc:date>
    </item>
  </channel>
</rss>

