<?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: Get first value of a field after filtering its row out in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Get-first-value-of-a-field-after-filtering-its-row-out/m-p/711908#M240259</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It worked perfectly!&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you so much&lt;/P&gt;</description>
    <pubDate>Tue, 18 Feb 2025 11:57:06 GMT</pubDate>
    <dc:creator>pedropiin</dc:creator>
    <dc:date>2025-02-18T11:57:06Z</dc:date>
    <item>
      <title>Get first value of a field after filtering its row out</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-first-value-of-a-field-after-filtering-its-row-out/m-p/711883#M240250</link>
      <description>&lt;P&gt;Hi everyone.&lt;BR /&gt;&lt;BR /&gt;I'm really new to Splunk, so I'm confused with what seems to be a simple problem.&amp;nbsp;&lt;BR /&gt;I'm using "where row_num &amp;gt; 1" to remove the first row of my search, as I need to calculate lots of metrics based on the whole data without this specific first row. But I'm also supposed to show the value of this first row in a specific field.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;My query is of the following structure:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;my_search...
| eval val1=...
| sort val1
| streamstats count as row_num
| where row_num &amp;gt; 1
| stats avg(...) as metric1,
  max(...) as metric2,
  count(...) as metric3
...
| fields metric1, metric2, metric3&lt;/LI-CODE&gt;&lt;P&gt;But I also need to output the value 'x' that is specifically on field 'y' on row 1.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;How would I do this?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 19:01:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-first-value-of-a-field-after-filtering-its-row-out/m-p/711883#M240250</guid>
      <dc:creator>pedropiin</dc:creator>
      <dc:date>2025-02-17T19:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Get first value of a field after filtering its row out</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-first-value-of-a-field-after-filtering-its-row-out/m-p/711888#M240254</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/276496"&gt;@pedropiin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im not 100% sure if I'm on the right page...but nevertheless have a look to see if this helps you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Ive used some sample data inline to help build out a working query for you to work with.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw = "[{\"name\":\"SampleMetric\",\"metric\":\"42\",\"xfield\":\"Mickey Mouse\"},{\"name\":\"SampleMetric\",\"metric\":\"17\",\"xfield\":\"Donald Duck\"},{\"name\":\"SampleMetric\",\"metric\":\"36\",\"xfield\":\"Goofy\"},{\"name\":\"SampleMetric\",\"metric\":\"29\",\"xfield\":\"Minnie Mouse\"},{\"name\":\"SampleMetric\",\"metric\":\"48\",\"xfield\":\"Pluto\"}]" 
| eval events=json_array_to_mv(_raw) 
| mvexpand events 
| eval _raw=events 
| fields _raw 
| spath 
| table name metric xfield
    ``` Sample data Prep work complete ``` 
| sort metric 
| streamstats count as row_num 
| eval xfield=IF(row_num==1,xfield,NULL()) 
| filldown xfield 
| where row_num &amp;gt; 1 
| stats values(xfield) as xfield,
    avg(metric) as metric1,
    max(metric) as metric2,
    count(metric) as metric3 
| fields xfield metric1, metric2, metric3&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="livehybrid_0-1739828929560.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34606i2D2EA13FA8BBD117/image-size/medium?v=v2&amp;amp;px=400" role="button" title="livehybrid_0-1739828929560.png" alt="livehybrid_0-1739828929560.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please let me know how you get on and consider accepting this answer or adding karma this answer if it has helped.&lt;BR /&gt;Regards&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 21:49:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-first-value-of-a-field-after-filtering-its-row-out/m-p/711888#M240254</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-02-17T21:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Get first value of a field after filtering its row out</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-first-value-of-a-field-after-filtering-its-row-out/m-p/711908#M240259</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It worked perfectly!&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you so much&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 11:57:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-first-value-of-a-field-after-filtering-its-row-out/m-p/711908#M240259</guid>
      <dc:creator>pedropiin</dc:creator>
      <dc:date>2025-02-18T11:57:06Z</dc:date>
    </item>
  </channel>
</rss>

