<?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: Compare Values from Stats Function in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Compare-Values-from-Stats-Function/m-p/395091#M114755</link>
    <description>&lt;P&gt;"| sort 1 -avg_duration" should give you whichever is the biggest&lt;/P&gt;</description>
    <pubDate>Fri, 31 May 2019 00:04:59 GMT</pubDate>
    <dc:creator>niyaz006</dc:creator>
    <dc:date>2019-05-31T00:04:59Z</dc:date>
    <item>
      <title>Compare Values from Stats Function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-Values-from-Stats-Function/m-p/395090#M114754</link>
      <description>&lt;P&gt;I have a search that returns two different values for avg_duration. These values are an average of all the the values that fall under that state of either NEW or OLD. What I need to do now is access the avg_duration's separately in order to determing whether the avg_duration for the NEW or OLD is bigger. The search is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| sort targetId timestamp
| stats first(timestamp) as start, last(timestamp) as end, first(task) as task0, last(task) as task1, first(status) as status0, last(status) as status1 by targetId
| eval curr_time=now()
| eval start_time=if(status0="Started" AND task0="Build CI" AND status1="Completed", strptime(start, "%m/%d/%Y %l:%M:%S %p"), 0) 
| eval start_time=ifnull(start_time, strptime(start, "%Y-%m-%dT%H:%M:%SZ")) 
| eval start_time=ifnull(start_time, strptime(start, "%Y-%m-%dT%H:%M:%S.%QZ")) 
| eval end_time = if(status0="Started" AND task0="Build CI" AND status1="Completed", strptime(end, "%m/%d/%Y %l:%M:%S %p"), 0) 
| eval end_time=ifnull(end_time, strptime(end, "%Y-%m-%dT%H:%M:%SZ")) 
| eval end_time=ifnull(end_time, strptime(end, "%Y-%m-%dT%H:%M:%S.%QZ")) 
| eval start_time=round(start_time, 2) 
| eval end_time=round(end_time, 2)
| eval duration=if(status0="Started" AND task0="Build CI" AND status1="Completed", end_time-start_time, "No Duration")
| where duration!="No Duration"
| eval state=if(start_time+1296000&amp;gt;=curr_time, "NEW", "OLD") 
| stats avg(duration) as avg_duration by state
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The search and output are shown in the attached picture.&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/273802-search-screenshot.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:44:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-Values-from-Stats-Function/m-p/395090#M114754</guid>
      <dc:creator>whunterj</dc:creator>
      <dc:date>2020-09-30T00:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: Compare Values from Stats Function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-Values-from-Stats-Function/m-p/395091#M114755</link>
      <description>&lt;P&gt;"| sort 1 -avg_duration" should give you whichever is the biggest&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 00:04:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-Values-from-Stats-Function/m-p/395091#M114755</guid>
      <dc:creator>niyaz006</dc:creator>
      <dc:date>2019-05-31T00:04:59Z</dc:date>
    </item>
  </channel>
</rss>

