<?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 Adding 2 searches together sounds easy in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353438#M163182</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;index=ABC source="ABC"   ServiceName=ABC  |  
stats distinct_count(CorrelationId) as TotalA | 
appendcols [search  "TokenStatus=*Success*" ServiceName=ABC | stats distinct_count(CorrelationId) as TotalSuccess ]| 
appendcols [search TokenSubStatus=*error* ServiceName=ABC | stats distinct_count(CorrelationId) as TotalFailure ]| 
eval Total=(TotalSuccess*100)/TotalA | fields Total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have been given the above query to troubleshoot and i've already pulled my hair out.&lt;/P&gt;

&lt;P&gt;I can see that line 4 is not required but this always returns 0. Let's say TotalA is 100 &amp;amp; TotalSuccess  is 10 I would expect the output to = 10% or at least 10.&lt;/P&gt;

&lt;P&gt;Am I missing something simple?&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 16:33:06 GMT</pubDate>
    <dc:creator>rob3770</dc:creator>
    <dc:date>2018-02-01T16:33:06Z</dc:date>
    <item>
      <title>Adding 2 searches together sounds easy</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353438#M163182</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=ABC source="ABC"   ServiceName=ABC  |  
stats distinct_count(CorrelationId) as TotalA | 
appendcols [search  "TokenStatus=*Success*" ServiceName=ABC | stats distinct_count(CorrelationId) as TotalSuccess ]| 
appendcols [search TokenSubStatus=*error* ServiceName=ABC | stats distinct_count(CorrelationId) as TotalFailure ]| 
eval Total=(TotalSuccess*100)/TotalA | fields Total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have been given the above query to troubleshoot and i've already pulled my hair out.&lt;/P&gt;

&lt;P&gt;I can see that line 4 is not required but this always returns 0. Let's say TotalA is 100 &amp;amp; TotalSuccess  is 10 I would expect the output to = 10% or at least 10.&lt;/P&gt;

&lt;P&gt;Am I missing something simple?&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 16:33:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353438#M163182</guid>
      <dc:creator>rob3770</dc:creator>
      <dc:date>2018-02-01T16:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Adding 2 searches together sounds easy</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353439#M163183</link>
      <description>&lt;P&gt;@rob3770, can you post the code with &lt;CODE&gt;code button (101010)&lt;/CODE&gt; so that special characters do not escape?&lt;BR /&gt;
Also are the &lt;CODE&gt;index and source&lt;/CODE&gt; same for the sub-searches used in appendcols? and What is the current output of your query?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:01:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353439#M163183</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-02-01T17:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Adding 2 searches together sounds easy</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353440#M163184</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=ABC source="E:\\Logfiles\\OneClick\\Operations.log"   ServiceName=DEF  |  
stats distinct_count(CorrelationId) as TotalA | 
appendcols [search  "TokenStatus=*Success*" ServiceName=DEF | stats distinct_count(CorrelationId) as TotalSuccess ]| 
appendcols [search TokenSubStatus=*error* ServiceName=DEF | stats distinct_count(CorrelationId) as TotalFailure ]| 
eval Total=(TotalSuccess*100)/TotalA | fields Total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hi i have added the query as requested&lt;BR /&gt;
I have amended the index and sources for security but the sources are all the same&lt;BR /&gt;
The output is always 0&lt;/P&gt;

&lt;P&gt;I have tried &lt;STRONG&gt;&lt;EM&gt;eval Total=(TotalSuccess+100)/TotalA | fields Total&lt;/EM&gt;&lt;/STRONG&gt; and get 100&lt;/P&gt;

&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:09:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353440#M163184</guid>
      <dc:creator>rob3770</dc:creator>
      <dc:date>2018-02-01T17:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Adding 2 searches together sounds easy</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353441#M163185</link>
      <description>&lt;P&gt;Try this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=ABC source="E:\\Logfiles\\OneClick\\Operations.log"   ServiceName=DEF  
| eval Success=if(match(TokenStatus,"Success"),CorrelationId,null())
| eval Failure=if(match(TokenStatus,"error"),CorrelationId,null())
|  stats dc(CorrelationId) as TotalA  dc(Success) as TotalSuccess dc(Failure) as TotalFailure
| eval Total=(TotalSuccess*100)/TotalA | fields Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:24:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353441#M163185</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-01T17:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Adding 2 searches together sounds easy</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353442#M163186</link>
      <description>&lt;P&gt;How about this way:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=ABC ("TokenStatus=Success" OR TokenSubStatus=error) ServiceName=ABC 
| eval TotalSuccess = if(TokenStatus=Success,1,0)
| eval TotalFailure = if(TokenSubStatus=error,1,0)
| stats 
count as TotalA
sum(TotalSuccess) as TotalSuccess
sum(TotalFailure) as TotalFailure
| eval Total=(TotalSuccess*100)/TotalA | table Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:41:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353442#M163186</guid>
      <dc:creator>felipesewaybric</dc:creator>
      <dc:date>2018-02-01T17:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Adding 2 searches together sounds easy</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353443#M163187</link>
      <description>&lt;P&gt;Hi, both your queries are returning 0&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:42:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353443#M163187</guid>
      <dc:creator>rob3770</dc:creator>
      <dc:date>2018-02-01T17:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding 2 searches together sounds easy</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353444#M163188</link>
      <description>&lt;P&gt;try this one, if istill return zero, try the first line only, then 1,2 and 3 together, then 1 to 7&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=ABC ("TokenStatus=Success" OR TokenSubStatus=error) ServiceName=ABC 
 | eval TotalSuccess = if(TokenStatus=Success,1,0)
 | eval TotalFailure = if(TokenSubStatus=error,1,0)
 | stats 
 count as TotalA
 sum(TotalSuccess) as TotalSuccess
 sum(TotalFailure) as TotalFailure
 | eval Total=(TotalSuccess*100)/TotalA | table Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:50:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353444#M163188</guid>
      <dc:creator>felipesewaybric</dc:creator>
      <dc:date>2018-02-01T17:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Adding 2 searches together sounds easy</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353445#M163189</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=wpap source="E:\\Logfiles\\OneClick\\Operations.log" ("TokenStatus=*Success*") ServiceName=BILLDESK 
| eval TotalSuccess = if(TokenStatus=Success,1,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This provides the correct number of successes, the line concerning failures is a red herring and was left over by the original person.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stats distinct_count(CorrelationId) as TotalA | 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the line which counts the number of unique ID's and should be used in the calculation against the Success number (ID*100/Success)&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 22:28:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-2-searches-together-sounds-easy/m-p/353445#M163189</guid>
      <dc:creator>rob3770</dc:creator>
      <dc:date>2018-02-01T22:28:16Z</dc:date>
    </item>
  </channel>
</rss>

