<?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: Using eval to Add Field for top Result in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-eval-to-Add-Field-for-top-Result/m-p/618092#M214820</link>
    <description>&lt;P&gt;Is this what you're after?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source="tutorialdata.zip*"
| eval X_{action}=action
| stats count as total count(X_*) as X_* by itemId
| sort - total
| head 5
| rename X_* as *
| fields - total&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That will give you 5 rows of the most frequent itemId and then each column is a count of actions&lt;/P&gt;&lt;P&gt;Note the X_ prefix to the new field created is to allow the use of wildcards in the stats command to only collect the fields you're interested in.&lt;/P&gt;&lt;P&gt;You could also replace the eval/stats with&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval X_{action}=1
| stats count as total sum(X_*) as X_* by itemId&lt;/LI-CODE&gt;&lt;P&gt;which may be slightly more efficient&lt;/P&gt;</description>
    <pubDate>Mon, 24 Oct 2022 00:41:27 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2022-10-24T00:41:27Z</dc:date>
    <item>
      <title>Using eval to Add Field for top Result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-eval-to-Add-Field-for-top-Result/m-p/618091#M214819</link>
      <description>&lt;P&gt;I need to create a new field to assign to the &lt;STRONG&gt;top&lt;/STRONG&gt; results of a command using &lt;STRONG&gt;eval&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously this syntax doesn't work, so I'm looking for the correct query:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;source="tutorialdata.zip*" | eval popular = top limit=5 itemId | stats count(action) by popular, action&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Basically I only need the &lt;STRONG&gt;action&lt;/STRONG&gt;&amp;nbsp;stats of the top 5 itemId results of the following:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-10-23 at 7.43.46 PM.png" style="width: 889px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/22123i687346FB7B58FAB6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2022-10-23 at 7.43.46 PM.png" alt="Screen Shot 2022-10-23 at 7.43.46 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for the n00b question; I am just getting started with Splunk. Thanks for your time!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 13:21:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-eval-to-Add-Field-for-top-Result/m-p/618091#M214819</guid>
      <dc:creator>splunkyphil</dc:creator>
      <dc:date>2022-10-24T13:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using eval to Add Field for top Result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-eval-to-Add-Field-for-top-Result/m-p/618092#M214820</link>
      <description>&lt;P&gt;Is this what you're after?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source="tutorialdata.zip*"
| eval X_{action}=action
| stats count as total count(X_*) as X_* by itemId
| sort - total
| head 5
| rename X_* as *
| fields - total&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That will give you 5 rows of the most frequent itemId and then each column is a count of actions&lt;/P&gt;&lt;P&gt;Note the X_ prefix to the new field created is to allow the use of wildcards in the stats command to only collect the fields you're interested in.&lt;/P&gt;&lt;P&gt;You could also replace the eval/stats with&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval X_{action}=1
| stats count as total sum(X_*) as X_* by itemId&lt;/LI-CODE&gt;&lt;P&gt;which may be slightly more efficient&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 00:41:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-eval-to-Add-Field-for-top-Result/m-p/618092#M214820</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-10-24T00:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using eval to Add Field for top Result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-eval-to-Add-Field-for-top-Result/m-p/618097#M214823</link>
      <description>&lt;P&gt;This works; thank you kindly!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 04:05:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-eval-to-Add-Field-for-top-Result/m-p/618097#M214823</guid>
      <dc:creator>splunkyphil</dc:creator>
      <dc:date>2022-10-24T04:05:01Z</dc:date>
    </item>
  </channel>
</rss>

