<?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: multiple eval and count in the pipe in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191067#M54981</link>
    <description>&lt;P&gt;so how many faces does have "count" ? &lt;BR /&gt;
a) in case:&lt;BR /&gt;
| eval count (Field1) as X&lt;/P&gt;

&lt;P&gt;X will have count number of of Field1, right ?&lt;/P&gt;

&lt;P&gt;b) in case:&lt;BR /&gt;
| eval count (eval(Field1="something")) as X&lt;BR /&gt;
will this work ? Is having eval-count-eval order allowed ?&lt;/P&gt;

&lt;P&gt;c) in case:&lt;BR /&gt;
| stats count by Field1&lt;BR /&gt;
no new field will be produced right ? But we could in the next pipe use "count" as variable, right ?&lt;BR /&gt;
e.g.&lt;BR /&gt;
| stats count by Field1 | eval Add_Status=if(count &amp;gt; 0,"PASS","FAIL")&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jan 2015 15:52:42 GMT</pubDate>
    <dc:creator>milande</dc:creator>
    <dc:date>2015-01-23T15:52:42Z</dc:date>
    <item>
      <title>multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191062#M54976</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a table with header line like:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;stepName          stepStatus    time&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;additional_sub_4        PASS               today&lt;BR /&gt;&lt;BR /&gt;
additional_sub_3        FAIL                today&lt;BR /&gt;
wrong_sub_4             FAIL                today&lt;BR /&gt;
wrong_sub_3             PASS               today&lt;BR /&gt;
...&lt;BR /&gt;
additional_sub_4        FAIL                yesterday&lt;BR /&gt;
additional_sub_3        FAIL                yesterday&lt;BR /&gt;
wrong_sub_4             PASS               yesterday&lt;BR /&gt;
wrong_sub_3             PASS               yesterday&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;I need to draw a chart with two lines &lt;STRONG&gt;Add_Status&lt;/STRONG&gt;, &lt;STRONG&gt;Wrg_Status&lt;/STRONG&gt; which would have values of PASS or FAIL over the time. So, &lt;STRONG&gt;Add_Status&lt;/STRONG&gt; would have value &lt;STRONG&gt;PASS&lt;/STRONG&gt; is at least one &lt;STRONG&gt;stepName&lt;/STRONG&gt;(additional_sub_4 or additional_sub_3) is PASS, otherwise FAIL. The same holds for the chart of values &lt;STRONG&gt;Wrg_Status&lt;/STRONG&gt; over the time. My search string looks like:&lt;/P&gt;

&lt;P&gt;... |  eval testLogic=case(&lt;BR /&gt;
 LIKE(stepName,"additional_sub_%") AND stepStatus="PASS", "ADD_PASS",&lt;BR /&gt;
 LIKE(stepName,"wrong_sub_%") AND stepStatus="PASS", "WRG_PASS") |&lt;BR /&gt;
 eval Add_Count = count(testLogic="ADD_PASS") , Wrg_Count = count(testLogic="WRG_PASS") | &lt;BR /&gt;
 eval Add_Status=if(Add_Count&amp;gt;0,"PASS","FAIL"), Wrg_Status=if(Add_Count&amp;gt;0,"PASS","FAIL") |&lt;BR /&gt;
 chart Add_Status, Wrg_Status by _time&lt;/P&gt;

&lt;P&gt;to describe step by step what I am doing:&lt;BR /&gt;
... |  eval testLogic=case(&lt;BR /&gt;
 LIKE(stepName,"additional_sub_%") AND stepStatus="PASS", "ADD_PASS",&lt;BR /&gt;
 LIKE(stepName,"wrong_sub_%") AND stepStatus="PASS", "WRG_PASS") &lt;/P&gt;

&lt;P&gt;(here I get into field &lt;STRONG&gt;testLogic&lt;/STRONG&gt; all events which are PASS and belongs to one of two &lt;STRONG&gt;stepName&lt;/STRONG&gt;)&lt;/P&gt;

&lt;TABLE&gt;&lt;THEAD&gt;
&lt;TR&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;&lt;TBODY&gt;
&lt;/TBODY&gt;&lt;/TABLE&gt;

&lt;P&gt;(here I count number of "PASS"es, max is 2 min is 0 )&lt;/P&gt;

&lt;TABLE&gt;&lt;THEAD&gt;
&lt;TR&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;&lt;TBODY&gt;
&lt;/TBODY&gt;&lt;/TABLE&gt;

&lt;P&gt;(here I check if count is more then zero or not)&lt;/P&gt;

&lt;TABLE&gt;&lt;THEAD&gt;
&lt;TR&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;&lt;TBODY&gt;
&lt;/TBODY&gt;&lt;/TABLE&gt;

&lt;P&gt;(here I expect to get over the time chart if at least one &lt;STRONG&gt;stepName&lt;/STRONG&gt; &lt;STRONG&gt;additional_sub_?&lt;/STRONG&gt; or &lt;STRONG&gt;wrong_sub_?&lt;/STRONG&gt; was having stepStatus PASS or not)&lt;/P&gt;

&lt;P&gt;But it produce a lot of errors starting with:&lt;BR /&gt;
Error in 'eval' command: The operator at ', Wrg_Count = count(testLogic="WRG_PASS")' is invalid. &lt;BR /&gt;
so I am wondering what I am all doing wrong ?&lt;/P&gt;

&lt;P&gt;regards,&lt;BR /&gt;
Milan&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:40:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191062#M54976</guid>
      <dc:creator>milande</dc:creator>
      <dc:date>2020-09-28T18:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191063#M54977</link>
      <description>&lt;P&gt;hi milande,&lt;BR /&gt;
trying to write this &lt;CODE&gt;Wrg_Count = count( eval(testLogic="WRG_PASS") )'&lt;/CODE&gt; to see if y 'will always be an error message&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 14:26:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191063#M54977</guid>
      <dc:creator>gyslainlatsa</dc:creator>
      <dc:date>2015-01-23T14:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191064#M54978</link>
      <description>&lt;P&gt;Simply, &lt;CODE&gt;count&lt;/CODE&gt; is not an &lt;CODE&gt;eval&lt;/CODE&gt; function. &lt;CODE&gt;eval&lt;/CODE&gt; is for creating or modifying fields in each record. If you want to actually count things, you need to use something like &lt;CODE&gt;stats&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;So something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... 
| eval testLogic=...your logic above...
| stats count by testLogic time
| eval Add_Status=if(testLogic="ADD_PASS",if(count &amp;gt; 0,"PASS","FAIL"),"")
| eval Wrg_Status=if(testLogic="WRG_PASS",if(count &amp;gt; 0,"PASS","FAIL"),"")
| chart first(Add_Status) first(Wrg_Status) by time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You have a &lt;CODE&gt;time&lt;/CODE&gt; field already, so you should use that instead of whatever time Splunk is assigning to your event. Also, you can't use &lt;CODE&gt;chart&lt;/CODE&gt; with just values, you have to apply a function to the grouping that you generate with the &lt;CODE&gt;by&lt;/CODE&gt; clause; you can use &lt;CODE&gt;first&lt;/CODE&gt; since your grouping should guarantee a unique value there.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 14:30:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191064#M54978</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2015-01-23T14:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191065#M54979</link>
      <description>&lt;P&gt;The issue at hand I think is an understanding of the differences between &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.1/SearchReference/eval"&gt;eval&lt;/A&gt; and &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.1/SearchReference/chart"&gt;chart&lt;/A&gt;. eval lets you assign a value to a new field on each result (row / record) based on values of other fields in each result and &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.1/SearchReference/CommonEvalFunctions"&gt;functions applied to the same&lt;/A&gt;. Because eval works on a row by row basis, attempting to count the number of times a field is a certain value across all records isn't possible with the eval function. Additionally, eval only sets the value of a single field at a time. If you want to set multiple values you need multiple eval statements&lt;/P&gt;

&lt;P&gt;Stats (and other functions) on the other hand lets you apply &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.1/SearchReference/CommonStatsFunctions"&gt;statistical functions&lt;/A&gt; across all records in your record set, including but not limited to &lt;CODE&gt;count(eval(testLogic=="ADD_PASS")) as Add_Count&lt;/CODE&gt; for example. You can calculate these statistics across the record set as a whole (the default) or you can add a &lt;CODE&gt;by&lt;/CODE&gt; clause to group over a set of other fields with the same corresponding value set for those fields allowing you to answer questions that require such division.  &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.1/SearchReference/chart"&gt;chart&lt;/A&gt; is the same as stats but it let's you group by only two fields instead of arbitrarily many. The reason for this is to help you setup a visual chart with multiple series of statistics &lt;CODE&gt;over&lt;/CODE&gt; a field containing the x-axis values. As bucketed time windows is often the preferred x-axis when it comes to data in Splunk, the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.1/SearchReference/timechart"&gt;timechart&lt;/A&gt; command is the chart command where the x-axis is simply the _time field, divided into buckets (every day, hour, minute, etc).&lt;/P&gt;

&lt;P&gt;Now with the basics out of the way let's look at your data. For this, I'm assuming that everything before the first underscore is a parent job identifier and that &lt;CODE&gt;time&lt;/CODE&gt; is discrete strings as is in your question. So if we do &lt;CODE&gt;base search to retrieve data | rex field=stepName "^(?[^_]+)_" | stats count(eval(stepStatus=="PASS")) as nPass by time,parentId | eval nPass=if(nPass&amp;gt;0,1,0) | chart max(nPass) by parentId over time&lt;/CODE&gt; this begins to get us an approximation of what you are looking for. If time is actually &lt;CODE&gt;_time&lt;/CODE&gt; and a Unix time stamp value instead of a discrete string, the above will change as you'll need to solve bucketing issues (for example do I have 1 or multiple runs of my overall job in my bucket,if multiple pass is that 1 or potentially 2?). also think should a partial success be counted differently or not. But I leave that as an exercise to you dear asker, and hope this early morning explanation helps&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 14:52:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191065#M54979</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-01-23T14:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191066#M54980</link>
      <description>&lt;P&gt;That will always be an error. In an eval like command, count is not a function, in a stats like command you use an &lt;CODE&gt;as&lt;/CODE&gt; clause to rename the field not &lt;CODE&gt;=&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 14:56:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191066#M54980</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-01-23T14:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191067#M54981</link>
      <description>&lt;P&gt;so how many faces does have "count" ? &lt;BR /&gt;
a) in case:&lt;BR /&gt;
| eval count (Field1) as X&lt;/P&gt;

&lt;P&gt;X will have count number of of Field1, right ?&lt;/P&gt;

&lt;P&gt;b) in case:&lt;BR /&gt;
| eval count (eval(Field1="something")) as X&lt;BR /&gt;
will this work ? Is having eval-count-eval order allowed ?&lt;/P&gt;

&lt;P&gt;c) in case:&lt;BR /&gt;
| stats count by Field1&lt;BR /&gt;
no new field will be produced right ? But we could in the next pipe use "count" as variable, right ?&lt;BR /&gt;
e.g.&lt;BR /&gt;
| stats count by Field1 | eval Add_Status=if(count &amp;gt; 0,"PASS","FAIL")&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 15:52:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191067#M54981</guid>
      <dc:creator>milande</dc:creator>
      <dc:date>2015-01-23T15:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191068#M54982</link>
      <description>&lt;P&gt;As @acharlieh and I explained, cases (a) and (b) are syntax errors. &lt;CODE&gt;count&lt;/CODE&gt; is not a function you can use with &lt;CODE&gt;eval&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;If you want a new field &lt;CODE&gt;X&lt;/CODE&gt; to be added to each event that contains the total count of whatever you're counting, you need to use &lt;CODE&gt;eventstats&lt;/CODE&gt; for that. Read here: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.1/SearchReference/Eventstats"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.1/SearchReference/Eventstats&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Case (c) returns a table with two fields, &lt;CODE&gt;Field1&lt;/CODE&gt; and &lt;CODE&gt;count&lt;/CODE&gt;. All your other data is gone at that point. You can use &lt;CODE&gt;count&lt;/CODE&gt; in the next pipe, though.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2015 15:57:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191068#M54982</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2015-01-23T15:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191069#M54983</link>
      <description>&lt;P&gt;Hi aweitzman,&lt;BR /&gt;
your suggestion seems to work up to the last line:&lt;BR /&gt;
| chart first(Add_Status) first(Wrg_Status) by time&lt;BR /&gt;
as the &lt;STRONG&gt;Add_Status&lt;/STRONG&gt; and &lt;STRONG&gt;Wrg_Status&lt;/STRONG&gt; are strings chart seems to have problem in drawing "PASS/FAIL" points on Y axis. How to make chart draw "PASS/FAIL" values  ?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:44:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191069#M54983</guid>
      <dc:creator>milande</dc:creator>
      <dc:date>2020-09-28T18:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191070#M54984</link>
      <description>&lt;P&gt;In this case, &lt;CODE&gt;chart&lt;/CODE&gt; will get you a useful table, but because your values are not numeric, you cannot turn your result into a graph. &lt;/P&gt;</description>
      <pubDate>Tue, 27 Jan 2015 13:29:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191070#M54984</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2015-01-27T13:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191071#M54985</link>
      <description>&lt;P&gt;so is there any other option to bring to the Y axis non numerical values ?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jan 2015 14:24:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191071#M54985</guid>
      <dc:creator>milande</dc:creator>
      <dc:date>2015-01-27T14:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: multiple eval and count in the pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191072#M54986</link>
      <description>&lt;P&gt;so having diagrams with some other categories (beside the numbers) is not possible at all in SPLUNK ?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jan 2015 10:15:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/multiple-eval-and-count-in-the-pipe/m-p/191072#M54986</guid>
      <dc:creator>milande</dc:creator>
      <dc:date>2015-01-28T10:15:49Z</dc:date>
    </item>
  </channel>
</rss>

