<?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: Using conditional sum after case statement in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385633#M169543</link>
    <description>&lt;P&gt;A sum over what field? Please be a bit more specific in what data you have and what result you're after.&lt;/P&gt;</description>
    <pubDate>Wed, 09 May 2018 08:57:40 GMT</pubDate>
    <dc:creator>FrankVl</dc:creator>
    <dc:date>2018-05-09T08:57:40Z</dc:date>
    <item>
      <title>Using conditional sum after case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385631#M169541</link>
      <description>&lt;P&gt;.....search&lt;BR /&gt;
| eval Type=case(like(publishId,"%U"),"unsubscribed",like(publishId,"%S"),"subscribed") &lt;BR /&gt;
| stats count by tile Type&lt;BR /&gt;
| sort Type&lt;/P&gt;

&lt;P&gt;How do you get a separate sum for "%U" and "%S" ???&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 21:58:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385631#M169541</guid>
      <dc:creator>dwong2</dc:creator>
      <dc:date>2018-05-08T21:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using conditional sum after case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385632#M169542</link>
      <description>&lt;P&gt;You could use a different representation if that fits your needs, eg: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.....search
| eval Type=case(like(publishId,"%U"),"unsubscribed",like(publishId,"%S"),"subscribed") 
| chart count over tile Type
| addcoltotals
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;More in spirit of the original representation maybe:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.....search
 | eval Type=case(like(publishId,"%U"),"unsubscribed",like(publishId,"%S"),"subscribed") 
 | stats count by tile Type
 | sort Type
 | stats list(Type) as Type list(count) as Count by tile
 | eventstats sum(Count) as Total by tile
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;UL&gt;
&lt;LI&gt;but there must be something more elegant. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 09 May 2018 08:51:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385632#M169542</guid>
      <dc:creator>knielsen</dc:creator>
      <dc:date>2018-05-09T08:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using conditional sum after case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385633#M169543</link>
      <description>&lt;P&gt;A sum over what field? Please be a bit more specific in what data you have and what result you're after.&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 08:57:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385633#M169543</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-05-09T08:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using conditional sum after case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385634#M169544</link>
      <description>&lt;P&gt;This is my output now:&lt;/P&gt;

&lt;P&gt;tile    Type    count&lt;BR /&gt;
PosterTile  subscribed  2&lt;BR /&gt;
Tile1   subscribed  4&lt;BR /&gt;
Tile2   subscribed  6&lt;BR /&gt;
Tile3   subscribed  2&lt;BR /&gt;
Tile4   subscribed  2&lt;BR /&gt;
BannerTile  unsubscribed    5&lt;BR /&gt;
Tile1   unsubscribed    6&lt;BR /&gt;
Tile2   unsubscribed    5&lt;BR /&gt;
Tile3   unsubscribed    4&lt;BR /&gt;
Tile4   unsubscribed    7&lt;/P&gt;

&lt;P&gt;Can't figure out how to sum the subscribed and unsubscribed and the calculate to get an average in percentage.&lt;BR /&gt;
i.e. for subscribed    Tile1/Total tile of subscribed only so 4/16; Tile2/Total tile of subscribed only so 6/16&lt;BR /&gt;
for unsubscribed   Tile1/Total tile of unsubscribed only so 6/27; Tile2/Total tile of unsubscribed only so 5/27&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 21:26:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385634#M169544</guid>
      <dc:creator>dwong2</dc:creator>
      <dc:date>2018-05-09T21:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using conditional sum after case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385635#M169545</link>
      <description>&lt;P&gt;@dwong2, can you please try the following search with eventstats to compute Total by Type and add Total to each event for corresponding Type:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;
| eval Type=case(like(publishId,"%U"),"unsubscribed",like(publishId,"%S"),"subscribed") 
| stats count by tile Type
| eventstats sum(count) as Total by Type
| eval Avg=round(count/Total,2)
| sort Type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search based on sample data provided:&lt;BR /&gt;
PS: Commands from &lt;CODE&gt;| makeresults&lt;/CODE&gt; till &lt;CODE&gt;| table tile Type count&lt;/CODE&gt; generate the sample data as per the question. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| fields - _time
| eval data="PosterTile subscribed 2;
Tile1 subscribed 4;
Tile2 subscribed 6;
Tile3 subscribed 2;
Tile4 subscribed 2;
BannerTile unsubscribed 5;
Tile1 unsubscribed 6;
Tile2 unsubscribed 5;
Tile3 unsubscribed 4;
Tile4 unsubscribed 7"
| makemv data delim=";"
| mvexpand data
| makemv data delim=" "
| eval tile=mvindex(data,0), Type=mvindex(data,1), count=mvindex(data,2)
| table tile Type count
| eventstats sum(count) as Total by Type
| eval Avg=round(count/Total,2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 23:02:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-conditional-sum-after-case-statement/m-p/385635#M169545</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-09T23:02:58Z</dc:date>
    </item>
  </channel>
</rss>

