<?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 do I divide the sum based on a criterion using the eval command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418709#M120385</link>
    <description>&lt;P&gt;WoW man, rename must be first. OOOOO I read half of the SPlunk doc for if/case/string/toNumber tried 100 different scnearios. Thankssssss&lt;/P&gt;</description>
    <pubDate>Sat, 06 Oct 2018 19:50:53 GMT</pubDate>
    <dc:creator>xelian</dc:creator>
    <dc:date>2018-10-06T19:50:53Z</dc:date>
    <item>
      <title>How do I divide the sum based on a criterion using the eval command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418705#M120381</link>
      <description>&lt;P&gt;Hi I have the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[my search]
|dedup @timestamp 
|stats sum(json_message.amount) as "total" by json_message.currencyCode 
|eval devide = if(like(json_message.currencyCode,"%IDR%") , "1748000" , "100")
|eval final=total/devide 
|table json_message.currencyCode final
|rename final as "Total in real amount",  json_message.currencyCode as "Currency"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In the result table, I want the total amount to be divided by 1748000 for IDR and by 100 for other currencies.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Oct 2018 08:51:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418705#M120381</guid>
      <dc:creator>xelian</dc:creator>
      <dc:date>2018-10-06T08:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I divide the sum based on a criterion using the eval command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418706#M120382</link>
      <description>&lt;P&gt;@xelian ,&lt;/P&gt;

&lt;P&gt;Your search should work. Are you not getting the result? Suggest to remove the quotes around the numbers in the condition though it should not affect your result.&lt;/P&gt;

&lt;P&gt;This is a run anywhere example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults |eval currencies="IDR,EUR,USD,AUD"|makemv currencies delim=","| mvexpand currencies|eval total=100
|eval divider=if(currencies=="IDR",100,10)|eval final=total/divider|fields - divider
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Oct 2018 13:16:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418706#M120382</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-06T13:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I divide the sum based on a criterion using the eval command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418707#M120383</link>
      <description>&lt;P&gt;I remove quotes but in the result always 100 is devide. I think the problem is somewhere in the if, because it is a String. I do not know I am very upset. I tried 100 different scenarios and always 100.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Oct 2018 17:40:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418707#M120383</guid>
      <dc:creator>xelian</dc:creator>
      <dc:date>2018-10-06T17:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I divide the sum based on a criterion using the eval command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418708#M120384</link>
      <description>&lt;P&gt;Hi @xelian,&lt;BR /&gt;
Can you please try below query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[my search]
|dedup @timestamp 
| rename json_message.currencyCode as currencyCode,  json_message.amount as amount
|stats sum(amount) as "total" by currencyCode 
|eval devide = if(like(currencyCode,"%IDR%") , 1748000 , 100)
|eval final=total/devide 
|table currencyCode final
|rename final as "Total in real amount",  currencyCode as "Currency"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps!!&lt;/P&gt;</description>
      <pubDate>Sat, 06 Oct 2018 18:58:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418708#M120384</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2018-10-06T18:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I divide the sum based on a criterion using the eval command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418709#M120385</link>
      <description>&lt;P&gt;WoW man, rename must be first. OOOOO I read half of the SPlunk doc for if/case/string/toNumber tried 100 different scnearios. Thankssssss&lt;/P&gt;</description>
      <pubDate>Sat, 06 Oct 2018 19:50:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418709#M120385</guid>
      <dc:creator>xelian</dc:creator>
      <dc:date>2018-10-06T19:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I divide the sum based on a criterion using the eval command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418710#M120386</link>
      <description>&lt;P&gt;Yes, you caught that correctly, always consider renaming the field name if field name cannot be a variable name for your script, for being on safe side.!!!!!&lt;/P&gt;</description>
      <pubDate>Sat, 06 Oct 2018 20:31:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-divide-the-sum-based-on-a-criterion-using-the-eval/m-p/418710#M120386</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2018-10-06T20:31:16Z</dc:date>
    </item>
  </channel>
</rss>

