<?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: Duration between two events by day based on three or more fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Duration-between-two-events-by-day-based-on-three-or-more-fields/m-p/634024#M220210</link>
    <description>&lt;P&gt;Your sample data show multiple inactive status for some users. Is this representative or will you only get one event when the state changes?&lt;/P&gt;</description>
    <pubDate>Fri, 10 Mar 2023 08:20:43 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-03-10T08:20:43Z</dc:date>
    <item>
      <title>Duration between two events by day based on three or more fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-between-two-events-by-day-based-on-three-or-more-fields/m-p/633889#M220158</link>
      <description>&lt;P&gt;Hello - I need to calculate the average duration between two status types for a user type in a location in a region. I have attached the sample data. For example, I need to calculate the average duration a given user type remains in "inactive" status. These user types are segregated into different locations in different regions.&lt;/P&gt;
&lt;P&gt;Sample data:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nu_learner_0-1678371979630.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24264i6908C5DFD2ADE894/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nu_learner_0-1678371979630.png" alt="nu_learner_0-1678371979630.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The result is want is like this (time is in seconds):&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;aaa&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bbb&amp;nbsp; &amp;nbsp; &amp;nbsp;ccc&lt;BR /&gt;Day 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 40&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;BR /&gt;Day 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;BR /&gt;Day 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;and so on&lt;BR /&gt;I would appreciate any help.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 13:26:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-between-two-events-by-day-based-on-three-or-more-fields/m-p/633889#M220158</guid>
      <dc:creator>nu_learner</dc:creator>
      <dc:date>2023-03-13T13:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Duration between two events by day based on three or more fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-between-two-events-by-day-based-on-three-or-more-fields/m-p/634024#M220210</link>
      <description>&lt;P&gt;Your sample data show multiple inactive status for some users. Is this representative or will you only get one event when the state changes?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 08:20:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-between-two-events-by-day-based-on-three-or-more-fields/m-p/634024#M220210</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-03-10T08:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Duration between two events by day based on three or more fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-between-two-events-by-day-based-on-three-or-more-fields/m-p/634118#M220248</link>
      <description>&lt;P&gt;This is nearly one for one the same as&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634096#M220230" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634096#M220230&lt;/A&gt;; the only difference is that you have consecutive time boundaries you want to calculate for while the other use case calculates for a single start-to-end interval.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval day = _time
| bin span=1d@d day ``` start of day of event ```
| addinfo ``` search end time is info_max_time ```
| eval duration = if(closed_txn == 1, duration,
 if(status == "active", _time - max(day, info_min_time),
 min(info_max_time, relative_time(day, "+1d")) - _time))
| stats sum(duration) as inactive by day user_type region_id location_id&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2023 04:59:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-between-two-events-by-day-based-on-three-or-more-fields/m-p/634118#M220248</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-03-11T04:59:29Z</dc:date>
    </item>
  </channel>
</rss>

