<?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 Why are the values showing wrong stats? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-are-the-values-showing-wrong-stats/m-p/337560#M163269</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;earliest=-32d@d | search Mode="GoNoGo"  | stats dc(source) by Number | eval A=if(source= "faulty.csv", "Fail", "Pass") | stats values(A)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Why returns &lt;CODE&gt;values(A) "Pass"&lt;/CODE&gt; for all entries and&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-32d@d | search Mode="GoNoGo"  |  eval A=if(source= "faulty.csv", "Fail", "Pass") | stats values(A)
returns "Pass" and "Fail"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Like to use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-32d@d | search Mode="GoNoGo"  | stats dc(source) by Number | eval A=if(source= "faulty.csv", "Fail", "Pass") | stats values(A) with the values "Pass" and "Fail" for A
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 29 Jan 2018 10:10:23 GMT</pubDate>
    <dc:creator>LH_SPLUNK</dc:creator>
    <dc:date>2018-01-29T10:10:23Z</dc:date>
    <item>
      <title>Why are the values showing wrong stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-the-values-showing-wrong-stats/m-p/337560#M163269</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;earliest=-32d@d | search Mode="GoNoGo"  | stats dc(source) by Number | eval A=if(source= "faulty.csv", "Fail", "Pass") | stats values(A)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Why returns &lt;CODE&gt;values(A) "Pass"&lt;/CODE&gt; for all entries and&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-32d@d | search Mode="GoNoGo"  |  eval A=if(source= "faulty.csv", "Fail", "Pass") | stats values(A)
returns "Pass" and "Fail"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Like to use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=-32d@d | search Mode="GoNoGo"  | stats dc(source) by Number | eval A=if(source= "faulty.csv", "Fail", "Pass") | stats values(A) with the values "Pass" and "Fail" for A
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jan 2018 10:10:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-the-values-showing-wrong-stats/m-p/337560#M163269</guid>
      <dc:creator>LH_SPLUNK</dc:creator>
      <dc:date>2018-01-29T10:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Why are the values showing wrong stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-the-values-showing-wrong-stats/m-p/337561#M163270</link>
      <description>&lt;P&gt;@LH_SPLUNK could you please describe what is the final output you are trying to get? Do you want to get the count of Fail and Pass? If this is so you should try the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearchWithIndexAndSourceType&amp;gt; source=* earliest=-32d@d Mode="GoNoGo" 
| stats count(eval(source="faulty.csv")) as Fail count(eval(source!="faulty.csv")) as Pass
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In your first search, once you run the stats command you are left only with the fields returned by stats i.e. &lt;CODE&gt;dc(source)&lt;/CODE&gt; and &lt;CODE&gt;Number&lt;/CODE&gt;. Hence the subsequent eval on &lt;CODE&gt;source&lt;/CODE&gt; will always be null resulting in &lt;CODE&gt;A="Pass"&lt;/CODE&gt; for all source which is the default else condition.&lt;/P&gt;

&lt;P&gt;PS: &lt;CODE&gt;| search Mode="GoNoGo"&lt;/CODE&gt; should actually be a part of your base search for query optimization (hope you have index and/or sourcetype defined in your base search.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 10:39:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-the-values-showing-wrong-stats/m-p/337561#M163270</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-01-29T10:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why are the values showing wrong stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-the-values-showing-wrong-stats/m-p/337562#M163271</link>
      <description>&lt;P&gt;Just to expand and clarify for @LH_SPLUNK, since this little nuance bit me more times than I'd like to admit when I first started using Splunk:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats dc(source) BY Number
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will leave you with two fields. Those fields will be named &lt;CODE&gt;dc(source)&lt;/CODE&gt; and &lt;CODE&gt;Number&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats dc(source) AS source BY Number
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will also leave you with two fields. Those fields will be named &lt;CODE&gt;source&lt;/CODE&gt; and &lt;CODE&gt;Number&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;So although the restructured search that @niketnilay has proposed above is a more efficient way to get the data you're seeking in this case, I thought it would be good to just be really explicit about why the search you crafted was failing. I've found it to be a best practice for me to always add an &lt;CODE&gt;AS&lt;/CODE&gt; clause when I'm using &lt;CODE&gt;stats&lt;/CODE&gt; - so all of my searches look something like this: &lt;CODE&gt;| stats dc(something) AS something, values(another_thing) AS another_thing...&lt;/CODE&gt; because of how many times I wasted energy trying to figure out where my important field went!&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 14:14:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-the-values-showing-wrong-stats/m-p/337562#M163271</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-01-29T14:14:56Z</dc:date>
    </item>
  </channel>
</rss>

