<?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 delta for range of time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327574#M161356</link>
    <description>&lt;P&gt;Excellent! This is precisely what I was looking for! Thanks a lot, @somesoni2&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2017 20:56:08 GMT</pubDate>
    <dc:creator>gauravnj1</dc:creator>
    <dc:date>2017-04-13T20:56:08Z</dc:date>
    <item>
      <title>Calculate delta for range of time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327570#M161352</link>
      <description>&lt;P&gt;I'm fairly new to Splunk and its query language. I have this data that I'd like to search through and visualize in a certain way. Below is what the data looks like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EmailAddress, LoggedInAt, EventDescription, IP_Address
abc@abc.com, 2017-04-13 07:00:00, AuthSuccessful, 1.1.1.1
abc@abc.com, 2017-04-13 07:10:00, AuthFailure, 2.2.2.2
abc@abc.com, 2017-04-13 07:20:00, AuthSuccessful, 3.3.3.3

def@abc.com, 2017-04-13 07:00:00, AuthSuccessful, 4.4.4.4
def@abc.com, 2017-04-13 07:10:00, AuthFailure, 5.5.5.5
def@abc.com, 2017-04-13 07:20:00, AuthSuccessful, 6.6.6.6

ghi@abc.com, 2017-04-13 07:00:00, AuthSuccessful, 7.7.7.7
ghi@abc.com, 2017-04-13 07:10:00, AuthFailure, 8.8.8.8
ghi@abc.com, 2017-04-13 07:20:00, AuthSuccessful, 8.8.8.8
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here's the query that I have created:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventDescription=AuthSuccessful LoggedInAt="2017-04-13*"
| iplocation IP_Address 
| stats values(Country) as Country by EmailAddress
| eval Countries=mvcount(Country)
| sort - Countries
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My output looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EmailAddress, Country, Countries
abc@abc.com, SomeCountry, 2
             SomeOtherCountry

def@abc.com, SomeCountry, 2
             SomeOtherCountry

ghi@abc.com, SomeCountry, 2
             SomeCountry2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I'd like to see is this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EmailAddress, Country, Countries, TimeDelta
abc@abc.com, SomeCountry, 2, 20
          SomeOtherCountry
def@abc.com, SomeCountry, 2, 20
          SomeOtherCountry
ghi@abc.com, SomeCountry, 2, 20
          SomeOtherCountry
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;where TimeDelta is the difference in the earliest and latest LoggedInAt timestamps for a particular EmailAddress. I've tried 'delta' command with no success. If someone could help me figure this out, I'd be very grateful.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2017 19:07:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327570#M161352</guid>
      <dc:creator>gauravnj1</dc:creator>
      <dc:date>2017-04-13T19:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate delta for range of time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327571#M161353</link>
      <description>&lt;P&gt;Since your LoggInAt is in string format, we need to convert it to epoch so that you can do your operation. Try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EventDescription=AuthSuccessful LoggedInAt="2017-04-13*"
 | iplocation IP_Address 
 | eval LoggedInAt=strptime(LoggedInAt,"%Y-%m-%d %H:%M:%S")
 | stats values(Country) as Country min(LoggedInAt) as min max(LoggedInAt) as max by EmailAddress
 | eval TimeDelta=max-min | fields - max min
 | eval Countries=mvcount(Country)
 | sort - Countries
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Apr 2017 19:20:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327571#M161353</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-04-13T19:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate delta for range of time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327572#M161354</link>
      <description>&lt;P&gt;This returns the time delta in seconds, correct? Is there a way to convert the delta back to human readable form? Like in minutes or hours?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2017 20:46:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327572#M161354</guid>
      <dc:creator>gauravnj1</dc:creator>
      <dc:date>2017-04-13T20:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate delta for range of time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327573#M161355</link>
      <description>&lt;P&gt;Yes and Yes.  Just replace &lt;CODE&gt;| eval TimeDelta=max-min&lt;/CODE&gt; with &lt;CODE&gt;| eval TimeDelta=tostring(max-min,"duration")&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2017 20:50:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327573#M161355</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-04-13T20:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate delta for range of time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327574#M161356</link>
      <description>&lt;P&gt;Excellent! This is precisely what I was looking for! Thanks a lot, @somesoni2&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2017 20:56:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327574#M161356</guid>
      <dc:creator>gauravnj1</dc:creator>
      <dc:date>2017-04-13T20:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate delta for range of time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327575#M161357</link>
      <description>&lt;P&gt;@somesoni2, once you've converted it, is there a reason you're not using &lt;CODE&gt;stats ... range(LoggedInAt) as TimeDelta ...&lt;/CODE&gt;?  I've seen @woodcock do that a few times in this situation. &lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2017 21:28:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-delta-for-range-of-time/m-p/327575#M161357</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-04-13T21:28:10Z</dc:date>
    </item>
  </channel>
</rss>

