<?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 can I run stats sum as command on same search for two different values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292122#M88245</link>
    <description>&lt;P&gt;I did the search a different way, but it seems as if the second eval statement is just throwing out the 0 instead of doing the sum, do you see anything wrong with this search?&lt;/P&gt;

&lt;P&gt;source="Dataset_Finance.csv" host="sample" index="dataintegration" sourcetype="SampleFinance" ObjectAccount="4*" OR ObjectAccount="5*"&lt;BR /&gt;
| stats sum(eval(if(ObjectAccount="411010",DomesticAmount,0))) as Sales, sum(eval(if(ObjectAccount="5*",DomesticAmount,0))) as Costs &lt;BR /&gt;
| eval CM=Sales+Costs &lt;BR /&gt;
| eval CMPer=CM/Sales&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 16:10:30 GMT</pubDate>
    <dc:creator>tonahoyos</dc:creator>
    <dc:date>2020-09-29T16:10:30Z</dc:date>
    <item>
      <title>How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292113#M88236</link>
      <description>&lt;P&gt;I have the following search:&lt;/P&gt;

&lt;P&gt;index="data_integration" host="sampledata" sourcetype="csv" Object_Account="4*" OR Object_Account="5*"|stats sum("Domestic _Amount") AS CM&lt;/P&gt;

&lt;P&gt;and the following second search: &lt;/P&gt;

&lt;P&gt;index="data_integration" host="sampledata" sourcetype="csv" Object_Account="4*"| stats sum("Domestic _Amount") AS Sales&lt;/P&gt;

&lt;P&gt;I want to be able to divide CM/Sales. What is the best command or the best way to join these two searches in order to do the division? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:07:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292113#M88236</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2020-09-29T16:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292114#M88237</link>
      <description>&lt;P&gt;Hi tonahoyos,&lt;/P&gt;

&lt;P&gt;you can try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="Dataset_Finance.csv" host="sample" index="dataintegration" sourcetype="SampleFinance" ObjectAccount="4*" OR ObjectAccount="5*"
| eval Sales=if(ObjectAccount="411010",DomesticAmount,0), Costs=if(like(ObjectAccount, "5%"),DomesticAmount,0)
| stats sum(Sales) as Sales, sum(Costs) as Costs 
| eval CM=Sales+Costs 
| eval CMPer=CM/Sales
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first &lt;CODE&gt;eval&lt;/CODE&gt; checks the &lt;CODE&gt;Object_Account&lt;/CODE&gt; and sets the value used, this value is used in the &lt;CODE&gt;stats&lt;/CODE&gt; to sum the total number.&lt;BR /&gt;
This is untested, so please bear in mind that you might need to adapt this to your actual events, but it should help you to get you going.&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 21:36:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292114#M88237</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2017-10-09T21:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292115#M88238</link>
      <description>&lt;P&gt;Here is another way to do this with a single stats command using an inline eval:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="data_integration" host="sampledata" sourcetype="csv" Object_Account="4*" OR Object_Account="5*"
| stats sum("Domestic _Amount") as CM, sum( eval( if( Object_Account like "4%", 'Domestic _Amount', 0 ))) as Sales
| eval ratio = Sales / CM
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Oct 2017 23:38:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292115#M88238</guid>
      <dc:creator>justinatpnnl</dc:creator>
      <dc:date>2017-10-09T23:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292116#M88239</link>
      <description>&lt;P&gt;Hey @tonahoyos, if they solved your problem, remember to "√Accept" an answer to award karma points &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 00:27:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292116#M88239</guid>
      <dc:creator>lfedak_splunk</dc:creator>
      <dc:date>2017-10-10T00:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292117#M88240</link>
      <description>&lt;P&gt;Hello justinatpnnl, &lt;/P&gt;

&lt;P&gt;First, I appreciate your help! I have tested the search and it seems as if there is an issue with the following: &lt;/P&gt;

&lt;P&gt;sum( eval( if( Object_Account like "4%", 'Domestic _Amount', 0 ))) as Sales&lt;/P&gt;

&lt;P&gt;The CM amount shows up, but the Sales amount never does. I have played with it and moved it around a little bit, but I have not been able to sum the Object_Account="4*" amounts. &lt;/P&gt;

&lt;P&gt;Also, I have a question about the if statement. Does it mean that if the object_account contains a 4%, then it will add the Domestic_Amount values, else it turns the value Sales to 0? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:13:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292117#M88240</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2020-09-29T16:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292118#M88241</link>
      <description>&lt;P&gt;Hello MuS,&lt;/P&gt;

&lt;P&gt;Thank you for your answer and your time! I have not been able to solve the search. It seems as if there was an issue after the first eval statement. It narrows down the search to the 4* and 5* Object_account numbers, but it does not follow the first eval section correctly. &lt;/P&gt;

&lt;P&gt;Thank you for your help, I will keep on working on it. &lt;/P&gt;

&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 18:37:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292118#M88241</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2017-10-11T18:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292119#M88242</link>
      <description>&lt;P&gt;My guess is that Splunk is having trouble with the field that has a space in it.  Can you try first renaming that field to something simpler and see if it works?  I used the single quotes around Domestic _Amount to hopefully prevent that issue, but I'm wondering if that is the hang up.&lt;/P&gt;

&lt;P&gt;For your second question, it is doing a sum on the values returned from the if statement.  If it finds a value of 4% (% being a wildcard when using LIKE), then it returns the value of the Domestic _Amount field.  Otherwise it returns a zero, so that it doesn't get added to sales.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 18:37:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292119#M88242</guid>
      <dc:creator>justinatpnnl</dc:creator>
      <dc:date>2017-10-11T18:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292120#M88243</link>
      <description>&lt;P&gt;Is there really a space in "Domestic _Amount"?  I can't imagine why someone would name a field that.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 19:10:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292120#M88243</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-10-11T19:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292121#M88244</link>
      <description>&lt;P&gt;Hello everyone, &lt;/P&gt;

&lt;P&gt;I tried a different way to solve the problem. I am getting close, but my Cost ("5*") do not sum, the if statement throws out the 0 instead. What can I do to fix this? Should I try a different command? &lt;/P&gt;

&lt;P&gt;source="Dataset_Finance.csv" host="sample" index="dataintegration" sourcetype="SampleFinance" ObjectAccount="4*" OR ObjectAccount="5*"&lt;BR /&gt;
| stats sum(eval(if(ObjectAccount="411010",DomesticAmount,0))) as Sales, &lt;STRONG&gt;sum(eval(if(ObjectAccount="5*",DomesticAmount,0))) as Costs&lt;/STRONG&gt; &lt;BR /&gt;
| eval CM=Sales+Costs &lt;BR /&gt;
| eval CMPer=CM/Sales&lt;/P&gt;

&lt;P&gt;Thank you for all the help!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:10:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292121#M88244</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2020-09-29T16:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292122#M88245</link>
      <description>&lt;P&gt;I did the search a different way, but it seems as if the second eval statement is just throwing out the 0 instead of doing the sum, do you see anything wrong with this search?&lt;/P&gt;

&lt;P&gt;source="Dataset_Finance.csv" host="sample" index="dataintegration" sourcetype="SampleFinance" ObjectAccount="4*" OR ObjectAccount="5*"&lt;BR /&gt;
| stats sum(eval(if(ObjectAccount="411010",DomesticAmount,0))) as Sales, sum(eval(if(ObjectAccount="5*",DomesticAmount,0))) as Costs &lt;BR /&gt;
| eval CM=Sales+Costs &lt;BR /&gt;
| eval CMPer=CM/Sales&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:10:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292122#M88245</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2020-09-29T16:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292123#M88246</link>
      <description>&lt;P&gt;I did the search a different way, but it seems as if the second eval statement is just throwing out the 0 instead of doing the sum, do you see anything wrong with this search?&lt;/P&gt;

&lt;P&gt;source="Dataset_Finance.csv" host="sample" index="dataintegration" sourcetype="SampleFinance" ObjectAccount="4*" OR ObjectAccount="5*"&lt;BR /&gt;
| stats sum(eval(if(ObjectAccount="411010",DomesticAmount,0))) as Sales, sum(eval(if(ObjectAccount="5*",DomesticAmount,0))) as Costs &lt;BR /&gt;
| eval CM=Sales+Costs &lt;BR /&gt;
| eval CMPer=CM/Sales&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:10:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292123#M88246</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2020-09-29T16:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292124#M88247</link>
      <description>&lt;P&gt;This is because you use a &lt;CODE&gt;5*&lt;/CODE&gt; in the &lt;CODE&gt;if&lt;/CODE&gt; statement, that does not work. You have to add a &lt;CODE&gt;like()&lt;/CODE&gt; (pro tip: for easier reading and understanding move &lt;CODE&gt;eval&lt;/CODE&gt; out of &lt;CODE&gt;stats&lt;/CODE&gt; - no performance impact at all &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;source="Dataset_Finance.csv" host="sample" index="dataintegration" sourcetype="SampleFinance" ObjectAccount="4*" OR ObjectAccount="5*"&lt;BR /&gt;
| eval Sales=if(ObjectAccount="411010",DomesticAmount,0), Costs=if(like(ObjectAccount, "5%"),DomesticAmount,0)&lt;BR /&gt;
| stats sum(Sales) as Sales, sum(Costs) as Costs &lt;BR /&gt;
| eval CM=Sales+Costs &lt;BR /&gt;
| eval CMPer=CM/Sales&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:15:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292124#M88247</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2020-09-29T16:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run stats sum as command on same search for two different values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292125#M88248</link>
      <description>&lt;P&gt;Within an if statement, you can't use * as a wildcard.  You have to use LIKE with % as the wildcard.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;if(ObjectAccount LIKE "5%",DomesticAmount, 0)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 20:42:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-run-stats-sum-as-command-on-same-search-for-two/m-p/292125#M88248</guid>
      <dc:creator>justinatpnnl</dc:creator>
      <dc:date>2017-10-13T20:42:58Z</dc:date>
    </item>
  </channel>
</rss>

