<?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 sum a column's values along multiple categories, then display the summed column along with the category which contributed the largest value in that category, all in the same row? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407440#M117668</link>
    <description>&lt;P&gt;Thank you very much, however (and I should have mentioned this earlier), the tabular data that I shared is not a fixed list. It is generated dynamically at runtime based on Splunk logs matching a lookup file (the part of the query I skipped and indicated with '...'). &lt;/P&gt;

&lt;P&gt;Hence, I am unfortunately not sure how the 'eval' function could work.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jan 2019 18:52:13 GMT</pubDate>
    <dc:creator>rey123</dc:creator>
    <dc:date>2019-01-17T18:52:13Z</dc:date>
    <item>
      <title>How to sum a column's values along multiple categories, then display the summed column along with the category which contributed the largest value in that category, all in the same row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407437#M117665</link>
      <description>&lt;P&gt;I have the following data:&lt;/P&gt;

&lt;H2&gt;&lt;STRONG&gt;A                B                       C                  Pkg              Area                     Count&lt;/STRONG&gt;&lt;/H2&gt;

&lt;P&gt;NP                bcd                  D02             abc.d            PP                        1656&lt;BR /&gt;
NP                bcd                  D05             abc.d            PP                          870&lt;BR /&gt;
NP                bcd                  D01             abc.d            PP                          100&lt;BR /&gt;
NP                cde                  D05             lmn.o            PP                            50&lt;BR /&gt;
NP                cde                  D10             lmn.o            PP                          350&lt;BR /&gt;
NP                cde                  D07             lmn.o            PP                          200&lt;/P&gt;

&lt;P&gt;I want to sum the Count column by A and B, but display the resulting rows with the value of Column C which contributed to the maximum Count in the above summation.&lt;/P&gt;

&lt;P&gt;So, expected result:&lt;/P&gt;

&lt;H2&gt;&lt;STRONG&gt;A                B                       C                  Pkg              Area                     Count&lt;/STRONG&gt;&lt;/H2&gt;

&lt;P&gt;NP                bcd                  &lt;STRONG&gt;D02&lt;/STRONG&gt;             abc.d            PP                  &lt;STRONG&gt;2626&lt;/STRONG&gt;&lt;BR /&gt;
NP                cde                  &lt;STRONG&gt;D10&lt;/STRONG&gt;             lmn.o            PP                    &lt;STRONG&gt;600&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Tried the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "java\.lang\.(?P[A-Z]+(NP))"
| rex field=_raw "(?\S+)\.[A-Z]\S+\((?&amp;lt;b&amp;gt;\w+)\)"
| search A=NP
...

| stats values(Pkg), values(Area), values(C) , count as Count by A, B, C
| eventstats sum(Count) as Count1 by A, B  
| search Area=PP 
| sort -Count1 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Result:&lt;/P&gt;

&lt;H2&gt;*&lt;EM&gt;A                B                       C                  Pkg              Area                   Count       Count1 *&lt;/EM&gt;&lt;/H2&gt;

&lt;P&gt;NP                bcd                  D02             abc.d            PP                        1656          2626&lt;BR /&gt;
NP                bcd                  D05             abc.d            PP                          870          2626&lt;BR /&gt;
NP                bcd                  D01             abc.d            PP                          100          2626&lt;BR /&gt;
NP                cde                  D05             lmn.o            PP                            50            600&lt;BR /&gt;
NP                cde                  D10             lmn.o            PP                          350            600&lt;BR /&gt;
NP                cde                  D07             lmn.o            PP                          200            600&lt;/P&gt;

&lt;P&gt;If I modify the query as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "java\.lang\.(?P[A-Z]+(NP))"
| rex field=_raw "(?\S+)\.[A-Z]\S+\((?&amp;lt;b&amp;gt;\w+)\)"
| search A=NP
...

| stats values(Pkg), values(Area), values(C) , count as Count by A, B, C
| eventstats sum(Count) as Count1 by A, B  first(Count1) as Top_Count by C
| search Area=PP 
| sort -Count1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;..the &lt;STRONG&gt;Top_Count&lt;/STRONG&gt; column shows up empty:&lt;/P&gt;

&lt;H2&gt;*&lt;EM&gt;A                B                       C                  Pkg              Area                   Count       Top_Count *&lt;/EM&gt;&lt;/H2&gt;

&lt;P&gt;NP                bcd                  D02             abc.d            PP                        1656&lt;BR /&gt;&lt;BR /&gt;
NP                bcd                  D05             abc.d            PP                          870&lt;BR /&gt;&lt;BR /&gt;
NP                bcd                  D01             abc.d            PP                          100&lt;BR /&gt;&lt;BR /&gt;
NP                cde                  D05             lmn.o            PP                            50&lt;BR /&gt;&lt;BR /&gt;
NP                cde                  D10             lmn.o            PP                          350&lt;BR /&gt;&lt;BR /&gt;
NP                cde                  D07             lmn.o            PP                          200          &lt;/P&gt;

&lt;P&gt;Removing the &lt;STRONG&gt;Count&lt;/STRONG&gt; column at the end.. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "java\.lang\.(?P[A-Z]+(NP))"
| rex field=_raw "(?\S+)\.[A-Z]\S+\((?&amp;lt;b&amp;gt;\w+)\)"
| search A=NP
...

| stats values(Pkg), values(Area), values(C) , count as Count by A, B, C
| eventstats sum(Count) as Count1 by A, B  first(Count1) as Top_Count by C
| search Area=PP 
| sort -Count1
| fields - Count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;..hides all the &lt;STRONG&gt;Count&lt;/STRONG&gt; columns:&lt;/P&gt;

&lt;H2&gt;*&lt;EM&gt;A                B                       C                  Pkg              Area                   Top_Count *&lt;/EM&gt;&lt;/H2&gt;

&lt;P&gt;NP                bcd                  D02             abc.d            PP&lt;BR /&gt;&lt;BR /&gt;
NP                bcd                  D05             abc.d            PP&lt;BR /&gt;&lt;BR /&gt;
NP                bcd                  D01             abc.d            PP&lt;BR /&gt;&lt;BR /&gt;
NP                cde                  D05             lmn.o            PP&lt;BR /&gt;&lt;BR /&gt;
NP                cde                  D10             lmn.o            PP&lt;BR /&gt;&lt;BR /&gt;
NP                cde                  D07             lmn.o            PP                                    &lt;/P&gt;

&lt;P&gt;I am not sure why all the &lt;EM&gt;Count&lt;/EM&gt; columns get removed considering the &lt;STRONG&gt;Fields -&lt;/STRONG&gt; command is applied only at the very end. &lt;/P&gt;

&lt;P&gt;Any pointers? Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 05:56:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407437#M117665</guid>
      <dc:creator>rey123</dc:creator>
      <dc:date>2019-01-17T05:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a column's values along multiple categories, then display the summed column along with the category which contributed the largest value in that category, all in the same row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407438#M117666</link>
      <description>&lt;P&gt;hi @rey123 &lt;/P&gt;

&lt;P&gt;try like this &lt;/P&gt;

&lt;P&gt;add in your query''   &lt;CODE&gt;| stats sum(Count) as Count1 by A, B&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 09:08:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407438#M117666</guid>
      <dc:creator>harishalipaka</dc:creator>
      <dc:date>2019-01-17T09:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a column's values along multiple categories, then display the summed column along with the category which contributed the largest value in that category, all in the same row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407439#M117667</link>
      <description>&lt;P&gt;Hi Try this run anywhere search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval data="NP bcd D02 abc.d PP 1656,NP bcd D05 abc.d PP 870,NP bcd D01 abc.d PP 100,NP cde D05 lmn.o PP 50,NP cde D10 lmn.o PP 350,NP cde D07 lmn.o PP 200" 
| makemv data delim="," 
| mvexpand data 
| rex field=data "(?&amp;lt;a&amp;gt;[^\s]+)\s(?&amp;lt;b&amp;gt;[^\s]+)\s(?&amp;lt;c&amp;gt;[^\s]+)\s(?&amp;lt;pkg&amp;gt;[^\s]+)\s(?&amp;lt;area&amp;gt;[^\s]+)\s(?&amp;lt;count&amp;gt;.*)" 
| table a b c pkg area count 
| eventstats sum(count) as sum max(count) as max by a b 
| where count==max 
| table a b c pkg area sum
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;put this at the end of your main search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table a b c pkg area count 
    | eventstats sum(count) as sum max(count) as max by a b 
    | where count==max 
    | table a b c pkg area sum
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 09:44:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407439#M117667</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-01-17T09:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a column's values along multiple categories, then display the summed column along with the category which contributed the largest value in that category, all in the same row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407440#M117668</link>
      <description>&lt;P&gt;Thank you very much, however (and I should have mentioned this earlier), the tabular data that I shared is not a fixed list. It is generated dynamically at runtime based on Splunk logs matching a lookup file (the part of the query I skipped and indicated with '...'). &lt;/P&gt;

&lt;P&gt;Hence, I am unfortunately not sure how the 'eval' function could work.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 18:52:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407440#M117668</guid>
      <dc:creator>rey123</dc:creator>
      <dc:date>2019-01-17T18:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a column's values along multiple categories, then display the summed column along with the category which contributed the largest value in that category, all in the same row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407441#M117669</link>
      <description>&lt;P&gt;Thank you, this seems to replace &lt;STRONG&gt;evalstats&lt;/STRONG&gt; with &lt;STRONG&gt;stats&lt;/STRONG&gt;. Tried, but didn't work, unfortunately (no data appeared).&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 18:54:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407441#M117669</guid>
      <dc:creator>rey123</dc:creator>
      <dc:date>2019-01-17T18:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a column's values along multiple categories, then display the summed column along with the category which contributed the largest value in that category, all in the same row?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407442#M117670</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval raw="NP,bcd,D02,abc.d,PP,1656 NP,bcd,D05,abc.d,PP,870 NP,bcd,D01,abc.d,PP,100 NP,cde,D05,lmn.o,PP,50 NP,cde,D10,lmn.o,PP,350 NP,cde,D07,lmn.o,PP,200" 
| makemv raw 
| mvexpand raw 
| rename raw AS _raw 
| rex "^(?&amp;lt;A&amp;gt;[^,]+),(?&amp;lt;B&amp;gt;[^,]+),(?&amp;lt;C&amp;gt;[^,]+),(?&amp;lt;Pkg&amp;gt;[^,]+),(?&amp;lt;Area&amp;gt;[^,]+),(?&amp;lt;Count&amp;gt;[^,]+)$" 

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| sort 0 - Count
| eventstats first(C) AS C BY A B Area
| stats sum(Count) AS Count BY A B C Pkg Area
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Jan 2019 20:19:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sum-a-column-s-values-along-multiple-categories-then/m-p/407442#M117670</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-18T20:19:52Z</dc:date>
    </item>
  </channel>
</rss>

