<?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 edit my eval=if() statement to output the expected result? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-if-statement-to-output-the-expected-result/m-p/201431#M58364</link>
    <description>&lt;P&gt;This works perfectly, thanks so much!&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jun 2016 21:33:33 GMT</pubDate>
    <dc:creator>jxiongjx</dc:creator>
    <dc:date>2016-06-09T21:33:33Z</dc:date>
    <item>
      <title>How to edit my eval=if() statement to output the expected result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-if-statement-to-output-the-expected-result/m-p/201429#M58362</link>
      <description>&lt;P&gt;In my search I currently have&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| transaction startswith = "start" endswith = "end" maxspan = 10m
| eval current = if(Data1 == "Curr", Data3, null)
| timechart avg(duration) max(current)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My transaction is grouping events how I want them to, but the problem I have is with the eval search. Data1 essentially has a description of the type of data and Data3 has the value. I only care about the data when Data1 is "Curr" so if that case is true, then current should be the value of Data3. If not, then I don't care about Data3 so I set it to null.&lt;/P&gt;

&lt;P&gt;(Note that each event has a Data1 and Data3 value so a transaction should have x number of Data1's and Data3's where x is the eventcount)&lt;BR /&gt;
The goal of the search is to go through each event in a transaction and see if Data1 is "Curr" and to take note of the value and after going through each event in the transaction, to find the max value.&lt;/P&gt;

&lt;P&gt;The problem I found is in the result of max(current)&lt;BR /&gt;
If none of the events in a transaction has Data1="Curr", then there is no max(current) value which is what I am looking for.&lt;/P&gt;

&lt;P&gt;But if there is then the max(current) value just finds the max of Data3 regardless of if that event is the one with Data1="Curr"&lt;BR /&gt;
For example: if a log data has&lt;BR /&gt;
Event1: start&lt;BR /&gt;
Event2: Data1 = Curr, Data3 = 5&lt;BR /&gt;
Event3: Data1 = Volt, Data3 = 10&lt;BR /&gt;
Event4: end&lt;BR /&gt;
My current search is outputting max(current) as 10 when I want it to be 5 since the 3rd event is not a Curr event so its Data3 value should not be counted when finding the max.&lt;/P&gt;

&lt;P&gt;Any help will be appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 21:50:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-if-statement-to-output-the-expected-result/m-p/201429#M58362</guid>
      <dc:creator>jxiongjx</dc:creator>
      <dc:date>2016-06-08T21:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval=if() statement to output the expected result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-if-statement-to-output-the-expected-result/m-p/201430#M58363</link>
      <description>&lt;P&gt;The transaction command is making a multi-value field out of Data1, so it will always equal "Curr" in your if statement.&lt;/P&gt;

&lt;P&gt;You should be able to fix this by moving your eval before your transaction. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval current = if(Data1 == "Curr", Data3, null) 
| transaction startswith="start" endswith="end" 
| timechart avg(duration) max(current)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2016 00:04:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-if-statement-to-output-the-expected-result/m-p/201430#M58363</guid>
      <dc:creator>justinatpnnl</dc:creator>
      <dc:date>2016-06-09T00:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval=if() statement to output the expected result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-if-statement-to-output-the-expected-result/m-p/201431#M58364</link>
      <description>&lt;P&gt;This works perfectly, thanks so much!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 21:33:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-if-statement-to-output-the-expected-result/m-p/201431#M58364</guid>
      <dc:creator>jxiongjx</dc:creator>
      <dc:date>2016-06-09T21:33:33Z</dc:date>
    </item>
  </channel>
</rss>

