<?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 How do I stats both the `latest()` and `values()` of a multi-value field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-stats-both-the-latest-and-values-of-a-multi-value-field/m-p/432833#M123666</link>
    <description>&lt;P&gt;I am trying to get both &lt;CODE&gt;latest()&lt;/CODE&gt; and &lt;CODE&gt;values()&lt;/CODE&gt; of a multivalue field. I am sending the field to Splunk as a comma-separated list of IDs. So, for a single event, I would get  &lt;CODE&gt;4,5,24&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;In  &lt;CODE&gt;props.conf&lt;/CODE&gt;, I create a multi-value field so I can use a CSV lookup from the field without having to split it in each search" &lt;CODE&gt;EVAL-mv_id=split(id,",")&lt;/CODE&gt; . Then, at search time, I can do the lookup: &lt;CODE&gt;lookup cat_id.csv mv_id output catname&lt;/CODE&gt;, which gives me a multi-value with 3 values for &lt;CODE&gt;catname&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;However, when I do &lt;CODE&gt;| stats latest(mv_id) AS mv_id latest(catname) AS catname BY group&lt;/CODE&gt;, only one of the values are returned, so I only get &lt;CODE&gt;4&lt;/CODE&gt; and a single &lt;CODE&gt;catname&lt;/CODE&gt;, although &lt;CODE&gt;4&lt;/CODE&gt;, &lt;CODE&gt;5&lt;/CODE&gt;, and &lt;CODE&gt;24&lt;/CODE&gt; are all from the same event and were sent at the same time. This is a problem for me because I want both the multi-value &lt;CODE&gt;latest(catname)&lt;/CODE&gt; and &lt;CODE&gt;values(catname)&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I realize I could do the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats latest(id) AS latest_id values(id) AS values_id BY group
| eval  mv_id=split(latest_id,","), values_id=split(values_id,",")
| lookup cat_id.csv mv_id OUTPUT catname
| rename catname AS latest_catname, values_id AS mv_id
| lookup cat_id.csv mv_id OUTPUT catname
| rename catname as values_catname
| table latest_catname values_catname group
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That just seems unnecessarily complicated to me, especially since the latest ID truly is a multi-value. Is there a better way to do this? Is there something I'm missing in the &lt;CODE&gt;props.conf&lt;/CODE&gt; &lt;CODE&gt;EVAL&lt;/CODE&gt; or elsewhere?&lt;/P&gt;</description>
    <pubDate>Mon, 22 Oct 2018 20:56:12 GMT</pubDate>
    <dc:creator>camillak</dc:creator>
    <dc:date>2018-10-22T20:56:12Z</dc:date>
    <item>
      <title>How do I stats both the `latest()` and `values()` of a multi-value field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-stats-both-the-latest-and-values-of-a-multi-value-field/m-p/432833#M123666</link>
      <description>&lt;P&gt;I am trying to get both &lt;CODE&gt;latest()&lt;/CODE&gt; and &lt;CODE&gt;values()&lt;/CODE&gt; of a multivalue field. I am sending the field to Splunk as a comma-separated list of IDs. So, for a single event, I would get  &lt;CODE&gt;4,5,24&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;In  &lt;CODE&gt;props.conf&lt;/CODE&gt;, I create a multi-value field so I can use a CSV lookup from the field without having to split it in each search" &lt;CODE&gt;EVAL-mv_id=split(id,",")&lt;/CODE&gt; . Then, at search time, I can do the lookup: &lt;CODE&gt;lookup cat_id.csv mv_id output catname&lt;/CODE&gt;, which gives me a multi-value with 3 values for &lt;CODE&gt;catname&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;However, when I do &lt;CODE&gt;| stats latest(mv_id) AS mv_id latest(catname) AS catname BY group&lt;/CODE&gt;, only one of the values are returned, so I only get &lt;CODE&gt;4&lt;/CODE&gt; and a single &lt;CODE&gt;catname&lt;/CODE&gt;, although &lt;CODE&gt;4&lt;/CODE&gt;, &lt;CODE&gt;5&lt;/CODE&gt;, and &lt;CODE&gt;24&lt;/CODE&gt; are all from the same event and were sent at the same time. This is a problem for me because I want both the multi-value &lt;CODE&gt;latest(catname)&lt;/CODE&gt; and &lt;CODE&gt;values(catname)&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I realize I could do the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats latest(id) AS latest_id values(id) AS values_id BY group
| eval  mv_id=split(latest_id,","), values_id=split(values_id,",")
| lookup cat_id.csv mv_id OUTPUT catname
| rename catname AS latest_catname, values_id AS mv_id
| lookup cat_id.csv mv_id OUTPUT catname
| rename catname as values_catname
| table latest_catname values_catname group
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That just seems unnecessarily complicated to me, especially since the latest ID truly is a multi-value. Is there a better way to do this? Is there something I'm missing in the &lt;CODE&gt;props.conf&lt;/CODE&gt; &lt;CODE&gt;EVAL&lt;/CODE&gt; or elsewhere?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 20:56:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-stats-both-the-latest-and-values-of-a-multi-value-field/m-p/432833#M123666</guid>
      <dc:creator>camillak</dc:creator>
      <dc:date>2018-10-22T20:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I stats both the `latest()` and `values()` of a multi-value field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-stats-both-the-latest-and-values-of-a-multi-value-field/m-p/432834#M123667</link>
      <description>&lt;P&gt;Here's an example of one method... &lt;/P&gt;

&lt;P&gt;Try...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your search 
your lookup 
| eval catnamejoined=mvjoin(catname,"!!!!"), 
| stats latest(catnamejoined) as latest_catname values(catname) as all_catname by group
| makemv delim="!!!!" latest_catname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use the same three-step strategy with mv_id: flatten, use the flat one for latest, then unflatten.&lt;/P&gt;

&lt;P&gt;We use "!!!!" since it hardly ever appears in normal data.    &lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 21:36:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-stats-both-the-latest-and-values-of-a-multi-value-field/m-p/432834#M123667</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-10-26T21:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I stats both the `latest()` and `values()` of a multi-value field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-stats-both-the-latest-and-values-of-a-multi-value-field/m-p/432835#M123668</link>
      <description>&lt;P&gt;You will have to collapse the values back into a single-value by using &lt;CODE&gt;nomv&lt;/CODE&gt; or &lt;CODE&gt;mvjoin&lt;/CODE&gt; and use that collapsed field instead.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 15:01:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-stats-both-the-latest-and-values-of-a-multi-value-field/m-p/432835#M123668</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-10-31T15:01:40Z</dc:date>
    </item>
  </channel>
</rss>

