<?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 to get sum of field based on it's value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484508#M135624</link>
    <description>&lt;P&gt;Hi @swdowiarz,&lt;/P&gt;

&lt;P&gt;Try this, could be that the &lt;CODE&gt;.&lt;/CODE&gt; is causing some problems with the eval as it could be interpreted as a concatenation :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=cs_engineering sourcetype=pizza_app data.offlineGDTS=* 
|rename data.offlineGDTS as NewofflineGDTS
| stats  count(eval(NewofflineGDTS="true")) as ONLINE_GDT count(eval(NewofflineGDTS="false")) as OFFLINE_GDT
 by data.user_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that helps.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
David&lt;/P&gt;</description>
    <pubDate>Sun, 22 Sep 2019 10:27:52 GMT</pubDate>
    <dc:creator>DavidHourani</dc:creator>
    <dc:date>2019-09-22T10:27:52Z</dc:date>
    <item>
      <title>How to get sum of field based on it's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484505#M135621</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I would be grateful  for any help.&lt;/P&gt;

&lt;P&gt;In my fields we are having two fields which are: &lt;STRONG&gt;data.user_id&lt;/STRONG&gt; and &lt;STRONG&gt;data.config.offlineGDTS&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;data.config.offlineGDTS&lt;/STRONG&gt; can have value &lt;STRONG&gt;true&lt;/STRONG&gt; or &lt;STRONG&gt;false&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;My questions is: How can I have statistics for each user how many events he has for data.config.offlineGDTS=true and data.config.offlineGDTS=false ?&lt;BR /&gt;
Basically I would like to have in one row: user_id, sum(data.config.offlineGDTS=true), sum(data.config.offlineGDTS=false)&lt;/P&gt;

&lt;P&gt;What I've tried looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=cs_engineering sourcetype=pizza_app data.offlineGDTS=* | stats 
count(eval(data.offlineGDTS="true")) as ONLINE_GDT
count((data.offlineGDTS="false")) as OFFLINE_GDT
by data.user_id
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Sep 2019 13:01:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484505#M135621</guid>
      <dc:creator>swdowiarz</dc:creator>
      <dc:date>2019-09-20T13:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to get sum of field based on it's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484506#M135622</link>
      <description>&lt;P&gt;The second &lt;CODE&gt;count&lt;/CODE&gt; is missing an &lt;CODE&gt;eval&lt;/CODE&gt;.  What do you get from that query?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 14:01:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484506#M135622</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-09-20T14:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to get sum of field based on it's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484507#M135623</link>
      <description>&lt;P&gt;Oh yes, I missed that one.&lt;BR /&gt;
With this query I'm getting the look of a table as I wanted with three columns( user_id, ONLINE_GDT, OFFLINE_GDT ), but for each row(user_id) the data are not being count and all the values for GDTs are 0.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:14:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484507#M135623</guid>
      <dc:creator>swdowiarz</dc:creator>
      <dc:date>2020-09-30T02:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to get sum of field based on it's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484508#M135624</link>
      <description>&lt;P&gt;Hi @swdowiarz,&lt;/P&gt;

&lt;P&gt;Try this, could be that the &lt;CODE&gt;.&lt;/CODE&gt; is causing some problems with the eval as it could be interpreted as a concatenation :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=cs_engineering sourcetype=pizza_app data.offlineGDTS=* 
|rename data.offlineGDTS as NewofflineGDTS
| stats  count(eval(NewofflineGDTS="true")) as ONLINE_GDT count(eval(NewofflineGDTS="false")) as OFFLINE_GDT
 by data.user_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that helps.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
David&lt;/P&gt;</description>
      <pubDate>Sun, 22 Sep 2019 10:27:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484508#M135624</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-09-22T10:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to get sum of field based on it's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484509#M135625</link>
      <description>&lt;P&gt;yeah! it is working as it should be, thanks! &lt;BR /&gt;
However, do you know how to present those counts in percentage? &lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 08:03:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484509#M135625</guid>
      <dc:creator>swdowiarz</dc:creator>
      <dc:date>2019-09-23T08:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to get sum of field based on it's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484510#M135626</link>
      <description>&lt;P&gt;you're welcome !&lt;/P&gt;

&lt;P&gt;Yeah for the percentage you just need the total count. Something like this should do the trick :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count(NewofflineGDTS)  as total count(eval(NewofflineGDTS="true")) as ONLINE_GDT count(eval(NewofflineGDTS="false")) as OFFLINE_GDT
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can then use that total with an eval to make a percentage &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 08:22:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484510#M135626</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-09-23T08:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to get sum of field based on it's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484511#M135627</link>
      <description>&lt;P&gt;You could try the top function, it orders your results by amount and automaticly adds percentage to it, but it might not be best practice. Not sure if you can add percetage on it's own. Maybe try "showperc=true" or something?&lt;/P&gt;

&lt;P&gt;(I just started with Splunk, so I might be wrong.)&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 08:51:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-sum-of-field-based-on-it-s-value/m-p/484511#M135627</guid>
      <dc:creator>jonydupre</dc:creator>
      <dc:date>2019-09-23T08:51:59Z</dc:date>
    </item>
  </channel>
</rss>

