<?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 do you sum all values of a field that has JSON data? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457333#M79027</link>
    <description>&lt;P&gt;Is the name of the primary key field &lt;CODE&gt;PrimaryKey&lt;/CODE&gt;?&lt;/P&gt;</description>
    <pubDate>Thu, 13 Sep 2018 20:55:28 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-09-13T20:55:28Z</dc:date>
    <item>
      <title>How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457323#M79017</link>
      <description>&lt;P&gt;I have some JSON data , in that i want to sum all values of a key in a Splunk query. Below is the sample data :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;data":[{"abc":"1234","mainrate":12},{"abc":"186","mainrate":222},{"abc":"633","mainrate":121},]}],
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Tried using &lt;CODE&gt;sum&lt;/CODE&gt; but that is not giving me sum of all minrate. I'm using the below query  to get this done :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=mytest| eventstats sum(mainrate) AS TotalMinRate
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 14:54:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457323#M79017</guid>
      <dc:creator>gauravepi</dc:creator>
      <dc:date>2018-09-13T14:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457324#M79018</link>
      <description>&lt;P&gt;You need to include a function after the pipe. Try using &lt;CODE&gt;eventstats&lt;/CODE&gt; or &lt;CODE&gt;stats&lt;/CODE&gt; to do this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=mytest
| eventstats sum(mainrate) AS TotalMinRate
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 14:59:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457324#M79018</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2018-09-13T14:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457325#M79019</link>
      <description>&lt;P&gt;I tried that as well but it is not working , can we use foreach to get this done? &lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 15:09:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457325#M79019</guid>
      <dc:creator>gauravepi</dc:creator>
      <dc:date>2018-09-13T15:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457326#M79020</link>
      <description>&lt;P&gt;No.. I see you updated your answer to reflect &lt;CODE&gt;eventstats&lt;/CODE&gt;. What is not working? Have you tried &lt;CODE&gt;stats&lt;/CODE&gt;? Are you trying to create a field with the summed values or trying to show a table view with the summed values? Have you confirmed the field is populating? If it's not then you have an issue with your extraction. Can you confirm &lt;CODE&gt;minrate&lt;/CODE&gt; is producing results? Can you confirm &lt;CODE&gt;minrate&lt;/CODE&gt; is numeric? If they are string values then it will not sum&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 15:13:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457326#M79020</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2018-09-13T15:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457327#M79021</link>
      <description>&lt;P&gt;Yes I am trying to create a table that will have totalMinrate field and that field will have the sum of all mainrate.It is showing the TotalMinRate in rate but it is not doing the sum for each minrate present in the Json array.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 15:19:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457327#M79021</guid>
      <dc:creator>gauravepi</dc:creator>
      <dc:date>2018-09-13T15:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457328#M79022</link>
      <description>&lt;P&gt;I have tried both &lt;CODE&gt;stats&lt;/CODE&gt; and &lt;CODE&gt;eventstats&lt;/CODE&gt; but both are helping me to sum all the key values.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 15:21:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457328#M79022</guid>
      <dc:creator>gauravepi</dc:creator>
      <dc:date>2018-09-13T15:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457329#M79023</link>
      <description>&lt;P&gt;You haven't answered my questions.. If these values are NOT numeric then it will not work. You should try testing with another field such as &lt;CODE&gt;date_minute&lt;/CODE&gt;. I just tested in my env and its working as expected&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=..
| eventstats sum(date_minute)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 15:43:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457329#M79023</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2018-09-13T15:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457330#M79024</link>
      <description>&lt;P&gt;Yes it is working for numeric values , &lt;BR /&gt;
Those are Json values might possible splunk is considering them as a String &lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 15:58:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457330#M79024</guid>
      <dc:creator>gauravepi</dc:creator>
      <dc:date>2018-09-13T15:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457331#M79025</link>
      <description>&lt;P&gt;Seems like you want to sum the multivalued field &lt;CODE&gt;mainrate&lt;/CODE&gt; values within same event. Unfortunately, there is no built-in function to do a multivalued field's value sum. Give this workaround a try.&lt;/P&gt;

&lt;P&gt;If there are no primary key (some key or keys that uniquely represent each row) in your data, try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=mytest | streamstats count as rank | eventstats sum(mainrate) AS TotalMinRate by rank
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If there is a primary key in your data, use it in eventstats.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=mytest | eventstats sum(mainrate) AS TotalMinRate by yourPrimaryKeyField
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 16:12:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457331#M79025</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-09-13T16:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457332#M79026</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;eventtype=mytest  |eventstats  sum(mainrate) AS TotalMinRate  by PrimaryKey | rename date AS "datetime" | table datetime, TotalMinRate
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Above is the full query but it is not doing the sum of all the json key it has for PrimaryKeyField&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 16:19:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457332#M79026</guid>
      <dc:creator>gauravepi</dc:creator>
      <dc:date>2018-09-13T16:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457333#M79027</link>
      <description>&lt;P&gt;Is the name of the primary key field &lt;CODE&gt;PrimaryKey&lt;/CODE&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 20:55:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457333#M79027</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-09-13T20:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do you sum all values of a field that has JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457334#M79028</link>
      <description>&lt;P&gt;No it's name is different i have just added as an example &lt;/P&gt;</description>
      <pubDate>Fri, 14 Sep 2018 16:59:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-sum-all-values-of-a-field-that-has-JSON-data/m-p/457334#M79028</guid>
      <dc:creator>gauravepi</dc:creator>
      <dc:date>2018-09-14T16:59:43Z</dc:date>
    </item>
  </channel>
</rss>

