<?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: How to get duration for the product A in 2 occurrences ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-duration-for-the-product-A-in-2-occurrences/m-p/554003#M157271</link>
    <description>&lt;P&gt;streamstats may be your friend&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval product="A" 
| eval status="Start A1 A2 End Start End" 
| makemv status 
| mvexpand status 
| appendcols 
    [| makeresults 
    | eval time="08:00 08:05 08:15 08:20 08:40 09:40" 
    | makemv time 
    | mvexpand time ] 
| rename COMMENT as "Dummy data ends here" 
| eval time=strptime(time,"%H:%M") 
| streamstats reset_on_change=t reset_after="status=\"End\"" min(time) as Start_Time max(time) as End_Time by product 
| eval duration=round((End_Time-Start_Time)/60)
| where status="End"
| table product duration *_Time&lt;/LI-CODE&gt;&lt;P&gt;but you would need to handle the cases where there is no End and also ensure that there is no interleaving of "starts" for the same product before an end - but you would need some other correlation field in that case.&lt;/P&gt;&lt;P&gt;This example shows products A and B, where before the streamstats you sort by product and time&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval product="A" 
| eval status="Start A1 A2 End Start End" 
| makemv status 
| mvexpand status 
| appendcols 
    [| makeresults 
    | eval time="08:00 08:05 08:15 08:20 08:40 09:40" 
    | makemv time 
    | mvexpand time ] 
| append [
  | makeresults 
  | eval product="B" 
  | eval status="Start B1 B2 End Start End" 
  | makemv status 
  | mvexpand status 
  | appendcols 
    [| makeresults 
    | eval time="08:02 08:07 08:15 08:50 08:55 09:30" 
    | makemv time 
    | mvexpand time ] 
]
| sort product time
| rename COMMENT as "Dummy data ends here"
| eval time=strptime(time,"%H:%M") 
| streamstats reset_on_change=t reset_after="status=\"End\"" min(time) as Start_Time max(time) as End_Time by product 
| eval duration=round((End_Time-Start_Time)/60)
| where status="End"
| table product duration *_Time&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 02 Jun 2021 03:12:13 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2021-06-02T03:12:13Z</dc:date>
    <item>
      <title>How to get duration for the product A in 2 occurrences ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-duration-for-the-product-A-in-2-occurrences/m-p/554001#M157269</link>
      <description>&lt;P&gt;So what I have now from my search so far&lt;/P&gt;&lt;P&gt;Product&amp;nbsp; &amp;nbsp; &amp;nbsp;Status&amp;nbsp; &amp;nbsp; Time&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Start&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.00 AM&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.05 AM&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.15 AM&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.20 AM&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Start&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8.40 AM&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.40 AM&lt;/P&gt;&lt;P&gt;Right now I only get the second start-end duration = 60 minutes only. How can I get it to show the first start-end duration = 20 minutes as well? The "Product" name needs to be the same.&lt;/P&gt;&lt;P&gt;|makeresults |eval product="A"|eval status="Start A1 A2 End Start End"|makemv status|mvexpand status&lt;BR /&gt;|appendcols [|makeresults|eval time="08:00 08:05 08:15 08:20 08:40 09:40"|makemv time|mvexpand time ]&lt;BR /&gt;|rename COMMENT as "Dummy data ends here"&lt;BR /&gt;|eval time=strptime(time,"%H:%M")&lt;BR /&gt;|stats max(eval(if(status=="Start",time,null()))) as Start_Time,max(eval(if(status=="End",time,null()))) as End_Time by product&lt;BR /&gt;|eval duration=round((End_Time-Start_Time)/60)&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jun 2021 02:53:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-duration-for-the-product-A-in-2-occurrences/m-p/554001#M157269</guid>
      <dc:creator>moinyuso96</dc:creator>
      <dc:date>2021-06-02T02:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to get duration for the product A in 2 occurrences ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-duration-for-the-product-A-in-2-occurrences/m-p/554003#M157271</link>
      <description>&lt;P&gt;streamstats may be your friend&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval product="A" 
| eval status="Start A1 A2 End Start End" 
| makemv status 
| mvexpand status 
| appendcols 
    [| makeresults 
    | eval time="08:00 08:05 08:15 08:20 08:40 09:40" 
    | makemv time 
    | mvexpand time ] 
| rename COMMENT as "Dummy data ends here" 
| eval time=strptime(time,"%H:%M") 
| streamstats reset_on_change=t reset_after="status=\"End\"" min(time) as Start_Time max(time) as End_Time by product 
| eval duration=round((End_Time-Start_Time)/60)
| where status="End"
| table product duration *_Time&lt;/LI-CODE&gt;&lt;P&gt;but you would need to handle the cases where there is no End and also ensure that there is no interleaving of "starts" for the same product before an end - but you would need some other correlation field in that case.&lt;/P&gt;&lt;P&gt;This example shows products A and B, where before the streamstats you sort by product and time&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval product="A" 
| eval status="Start A1 A2 End Start End" 
| makemv status 
| mvexpand status 
| appendcols 
    [| makeresults 
    | eval time="08:00 08:05 08:15 08:20 08:40 09:40" 
    | makemv time 
    | mvexpand time ] 
| append [
  | makeresults 
  | eval product="B" 
  | eval status="Start B1 B2 End Start End" 
  | makemv status 
  | mvexpand status 
  | appendcols 
    [| makeresults 
    | eval time="08:02 08:07 08:15 08:50 08:55 09:30" 
    | makemv time 
    | mvexpand time ] 
]
| sort product time
| rename COMMENT as "Dummy data ends here"
| eval time=strptime(time,"%H:%M") 
| streamstats reset_on_change=t reset_after="status=\"End\"" min(time) as Start_Time max(time) as End_Time by product 
| eval duration=round((End_Time-Start_Time)/60)
| where status="End"
| table product duration *_Time&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 02 Jun 2021 03:12:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-duration-for-the-product-A-in-2-occurrences/m-p/554003#M157271</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-06-02T03:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to get duration for the product A in 2 occurrences ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-duration-for-the-product-A-in-2-occurrences/m-p/554004#M157272</link>
      <description>&lt;P&gt;Thank you for the clear and thorough explanation.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jun 2021 03:16:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-duration-for-the-product-A-in-2-occurrences/m-p/554004#M157272</guid>
      <dc:creator>moinyuso96</dc:creator>
      <dc:date>2021-06-02T03:16:54Z</dc:date>
    </item>
  </channel>
</rss>

