<?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 How to perform math on single values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-math-on-single-values/m-p/105070#M27241</link>
    <description>&lt;P&gt;Hello experts. After mining this site I figure its not possible to do math on distinct vales. I've seen answers that help people munge multiple searches into one to avoid this issue. Well I have 2 distinct searches that don't have any fields in common. I only want to perform math on the counts from both.&lt;/P&gt;

&lt;P&gt;1st search:&lt;BR /&gt;
index=here sourcetype=this SpecialKeyword&lt;/P&gt;

&lt;P&gt;2nd search:&lt;BR /&gt;
index=here sourcetype=this SqlTransactionRollbackException AND CertainCommandObject&lt;/P&gt;

&lt;P&gt;You could say its a flaw in the logs that the data I need is written in separate events. Nevertheless I'd like to take the count of the 2nd search and divide by the count of the 1st, giving me a percentage of errors for a certain type of action.&lt;/P&gt;

&lt;P&gt;There are no fields in common between the two that differ in their values. The 2nd has a SQLSTATE of "40001" ... can that be compared to null somehow?&lt;/P&gt;

&lt;P&gt;index=here sourcetype=this SpecialKeyword OR (SqlTransactionRollbackException AND CertainCommandObject) | stats eval(count(SQLSTATE="40001")/count(SQLSTATE=null)) as "my desired value"&lt;/P&gt;

&lt;P&gt;I can't seem to find the right query.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Oct 2013 21:13:52 GMT</pubDate>
    <dc:creator>tsmithsplunk</dc:creator>
    <dc:date>2013-10-17T21:13:52Z</dc:date>
    <item>
      <title>How to perform math on single values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-math-on-single-values/m-p/105070#M27241</link>
      <description>&lt;P&gt;Hello experts. After mining this site I figure its not possible to do math on distinct vales. I've seen answers that help people munge multiple searches into one to avoid this issue. Well I have 2 distinct searches that don't have any fields in common. I only want to perform math on the counts from both.&lt;/P&gt;

&lt;P&gt;1st search:&lt;BR /&gt;
index=here sourcetype=this SpecialKeyword&lt;/P&gt;

&lt;P&gt;2nd search:&lt;BR /&gt;
index=here sourcetype=this SqlTransactionRollbackException AND CertainCommandObject&lt;/P&gt;

&lt;P&gt;You could say its a flaw in the logs that the data I need is written in separate events. Nevertheless I'd like to take the count of the 2nd search and divide by the count of the 1st, giving me a percentage of errors for a certain type of action.&lt;/P&gt;

&lt;P&gt;There are no fields in common between the two that differ in their values. The 2nd has a SQLSTATE of "40001" ... can that be compared to null somehow?&lt;/P&gt;

&lt;P&gt;index=here sourcetype=this SpecialKeyword OR (SqlTransactionRollbackException AND CertainCommandObject) | stats eval(count(SQLSTATE="40001")/count(SQLSTATE=null)) as "my desired value"&lt;/P&gt;

&lt;P&gt;I can't seem to find the right query.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2013 21:13:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-math-on-single-values/m-p/105070#M27241</guid>
      <dc:creator>tsmithsplunk</dc:creator>
      <dc:date>2013-10-17T21:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform math on single values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-math-on-single-values/m-p/105071#M27242</link>
      <description>&lt;P&gt;You could run your two searches using &lt;CODE&gt;append&lt;/CODE&gt;, calculate the counts independently and then do your &lt;CODE&gt;eval&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=here sourcetype=this SpecialKeyword | stats count as count1 | append [search index=here sourcetype=this SqlTransactionRollbackException AND CertainCommandObject | stats count as count2] | eval value=count2/count1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...or you could do something more similar to the search you have in the end:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=here sourcetype=this SpecialKeyword OR (SqlTransactionRollbackException AND CertainCommandObject) | stats count(eval(SQLSTATE=="40001")) as count2, count(eval(isnull(SQLSTATE))) as count1 | eval value=count2/count1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Oct 2013 21:23:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-math-on-single-values/m-p/105071#M27242</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-10-17T21:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform math on single values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-math-on-single-values/m-p/105072#M27243</link>
      <description>&lt;P&gt;There are several ways to do this, and you don't need to screw around with finding field values. You can do it the most crude way:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=here sourcetype=this SpecialKeyword
| stats count as c_special 
| append [ search index=here sourcetype=this SqlTransactionRollbackException AND CertainCommandObject 
           | stats count as c_other]
| eval ratio=c_other/c_special
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But you can refactor to make the search more efficient, which was kind of what you were trying:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=here sourcetype=this (SpecialKeyword OR (SqlTransactionRollbackException AND CertainCommandObject))
| stats count(searchmatch("SpecialKeyword")) as c_special
        count(searchmatch("SqlTransactionRollbackException AND CertainCommandObject")) as c_other
| eval ratio = c_other/c_special
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;searchmatch()&lt;/CODE&gt; function lets you just use the same search terms as before (just a substitute for the looking for a SQLSTATE value or other field), though it makes a bunch of redundancy and makes it harder to see what you're doing. But the overall search will be faster. &lt;/P&gt;

&lt;P&gt;Another way to solve this makes use of the &lt;CODE&gt;multisearch&lt;/CODE&gt; search command. It's arguably clearer than the above refactoring, and the good thing is it doesn't have the redundancy:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| multisearch
  [ search index=here sourcetype=this SpecialKeyword
    | eval marker="s" ]
  [ search index=here sourcetype=this SqlTransactionRollbackException AND CertainCommandObject
    | eval marker="o" ]
| stats count(eval(marker=="s")) as c_s
        count(eval(marker=="o")) as c_o
| eval r=c_o/c_s
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is pretty much what you were trying to do, except without you having to try to find a special marker field (you just create it with &lt;CODE&gt;| eval marker=...&lt;/CODE&gt;) and without having to redundantly specify search terms (which is what i did above). You also get the improved performance of not having to dispatch two searches in sequence (which is what the version with &lt;CODE&gt;append&lt;/CODE&gt;), as Splunk does the refactor and runs both multisearches in a single pass.    &lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2013 23:09:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-math-on-single-values/m-p/105072#M27243</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-10-17T23:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform math on single values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-perform-math-on-single-values/m-p/105073#M27244</link>
      <description>&lt;P&gt;I tried the multisearch approach and it works great. Pretty quick too. I tacked on a nice &lt;/P&gt;

&lt;P&gt;| untable "" measure value&lt;/P&gt;

&lt;P&gt;which allowed me to chart the results as a PIE.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2013 20:23:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-perform-math-on-single-values/m-p/105073#M27244</guid>
      <dc:creator>tsmithsplunk</dc:creator>
      <dc:date>2013-10-21T20:23:59Z</dc:date>
    </item>
  </channel>
</rss>

