<?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: Calculate the duration in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617517#M214600</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249836"&gt;@tomapatan&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;this is one of the few cases to use the thansaction command.&lt;/P&gt;&lt;P&gt;if the swipe_ is identiiable with "*IN*" and swipe_out with "*OUT*", please trysomething like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;your-search&amp;gt;
| transaction startswith=location_desc="*IN*" endswith=location_desc="*OUT*"
| table _time duration&lt;/LI-CODE&gt;&lt;P&gt;otherwise, please tell me how to identify swipe_in and swipe_out.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
    <pubDate>Tue, 18 Oct 2022 12:16:14 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2022-10-18T12:16:14Z</dc:date>
    <item>
      <title>How to calculate the duration?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617511#M214596</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I`ve got the following search that I would like to amend as follows:&lt;/P&gt;
&lt;P&gt;1. swipe_in and swipe_out times to show on the same row for each "transaction" (in and out being considered a transaction).&lt;/P&gt;
&lt;P&gt;2. only show the duration for swipe_in and swipe_out and not for swipe_out-swipe_in.&lt;/P&gt;
&lt;P&gt;Essentially my table should display: swipe_in times, swipe out times and duration.&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;Search details:&lt;/P&gt;
&lt;P&gt;| eval location_desc=if(match(location_desc,"OUT"), "swipe_out", "swipe_in")&lt;BR /&gt;| sort _time&lt;BR /&gt;| streamstats window=2 current=f first(_time) as previous_swipe&lt;BR /&gt;| eval duration=round((_time-previous_swipe)/3600, 2)&lt;BR /&gt;| table location_desc, _time, duration&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 14:23:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617511#M214596</guid>
      <dc:creator>tomapatan</dc:creator>
      <dc:date>2022-10-18T14:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617514#M214598</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249836"&gt;@tomapatan&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you could try something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;your_search&amp;gt;
| stats 
   earliest(eval(if(match(location_desc,"OUT"),"",_time))) AS swipe_in
   latest(eval(if(match(location_desc,"OUT"),_time,""))) AS swipe_out
| eval duration=swipe_out-swipe_in&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, next time, add your search also as text&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 12:01:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617514#M214598</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-10-18T12:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617515#M214599</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks for your answer.&lt;/P&gt;&lt;P&gt;This search returns only the very first and very last swipe_in and swipe_out, I need to calculate the duration of every swipe_in and swipe_out during a certain period of time.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 12:09:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617515#M214599</guid>
      <dc:creator>tomapatan</dc:creator>
      <dc:date>2022-10-18T12:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617517#M214600</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249836"&gt;@tomapatan&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;this is one of the few cases to use the thansaction command.&lt;/P&gt;&lt;P&gt;if the swipe_ is identiiable with "*IN*" and swipe_out with "*OUT*", please trysomething like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;your-search&amp;gt;
| transaction startswith=location_desc="*IN*" endswith=location_desc="*OUT*"
| table _time duration&lt;/LI-CODE&gt;&lt;P&gt;otherwise, please tell me how to identify swipe_in and swipe_out.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 12:16:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617517#M214600</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-10-18T12:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617519#M214601</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;BR /&gt;I`ve also looked at the transaction command, but I`m only getting the swipe_in time stamp and missing the swipe_out data. Duration is calculated OK, but ideally I`d like to be able to display a table that contains:&lt;/P&gt;&lt;P&gt;swipe_in swipe_out duration&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;2022-10-17 08:02:19&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;2022-10-17 16:02:19&lt;/TD&gt;&lt;TD&gt;08:00:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&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;This is what I`m currently getting:&lt;/P&gt;&lt;P&gt;location_desc _time duration&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;swipe_in&lt;/DIV&gt;&lt;DIV class=""&gt;swipe_out&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;2022-10-17 08:02:19&lt;/TD&gt;&lt;TD&gt;08:45:18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;swipe_in&lt;/DIV&gt;&lt;DIV class=""&gt;swipe_out&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;2022-10-11 08:04:37&lt;/TD&gt;&lt;TD&gt;08:26:48&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;swipe_in&lt;/DIV&gt;&lt;DIV class=""&gt;swipe_out&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;2022-10-10 08:15:24&lt;/TD&gt;&lt;TD&gt;08:05:37&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 18 Oct 2022 12:28:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617519#M214601</guid>
      <dc:creator>tomapatan</dc:creator>
      <dc:date>2022-10-18T12:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617525#M214603</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249836"&gt;@tomapatan&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;as you can read in the above link startswith and endswith take as value a string or an eval expressin, so you could try something like this (I never tested!):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;your_search&amp;gt;
| transaction maxevents=2 startswith=eval(NOT match(location_desc,"OUT")) endswith=eval(match(location_desc,"OUT"))
| table _time duration&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 12:57:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617525#M214603</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-10-18T12:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the duration?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617665#M214658</link>
      <description>&lt;P&gt;This is what did the trick for me, although I am convinced there are more elegant ways of writing this search.&lt;/P&gt;&lt;P&gt;{location_desc}=_time - &amp;gt; pairs each Entrance and Exit with it`s corresponding timestamp&lt;/P&gt;&lt;P&gt;Key was to stitch the data together using mvzip then to expand it using mvexpand so I can have Entrance and Exit times displayed on the same row.&lt;/P&gt;&lt;P&gt;Search details:&lt;/P&gt;&lt;P&gt;| fields first_name last_name _time, location_desc&lt;BR /&gt;| eval location_desc=if(match(location_desc,"OUT"), "Exit", "Entrance")&lt;BR /&gt;| eval&lt;BR /&gt;name=first_name." ".last_name,&lt;BR /&gt;{location_desc}=_time&lt;BR /&gt;| stats values(Entrance) as Entrance values(Exit) as Exit by name&lt;BR /&gt;| eval combined_data=mvzip(Entrance,Exit,"|")&lt;BR /&gt;| mvexpand combined_data&lt;BR /&gt;| eval&lt;BR /&gt;fields=split(combined_data, "|"),&lt;BR /&gt;Entrance=mvindex(fields,0),&lt;BR /&gt;Exit=mvindex(fields,1),&lt;BR /&gt;duration=round((Exit-Entrance)/3600, 2),&lt;BR /&gt;Entrance=strftime(Entrance, "%d/%m/%Y %H:%M:%S"),&lt;BR /&gt;Exit=strftime(Exit, "%d/%m/%Y %H:%M:%S")&lt;BR /&gt;| table name, Entrance, Exit duration&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 09:18:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-duration/m-p/617665#M214658</guid>
      <dc:creator>tomapatan</dc:creator>
      <dc:date>2022-10-19T09:18:36Z</dc:date>
    </item>
  </channel>
</rss>

