<?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: How obtain the sum of a multivalue field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269823#M81207</link>
    <description>&lt;P&gt;@cgong can you please accept my answer if that solved the issue for you?&lt;/P&gt;</description>
    <pubDate>Tue, 20 Dec 2016 14:22:01 GMT</pubDate>
    <dc:creator>rjthibod</dc:creator>
    <dc:date>2016-12-20T14:22:01Z</dc:date>
    <item>
      <title>How obtain the sum of a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269815#M81199</link>
      <description>&lt;P&gt;In each of my events, I have a field named watched. The watched multifield contains the array of integers. Is it possible to get the sum of the multivalue field? Below is the json data which gets indexed into my splunk index.&lt;/P&gt;

&lt;P&gt;I have tried the following:&lt;/P&gt;

&lt;P&gt;1] index=netbase1_index sourcetype=sv_sessions  | rename "watched{}" as vwatch | eventstats sum(vwatch) as Total | table viewer.email Total&lt;/P&gt;

&lt;H1&gt;this returns the sum, but it is the sum of all the multivalue field, watched for all the events instead of the sum of each event.&lt;/H1&gt;

&lt;P&gt;2] index=netbase1_index sourcetype=sv_sessions | rename "watched{}" as vwatch | makemv vwatch | eventstats sum(vwatch) as total | table viewer.email vwatch total&lt;/P&gt;

&lt;H1&gt;the total for each event is just blank.&lt;/H1&gt;

&lt;P&gt;3] index=netbase1_index sourcetype=sv_sessions  |spath output=total sum(path=watched{*}) | table viewer.email total&lt;/P&gt;

&lt;H1&gt;the total for each event is just blank.&lt;/H1&gt;

&lt;P&gt;{"playback_type": "html5", "url": "&lt;A href="https://nds.io/videos/a49bdeb31316e4c62c/06-analyze-a-topic" target="_blank"&gt;https://nds.io/videos/a49bdeb31316e4c62c/06-analyze-a-topic&lt;/A&gt;", "geo": {"country": "US", "region": "NY", "city": "New York"}, "video_id": "a49bdeb31316e4c62c", "viewer": {"email": "&lt;A href="mailto:email@email.com" target="_blank"&gt;email@email.com&lt;/A&gt;", "watched": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 3, 2, 2, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "ip_address": "14.9.22.41"}&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:32:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269815#M81199</guid>
      <dc:creator>cgong</dc:creator>
      <dc:date>2020-09-29T11:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: How obtain the sum of a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269816#M81200</link>
      <description>&lt;P&gt;There are a couple of things about your results that don't make sense to me, but I will try to answer regardless.&lt;/P&gt;

&lt;P&gt;For #1, I don't understand how this works if  &lt;CODE&gt;vwatch&lt;/CODE&gt; is a multi-valued field, but I will answer anyway.  If it will add them up as you suggest, then you only need to add a term to your  &lt;CODE&gt;eventstats&lt;/CODE&gt; segment that identifies the unique IDs. If there is nothing already in each event that serves as a unique ID, then the easiest thing to do is add  &lt;CODE&gt;streamstats count as count |&lt;/CODE&gt; before the  &lt;CODE&gt;eventstats&lt;/CODE&gt; pipe. The result would be &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=netbase1_index sourcetype=sv_sessions | rename "watched{}" as vwatch | streamstats count as count | eventstats sum(vwatch) as Total by count | table viewer.email Total&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;For #2, I don't understand why using  &lt;CODE&gt;mvexpand&lt;/CODE&gt; wouldn't work, but you still need to have a unique value like #1. Without seeing the raw data, my attempt would be as follows:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=netbase1_index sourcetype=sv_sessions | rename "watched{}" as vwatch | streamstats count as count | mvexpand  vwatch | stats sum(vwatch) as Total by viewer.email count | table viewer.email Total&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;For #3, I am no help.&lt;/P&gt;

&lt;P&gt;Option #4, if you plan to do a lot of searches that need, I suggest you implement a custom SPL command like I did for this exact use case.  The starting point is called  &lt;CODE&gt;mvsum&lt;/CODE&gt; (see &lt;A href="http://jordan.broughs.net/archives/2012/06/mvsum-for-splunk-summing-multi-valued-fields-within-a-single-event"&gt;http://jordan.broughs.net/archives/2012/06/mvsum-for-splunk-summing-multi-valued-fields-within-a-single-event&lt;/A&gt;).   You can rip-off my implementation straight from my app Layer8Insight App For Splunk (&lt;A href="https://splunkbase.splunk.com/app/3171/"&gt;https://splunkbase.splunk.com/app/3171/&lt;/A&gt;). It is battle tested. My app includes the configuration files and python code you would need.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2016 18:11:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269816#M81200</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2016-10-22T18:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: How obtain the sum of a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269817#M81201</link>
      <description>&lt;P&gt;While I'm not fully understanding your request either,  it appears to me that you are either:&lt;/P&gt;

&lt;P&gt;1 - Trying to get the sum of the array of numbers in the field "watched{}", which I've based off of you renaming "watched{}" as "vwatch" and applying the stats function "sum(vwatch)" as the "total". &lt;/P&gt;

&lt;P&gt;2 - My other interpretation of your request, based off your second search where you are using "makemv", is that you are trying to gather a count of how many numbers there are in the field "watched{}"&lt;/P&gt;

&lt;P&gt;If either one of my interpretations are correct for the array below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 3, 2, 2, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then I think Splunk is actually interpreting these numbers as a string rather than numbers, in which case you need to convert the string to numbers.&lt;/P&gt;

&lt;P&gt;If my first interpretation above was correct, try this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=netbase1_index sourcetype=sv_sessions | rex field=_raw "watched\"\:\s\[(?P&amp;lt;watched_numbers&amp;gt;.[^\]]*)" | eval trim_spaces=trim(split(watched_numbers,",")) | stats count by viewer_email, trim_spaces | eval convert_string = tonumber(trim_spaces) | eval product = convert_string * count | eventstats sum(product) AS watch_total | dedup watch_total | table viewer_email, watch_total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If my second interpretation above was correct, try this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=netbase1_index sourcetype=sv_sessions | rex field=_raw "watched\"\:\s\[(?P&amp;lt;watched_numbers&amp;gt;.[^\]]*)" | eval trim_spaces=trim(split(watched_numbers,",")) | stats count by viewer_email, trim_spaces | eval convert_string = tonumber(trim_spaces) | stats sum(count) AS array_total by viewer_email
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;*edit - you will probably need to change the field "viewer_email" to match your own.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2016 19:04:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269817#M81201</guid>
      <dc:creator>adayton20</dc:creator>
      <dc:date>2016-10-22T19:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: How obtain the sum of a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269818#M81202</link>
      <description>&lt;P&gt;Yes its possible to sum your mutivalue field "watched". &lt;/P&gt;

&lt;P&gt;If the &lt;STRONG&gt;emailId&lt;/STRONG&gt; and &lt;STRONG&gt;watched&lt;/STRONG&gt; fields are already extracted then try below query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yourBaseSearch to return events containing emailId and watched
    | rex field=watched max_match=0 "(?&amp;lt;watchcount&amp;gt;[\d]+)" 
    | mvexpand watchcount
    | stats sum(watchcount) by emailId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the fields are not extracted use below query to extract the fields &lt;STRONG&gt;emailId&lt;/STRONG&gt; and &lt;STRONG&gt;watched&lt;/STRONG&gt; first and then do then counting:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yourBaseSearch to return events
|rex "email\":\s\"(?&amp;lt;emailId&amp;gt;[^\"]+)"
| rex "watched\"\:\s\[(?&amp;lt;watched&amp;gt;[^\]]+)\]"
| rex field=watched max_match=0 "(?&amp;lt;watchcount&amp;gt;[\d]+)" 
| mvexpand watchcount
| stats sum(watchcount) by emailId
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Oct 2016 21:39:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269818#M81202</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-10-22T21:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: How obtain the sum of a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269819#M81203</link>
      <description>&lt;P&gt;Assuming that yor watched (multivalued) field is available in all events and you want to add a field Total to each event, try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=netbase1_index sourcetype=sv_sessions | rename "watched{}" as vwatch | eval sno=1 | accum sno | eventstats sum(vwatch) as Total by sno| table viewer.email Total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to summarize data by viewer.email field (means if there are 2+ events are with same viewer.email value then sum all those events), then try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=netbase1_index sourcetype=sv_sessions | rename "watched{}" as vwatch |stats sum(vwatch) as Total by viewer.email
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Oct 2016 23:52:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269819#M81203</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-10-22T23:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: How obtain the sum of a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269820#M81204</link>
      <description>&lt;P&gt;This query worked:&lt;/P&gt;

&lt;P&gt;index=netbase1_index sourcetype=sv_sessions | rename "watched{}" as vwatch | eval sno=1 | accum sno | &lt;BR /&gt;
eventstats sum(vwatch) as Total by sno| table viewer.email Total&lt;/P&gt;

&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:32:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269820#M81204</guid>
      <dc:creator>cgong</dc:creator>
      <dc:date>2020-09-29T11:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: How obtain the sum of a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269821#M81205</link>
      <description>&lt;P&gt;This worked:&lt;/P&gt;

&lt;P&gt;index=netbase1_index sourcetype=sv_sessions | rename "watched{}" as vwatch | streamstats count as count | eventstats sum(vwatch) as Total by count | table viewer.email Total&lt;/P&gt;

&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:32:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269821#M81205</guid>
      <dc:creator>cgong</dc:creator>
      <dc:date>2020-09-29T11:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: How obtain the sum of a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269822#M81206</link>
      <description>&lt;P&gt;Hi @cgong - Looks like you got a solution to your question. Please don't forget to click "Accept" below the best answer and up-vote any answers that were helpful to you. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 04:22:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269822#M81206</guid>
      <dc:creator>aaraneta_splunk</dc:creator>
      <dc:date>2016-10-26T04:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: How obtain the sum of a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269823#M81207</link>
      <description>&lt;P&gt;@cgong can you please accept my answer if that solved the issue for you?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2016 14:22:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/269823#M81207</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2016-12-20T14:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: How obtain the sum of a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/692634#M235735</link>
      <description>&lt;P&gt;Another Easy way is to use forearch command: below is the example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;|makeresults | eval mv=mvappend("5", "15"), total = 0, count = 0 | foreach mode=multivalue mv [eval total = total + &amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;, count = count + 1]&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 11:58:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-obtain-the-sum-of-a-multivalue-field/m-p/692634#M235735</guid>
      <dc:creator>bhavikbhalodia</dc:creator>
      <dc:date>2024-07-08T11:58:56Z</dc:date>
    </item>
  </channel>
</rss>

