<?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: eval command after stats command not working in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304102#M91458</link>
    <description>&lt;P&gt;@jvmerilla, any reason for going after string format for comma separation on a percent field? Do you think your percent value can shoot up/down by 1000% or more which might show it as 1,000%?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval "Proficiency Composition" = tostring((count/Total)*100,"commas")."%"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Normally, we round off using &lt;CODE&gt;round()&lt;/CODE&gt; function to digits of precision based on our needs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval "Proficiency Composition" = round((count/Total)*100,2)."%"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Above rounds the percent to 2 digits of precision and adds  &lt;CODE&gt;%&lt;/CODE&gt; after the value.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2017 06:13:14 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-11-27T06:13:14Z</dc:date>
    <item>
      <title>eval command after stats command not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304096#M91452</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm having a problem with this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="pcmm" "Technical Proficiency"!=NA 
| stats count("Resource Name") as count by "Technical Proficiency"
| eval count = count
| appendpipe
    [stats sum(count) as Total]
| eval Total = Total
| eval "Proficiency Composition" = tostring((count/Total)*100,"commas")."%"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I'm trying to do here is to use the eval command to make a calculation with the "count" and "Total" field and put the result in the new field named "Proficiency Composition". But it seems that the eval command doesn't work since the result does not return the new field.&lt;/P&gt;

&lt;P&gt;Here's the result when I run the query:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3910i16160FBF352CC029/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;What could be the problem here?&lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 05:01:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304096#M91452</guid>
      <dc:creator>jvmerilla</dc:creator>
      <dc:date>2017-11-27T05:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: eval command after stats command not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304097#M91453</link>
      <description>&lt;P&gt;Hi &lt;BR /&gt;
Can you please try this one ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="pcmm" "Technical Proficiency"!=NA 
| stats count("Resource Name") as count by "Technical Proficiency"
| eventstats sum(count) as Total
| eval "Proficiency Composition" = tostring((count/Total)*100,"commas")."%"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Happy Splunking&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 05:18:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304097#M91453</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-27T05:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: eval command after stats command not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304098#M91454</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;It works! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;

&lt;P&gt;But you can explain to me how this works and why my search query doesn't?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 05:24:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304098#M91454</guid>
      <dc:creator>jvmerilla</dc:creator>
      <dc:date>2017-11-27T05:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: eval command after stats command not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304099#M91455</link>
      <description>&lt;P&gt;Hi @jvmerilla,&lt;/P&gt;

&lt;P&gt;Yes,&lt;/P&gt;

&lt;P&gt;1) In your search, you mentioned &lt;CODE&gt;| eval count = count&lt;/CODE&gt;, actually it does not make any sense. Bcoz It is assigning the same value to same field (count = count).&lt;/P&gt;

&lt;P&gt;2) &lt;CODE&gt;| appendpipe [stats sum(count) as Total]&lt;/CODE&gt;, this will create a new row with &lt;CODE&gt;Total&lt;/CODE&gt; column. So I have replaced it with &lt;CODE&gt;| eventstats sum(count) as Total&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;3) &lt;CODE&gt;| eval Total = Total&lt;/CODE&gt;, again same, assigning the same value to same field&lt;/P&gt;

&lt;P&gt;4) &lt;CODE&gt;| eval "Proficiency Composition" = tostring((count/Total)*100,"commas")."%"&lt;/CODE&gt; , this will work if &lt;CODE&gt;Total&lt;/CODE&gt; field is available for all rows. due to (2nd) reason. The replacement will give you &lt;CODE&gt;Total&lt;/CODE&gt; field for all rows and your eval works well.&lt;/P&gt;

&lt;P&gt;I hope this will help you.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;!!! Happy Splunking !!!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 05:42:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304099#M91455</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-27T05:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: eval command after stats command not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304100#M91456</link>
      <description>&lt;P&gt;Hi @kamlesh_vaghela,&lt;/P&gt;

&lt;P&gt;Thanks for the clarification!&lt;/P&gt;

&lt;P&gt;I get it now.&lt;/P&gt;

&lt;P&gt;Thank you again! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 05:48:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304100#M91456</guid>
      <dc:creator>jvmerilla</dc:creator>
      <dc:date>2017-11-27T05:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: eval command after stats command not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304101#M91457</link>
      <description>&lt;P&gt;Hi @jvmerilla,&lt;/P&gt;

&lt;P&gt;Glad to help you. Please upvote my comments which help you.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 05:49:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304101#M91457</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-27T05:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: eval command after stats command not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304102#M91458</link>
      <description>&lt;P&gt;@jvmerilla, any reason for going after string format for comma separation on a percent field? Do you think your percent value can shoot up/down by 1000% or more which might show it as 1,000%?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval "Proficiency Composition" = tostring((count/Total)*100,"commas")."%"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Normally, we round off using &lt;CODE&gt;round()&lt;/CODE&gt; function to digits of precision based on our needs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval "Proficiency Composition" = round((count/Total)*100,2)."%"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Above rounds the percent to 2 digits of precision and adds  &lt;CODE&gt;%&lt;/CODE&gt; after the value.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 06:13:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304102#M91458</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-27T06:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: eval command after stats command not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304103#M91459</link>
      <description>&lt;P&gt;@niketnilay. Agreed.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 06:15:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304103#M91459</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-27T06:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: eval command after stats command not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304104#M91460</link>
      <description>&lt;P&gt;Hi @niketnilay,&lt;BR /&gt;
Yes, you're right. I should have use the &lt;CODE&gt;round()&lt;/CODE&gt; instead of &lt;CODE&gt;tostring()&lt;/CODE&gt;.&lt;BR /&gt;
The only reason I used &lt;CODE&gt;tostring()&lt;/CODE&gt; was because I thought I need to make the value a string first before I can add the &lt;CODE&gt;%&lt;/CODE&gt;.&lt;BR /&gt;
But I realized that I was wrong about that.&lt;BR /&gt;
Thank you! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 06:19:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-command-after-stats-command-not-working/m-p/304104#M91460</guid>
      <dc:creator>jvmerilla</dc:creator>
      <dc:date>2017-11-27T06:19:55Z</dc:date>
    </item>
  </channel>
</rss>

