<?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 total time for a specific event over a range of time period in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634289#M220342</link>
    <description>&lt;P&gt;Yeah I already modified it to startswith=state="OFF" to get the correct results&lt;BR /&gt;Thanks for your help&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Mar 2023 15:10:56 GMT</pubDate>
    <dc:creator>akidua</dc:creator>
    <dc:date>2023-03-13T15:10:56Z</dc:date>
    <item>
      <title>Calculate total time for a specific event over a range of time period?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634096#M220230</link>
      <description>&lt;P&gt;I have 2 queries:&lt;BR /&gt;One is an OFF event, and one is an ON event for a cluster of machines for customers. I want to calculate approximate total hours of OFF event within a time range. Also, the assumption is if the ON event is seen for the first time within the time picker range that implies the machine was already OFF before this.&lt;BR /&gt;So, for example:&lt;BR /&gt;For 20-day period over month of November&lt;/P&gt;
&lt;P&gt;OFF events:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;CustomerID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;Time/Date&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;ABC&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/2/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;GHI&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/3/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;GHI&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/9/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;MNO&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/10/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;PQR&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/14/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;JKL&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/16/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;BR /&gt;ON events:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;CustomerID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;Time/Date&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;DEF&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/5/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;GHI&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/7/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;PQR&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/7/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;JKL&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/12/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;MNO&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/15/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;JKL&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/18/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if today date is November 20 and time picker range is set for last 20 days (making time range from 11/1/2022 to 11/20/2022):&lt;BR /&gt;OFF time for ABC is 11/20 – 11/2 = 18 days&lt;/P&gt;
&lt;P&gt;OFF time for DEF is 11/5- 11/1 = 4 days since the machines is assumed to be turned off before the ON event&lt;/P&gt;
&lt;P&gt;OFF time for GHI is (11/7-11/3) + (11/20-11/9) = 4 + 11 + 15 days&lt;/P&gt;
&lt;P&gt;OFF time for JKL is (11/12-11/1) + (11/18-11/16) = 11+2 = 13 days&lt;/P&gt;
&lt;P&gt;OFF time for MNO is (15-10) = 5 days&lt;/P&gt;
&lt;P&gt;OFF time for PQR is (11/7-11/1) +(11/20-11/14) = 6+6 =12 days&lt;/P&gt;
&lt;P&gt;So total off time(approximate) for 6 customers over a range of 20 days is 18+4+15+13+5+12=67 days&lt;BR /&gt;&lt;BR /&gt;The query that I came up with is just customers data sorted over customer and decreasing time:&lt;/P&gt;
&lt;P&gt;index=xaci sourcetype="xaxd" "*Powered off operation for*" OR "Powered On operation for" | rex "[cC]ustomer:(?&amp;lt;customerID&amp;gt;\w"|&amp;nbsp; sort customerID, - _time&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;CustomerID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;_time&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;ABC&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/2/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;DEF&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/5/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;GHI&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/9/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;GHI&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/7/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;GHI&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/3/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;JKL&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/18/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;JKL&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/16/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;JKL&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/12/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;MNO&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/15/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;MNO&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/10/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;PQR&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/14/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="312"&gt;
&lt;P&gt;PQR&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="312"&gt;
&lt;P&gt;11/7/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;BR /&gt;Any help is highly appreciated since I'm new to Splunk &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 13:39:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634096#M220230</guid>
      <dc:creator>akidua</dc:creator>
      <dc:date>2023-03-13T13:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate total time for a specific event over a range of time period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634106#M220238</link>
      <description>&lt;P&gt;Here is the most literal interpretation of your requirement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| transaction CustomerID startswith=State="ON" endswith=State="OFF" keepevicted=1 keeporphans=1
| addinfo
| eval offDays = round(if(closed_txn == 1, duration, if(State == "OFF", info_max_time - _time, _time - info_min_time)) / 86400)
| stats sum(offDays) as offDays by CustomerID&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This assumes that "Time/Date" in your data illustration is _time field. &amp;nbsp;The sample data gives&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;CustomerID&lt;/TD&gt;&lt;TD&gt;info_min_time&lt;/TD&gt;&lt;TD&gt;info_max_time&lt;/TD&gt;&lt;TD&gt;offDays&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;2022-11-01&lt;/TD&gt;&lt;TD&gt;2022-11-20&lt;/TD&gt;&lt;TD&gt;18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;DEF&lt;/TD&gt;&lt;TD&gt;2022-11-01&lt;/TD&gt;&lt;TD&gt;2022-11-20&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;GHI&lt;/TD&gt;&lt;TD&gt;2022-11-01&lt;/TD&gt;&lt;TD&gt;2022-11-20&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;JKL&lt;/TD&gt;&lt;TD&gt;2022-11-01&lt;/TD&gt;&lt;TD&gt;2022-11-20&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;MNO&lt;/TD&gt;&lt;TD&gt;2022-11-01&lt;/TD&gt;&lt;TD&gt;2022-11-20&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PQR&lt;/TD&gt;&lt;TD&gt;2022-11-01&lt;/TD&gt;&lt;TD&gt;2022-11-20&lt;/TD&gt;&lt;TD&gt;12&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;TD&gt;67&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Note the above code will not list info_min_time and info_max_time as shown. &amp;nbsp;Those columns are added to help visualization. &amp;nbsp;The expanded code is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| transaction CustomerID startswith=State="ON" endswith=State="OFF" keepevicted=1 keeporphans=1
| addinfo
| fieldformat info_min_time = strftime(info_min_time, "%F")
| fieldformat info_max_time = strftime(info_max_time, "%F")
| eval offDays = round(if(closed_txn == 1, duration, if(State == "OFF", info_max_time - _time, _time - info_min_time)) / 86400)
| stats sum(offDays) as offDays by CustomerID info_min_time info_max_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 21:59:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634106#M220238</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-03-10T21:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate total time for a specific event over a range of time period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634115#M220245</link>
      <description>&lt;P&gt;Thank you so much&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I have a question though:&lt;BR /&gt;For the customer JKL, how is "duration" going to give the correct result. Isn't duration going to give time difference between latest and first event? So with that logic it will give 11/12/2022 -11/16/2022&lt;BR /&gt;instead of 13 days?&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2023 03:10:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634115#M220245</guid>
      <dc:creator>akidua</dc:creator>
      <dc:date>2023-03-11T03:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate total time for a specific event over a range of time period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634116#M220246</link>
      <description>&lt;P&gt;Apologies..i understood the logic..duration will be computed for ON event followed by an OFF event.&lt;BR /&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp; for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2023 03:21:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634116#M220246</guid>
      <dc:creator>akidua</dc:creator>
      <dc:date>2023-03-11T03:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate total time for a specific event over a range of time period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634119#M220249</link>
      <description>&lt;P&gt;I think I made a mistake. &amp;nbsp;It should be from OFF to ON as one transaction. &amp;nbsp;The rest should be picked up from boundaries&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| transaction CustomerID startswith=State="OFF" endswith=State="ON" keepevicted=1 keeporphans=1
| addinfo
| fieldformat info_min_time = strftime(info_min_time, "%F")
| fieldformat info_max_time = strftime(info_max_time, "%F")
| eval offDays = round(if(closed_txn == 1, duration, if(State == "OFF", info_max_time - _time, _time - info_min_time)) / 86400)
| stats sum(offDays) as offDays by CustomerID&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 06:12:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634119#M220249</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-03-11T06:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate total time for a specific event over a range of time period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634289#M220342</link>
      <description>&lt;P&gt;Yeah I already modified it to startswith=state="OFF" to get the correct results&lt;BR /&gt;Thanks for your help&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 15:10:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range-of-time/m-p/634289#M220342</guid>
      <dc:creator>akidua</dc:creator>
      <dc:date>2023-03-13T15:10:56Z</dc:date>
    </item>
  </channel>
</rss>

