<?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 How to compute duration for different rows in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-duration-for-different-rows/m-p/507386#M86341</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to compute the duration between two rows. I need the duration for Battery_duration&amp;nbsp; and Battery_duration2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NodeBTime = Alarm ID 22214 Occurtime&lt;/P&gt;&lt;P&gt;PowerTime = Alarm ID 25622 Occurtime&lt;/P&gt;&lt;P&gt;CellTime = Alarm ID 29245Occurtime&lt;/P&gt;&lt;P&gt;Battery_duration = NodeBTime - PowerTime&lt;/P&gt;&lt;P&gt;Battery_duration2 = CellTime - NodeBTime&amp;nbsp;&lt;/P&gt;&lt;TABLE width="886px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="69px"&gt;AlarmID&lt;/TD&gt;&lt;TD width="93px"&gt;Occurtime&lt;/TD&gt;&lt;TD width="93px"&gt;ClearTime&lt;/TD&gt;&lt;TD width="72px"&gt;duration&lt;/TD&gt;&lt;TD width="95px"&gt;NodeBTime&lt;/TD&gt;&lt;TD width="93px"&gt;CellTime&lt;/TD&gt;&lt;TD width="93px"&gt;PowerTime&lt;/TD&gt;&lt;TD width="134px"&gt;Battery_duration&lt;/TD&gt;&lt;TD width="144px"&gt;Battery_duration2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="69px" height="20"&gt;29245&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 14:09&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 14:13&lt;/TD&gt;&lt;TD width="72px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="95px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 14:09&lt;/TD&gt;&lt;TD width="93px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="134px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="144px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="69px" height="20"&gt;25622&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 9:01&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 14:11&lt;/TD&gt;&lt;TD width="72px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="95px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="93px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 9:01&lt;/TD&gt;&lt;TD width="134px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="144px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="69px" height="20"&gt;22214&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 13:59&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 14:11&lt;/TD&gt;&lt;TD width="72px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="95px"&gt;3/07/2020 13:59&lt;/TD&gt;&lt;TD width="93px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="93px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="134px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="144px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my query:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;|fillnull ClearTime&lt;BR /&gt;|eval ClearTime=if(ClearTime=0,strftime(now(),"%Y-%m-%d %H:%M:%S"),ClearTime)&lt;BR /&gt;|eval dur_sec=strptime(ClearTime,"%Y-%m-%d %H:%M:%S.%N")-strptime(Occurtime,"%Y-%m-%d %H:%M:%S.%N")&lt;BR /&gt;|eval dur_sec=round((strptime(ClearTime,"%Y-%m-%d %H:%M:%S.%N")-strptime(Occurtime,"%Y-%m-%d %H:%M:%S.%N")))&lt;BR /&gt;|eval duration=tostring(dur_sec,"duration")&lt;BR /&gt;|convert num(duration)&lt;BR /&gt;|eval duration=round(duration/60,2)&lt;/P&gt;&lt;P&gt;| eval PowerTime=if((AlarmID="25622"),Occurtime,null)&lt;BR /&gt;| eval NodeBTime=if((AlarmID="22214"),Occurtime,null)&lt;BR /&gt;| eval CellTime=if((AlarmID="29245"),Occurtime,null)&lt;BR /&gt;| eval Battery_duration=strptime(NodeBTime,"%Y-%m-%d %H:%M:%S.%N")-strptime(PowerTime,"%Y-%m-%d %H:%M:%S.%N")&lt;BR /&gt;| eval Battery_duration=round((strptime(NodeBTime,"%Y-%m-%d %H:%M:%S.%N")-strptime(PowerTime,"%Y-%m-%d %H:%M:%S.%N")))&lt;BR /&gt;| table AlarmID Occurtime ClearTime duration NodeBTime, CellTime PowerTime Battery_duration Battery_duration2 State&lt;/P&gt;&lt;P&gt;Here is my result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="duration1111.PNG" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/9472iF5855D802595C4D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="duration1111.PNG" alt="duration1111.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It doesnt give me any result for Battery_duration and Battery_duration2.&lt;/P&gt;&lt;P&gt;What is missing?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
    <pubDate>Sun, 05 Jul 2020 03:28:14 GMT</pubDate>
    <dc:creator>Noob_splunker</dc:creator>
    <dc:date>2020-07-05T03:28:14Z</dc:date>
    <item>
      <title>How to compute duration for different rows</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-duration-for-different-rows/m-p/507386#M86341</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to compute the duration between two rows. I need the duration for Battery_duration&amp;nbsp; and Battery_duration2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NodeBTime = Alarm ID 22214 Occurtime&lt;/P&gt;&lt;P&gt;PowerTime = Alarm ID 25622 Occurtime&lt;/P&gt;&lt;P&gt;CellTime = Alarm ID 29245Occurtime&lt;/P&gt;&lt;P&gt;Battery_duration = NodeBTime - PowerTime&lt;/P&gt;&lt;P&gt;Battery_duration2 = CellTime - NodeBTime&amp;nbsp;&lt;/P&gt;&lt;TABLE width="886px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="69px"&gt;AlarmID&lt;/TD&gt;&lt;TD width="93px"&gt;Occurtime&lt;/TD&gt;&lt;TD width="93px"&gt;ClearTime&lt;/TD&gt;&lt;TD width="72px"&gt;duration&lt;/TD&gt;&lt;TD width="95px"&gt;NodeBTime&lt;/TD&gt;&lt;TD width="93px"&gt;CellTime&lt;/TD&gt;&lt;TD width="93px"&gt;PowerTime&lt;/TD&gt;&lt;TD width="134px"&gt;Battery_duration&lt;/TD&gt;&lt;TD width="144px"&gt;Battery_duration2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="69px" height="20"&gt;29245&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 14:09&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 14:13&lt;/TD&gt;&lt;TD width="72px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="95px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 14:09&lt;/TD&gt;&lt;TD width="93px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="134px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="144px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="69px" height="20"&gt;25622&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 9:01&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 14:11&lt;/TD&gt;&lt;TD width="72px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="95px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="93px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 9:01&lt;/TD&gt;&lt;TD width="134px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="144px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="69px" height="20"&gt;22214&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 13:59&lt;/TD&gt;&lt;TD width="93px"&gt;3/07/2020 14:11&lt;/TD&gt;&lt;TD width="72px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="95px"&gt;3/07/2020 13:59&lt;/TD&gt;&lt;TD width="93px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="93px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="134px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="144px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my query:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;|fillnull ClearTime&lt;BR /&gt;|eval ClearTime=if(ClearTime=0,strftime(now(),"%Y-%m-%d %H:%M:%S"),ClearTime)&lt;BR /&gt;|eval dur_sec=strptime(ClearTime,"%Y-%m-%d %H:%M:%S.%N")-strptime(Occurtime,"%Y-%m-%d %H:%M:%S.%N")&lt;BR /&gt;|eval dur_sec=round((strptime(ClearTime,"%Y-%m-%d %H:%M:%S.%N")-strptime(Occurtime,"%Y-%m-%d %H:%M:%S.%N")))&lt;BR /&gt;|eval duration=tostring(dur_sec,"duration")&lt;BR /&gt;|convert num(duration)&lt;BR /&gt;|eval duration=round(duration/60,2)&lt;/P&gt;&lt;P&gt;| eval PowerTime=if((AlarmID="25622"),Occurtime,null)&lt;BR /&gt;| eval NodeBTime=if((AlarmID="22214"),Occurtime,null)&lt;BR /&gt;| eval CellTime=if((AlarmID="29245"),Occurtime,null)&lt;BR /&gt;| eval Battery_duration=strptime(NodeBTime,"%Y-%m-%d %H:%M:%S.%N")-strptime(PowerTime,"%Y-%m-%d %H:%M:%S.%N")&lt;BR /&gt;| eval Battery_duration=round((strptime(NodeBTime,"%Y-%m-%d %H:%M:%S.%N")-strptime(PowerTime,"%Y-%m-%d %H:%M:%S.%N")))&lt;BR /&gt;| table AlarmID Occurtime ClearTime duration NodeBTime, CellTime PowerTime Battery_duration Battery_duration2 State&lt;/P&gt;&lt;P&gt;Here is my result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="duration1111.PNG" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/9472iF5855D802595C4D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="duration1111.PNG" alt="duration1111.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It doesnt give me any result for Battery_duration and Battery_duration2.&lt;/P&gt;&lt;P&gt;What is missing?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 03:28:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-duration-for-different-rows/m-p/507386#M86341</guid>
      <dc:creator>Noob_splunker</dc:creator>
      <dc:date>2020-07-05T03:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute duration for different rows</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-duration-for-different-rows/m-p/507387#M86342</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223048"&gt;@Noob_splunker&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;That's because the values are in different events as you can see in the table.&lt;/P&gt;&lt;P&gt;Are there only these three events always? If not , is there an identifier which could co-relate these events?&lt;/P&gt;&lt;P&gt;For the existing data example, try below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;your search
| eval PowerTime=if((AlarmID="25622"),Occurtime,null)
| eval NodeBTime=if((AlarmID="22214"),Occurtime,null)
| eval CellTime=if((AlarmID="29245"),Occurtime,null)
| eventstats values(PowerTime) as PowerTime,values(NodeBTime) as NodeBTime,values(CellTime) as CellTime
| " rest of your substraction calculations"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have multiple events and an common identifier to co-relate the events, you can add &lt;EM&gt;&lt;STRONG&gt;by that_identifier &lt;/STRONG&gt;&lt;/EM&gt;in the eventstats&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 06:45:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-duration-for-different-rows/m-p/507387#M86342</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2020-07-05T06:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute duration for different rows</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-duration-for-different-rows/m-p/507390#M86343</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="AlarmID,Occurtime,ClearTime,duration,NodeBTime,CellTime,PowerTime,Battery_duration,Battery_duration2
29245,3/07/2020 14:09,3/07/2020 14:13,,,3/07/2020 14:09,, 
25622,3/07/2020 9:01,3/07/2020 14:11,,,,3/07/2020 9:01,,
22214,3/07/2020 13:59,3/07/2020 14:11,,3/07/2020 13:59,,"
| multikv forceheader=1
| table AlarmID,Occurtime,ClearTime,duration,NodeBTime,CellTime,PowerTime,Battery_duration,Battery_duration2

| eventstats max(eval(strptime(NodeBTime,"%d/%m/%Y %H:%M"))) as Battery_duration1_fm ,max(eval(strptime(PowerTime,"%d/%m/%Y %H:%M"))) as Battery_duration1_to
| eventstats max(eval(strptime(CellTime,"%d/%m/%Y %H:%M"))) as Battery_duration2_fm ,max(eval(strptime(NodeBTime,"%d/%m/%Y %H:%M"))) as Battery_duration2_to
| eval Battery_duration=if(isstr(PowerTime),tostring(round(Battery_duration1_fm - Battery_duration1_to),"duration"),NULL)
| eval Battery_duration2=if(isstr(CellTime),tostring(round(Battery_duration2_fm - Battery_duration2_to),"duration"),NULL)
| fields - *_fm *_to&lt;/LI-CODE&gt;&lt;P&gt;Query's result and table does not look same.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 08:29:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-duration-for-different-rows/m-p/507390#M86343</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-07-05T08:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute duration for different rows</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-duration-for-different-rows/m-p/507432#M86349</link>
      <description>&lt;P&gt;thanks for giving me an idea. i'll try to apply it in my query.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 22:42:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-compute-duration-for-different-rows/m-p/507432#M86349</guid>
      <dc:creator>Noob_splunker</dc:creator>
      <dc:date>2020-07-05T22:42:15Z</dc:date>
    </item>
  </channel>
</rss>

