<?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 group by from two fields and perform stats depending of the field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510392#M142853</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, it looks like it works for my example, but on production data, I very quickly reach a limit that I cannot increase...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;command.mvexpand: output will be truncated at 946100 results due to excessive memory usage. Memory threshold of 500MB as configured in limits.conf / [mvexpand] / max_mem_usage_mb has been reached.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could I use a workaround for mvexpand?&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jul 2020 10:12:47 GMT</pubDate>
    <dc:creator>davietch</dc:creator>
    <dc:date>2020-07-22T10:12:47Z</dc:date>
    <item>
      <title>How to group by from two fields and perform stats depending of the field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510362#M142840</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Let me give you an example. I've got the following table to work with:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;src_group&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;dest_group&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;A&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;B&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;B&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;A&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;21&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;A&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;C&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;32&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;B&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;Z&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to have something like this for result:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;group&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;src_count&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;dest_count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;A&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;42&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;21&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;B&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;27&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;C&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;0&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;32&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="24px"&gt;Z&lt;/TD&gt;&lt;TD height="24px"&gt;0&lt;/TD&gt;&lt;TD height="24px"&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, I have now only one colomn with the groups,&amp;nbsp; and the count are merged by groups while the direction (src or dest) is now on the counts : we sum the count for each group depending of whether the group was the source or the destination in the first table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any clue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: to help me, you can use this search that will generate the first table:&lt;/P&gt;&lt;P&gt;| stats count | eval src_group="A", dest_group="B", count=10&lt;BR /&gt;| append [| stats count | eval src_group="B", dest_group="A", count=21 ]&lt;BR /&gt;| append [| stats count | eval src_group="A", dest_group="C", count=32 ]&lt;BR /&gt;| append [| stats count | eval src_group="B", dest_group="Z", count=6 ]&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 07:54:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510362#M142840</guid>
      <dc:creator>davietch</dc:creator>
      <dc:date>2020-07-22T07:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by from two fields and perform stats depending of the field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510363#M142841</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201384"&gt;@davietch&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Try something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;your_search
| eval group=coalesce(src_group,dest_group)
| stats count(src_group) AS src_group count(dest_group) AS dest_group BY group&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 07:42:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510363#M142841</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2020-07-22T07:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by from two fields and perform stats depending of the field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510367#M142843</link>
      <description>&lt;P&gt;Hi, Unfortunately this is not what I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;| eval group=coalesce(src_group,dest_group)&lt;/PRE&gt;&lt;P&gt;will give me only the src_group value and, in my example, discard C &amp;amp; Z.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;| stats count(src_group) AS src_group count(dest_group) AS dest_group BY group&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;will just count the number of lines. I would need to do a sum().&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 08:42:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510367#M142843</guid>
      <dc:creator>davietch</dc:creator>
      <dc:date>2020-07-22T08:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by from two fields and perform stats depending of the field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510378#M142847</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201384"&gt;@davietch&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;could you share two or three samples of your logs?&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 08:45:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510378#M142847</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2020-07-22T08:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by from two fields and perform stats depending of the field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510379#M142848</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;| stats count | eval src_group="A", dest_group="B", count=10&lt;BR /&gt;| append [| stats count | eval src_group="B", dest_group="A", count=21 ]&lt;BR /&gt;| append [| stats count | eval src_group="A", dest_group="C", count=32 ]&lt;BR /&gt;| append [| stats count | eval src_group="B", dest_group="Z", count=6 ]&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="lia-panel lia-panel-standard LabelsForMessage Chrome lia-component-message-view-widget-labels"&gt;&lt;DIV class="lia-decoration-border"&gt;&lt;DIV class="lia-decoration-border-top"&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="lia-decoration-border-content"&gt;&lt;DIV&gt;&lt;DIV class="lia-panel-heading-bar-wrapper"&gt;To work on&lt;/DIV&gt;&lt;DIV class="lia-panel-heading-bar-wrapper"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 22 Jul 2020 08:46:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510379#M142848</guid>
      <dc:creator>davietch</dc:creator>
      <dc:date>2020-07-22T08:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by from two fields and perform stats depending of the field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510389#M142852</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="src_group	dest_group	count
A	B	10
B	A	21
A	C	32
B	Z	6"
| multikv forceheader=1
| table src_group	dest_group	count
| rename COMMENT as "this is sample you provide. From here, the logic"
| eval tmp=mvappend(src_group,dest_group)
| eventstats values(tmp) as group
| mvexpand group
| stats sum(eval(if(src_group=group,count,NULL))) as src_count sum(eval(if(dest_group=group,count,NULL))) as dest_count by group
| fillnull src_count dest_count&lt;/LI-CODE&gt;&lt;P&gt;how about this?&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201384"&gt;@davietch&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 09:47:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510389#M142852</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-07-22T09:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by from two fields and perform stats depending of the field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510392#M142853</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, it looks like it works for my example, but on production data, I very quickly reach a limit that I cannot increase...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;command.mvexpand: output will be truncated at 946100 results due to excessive memory usage. Memory threshold of 500MB as configured in limits.conf / [mvexpand] / max_mem_usage_mb has been reached.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could I use a workaround for mvexpand?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 10:12:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510392#M142853</guid>
      <dc:creator>davietch</dc:creator>
      <dc:date>2020-07-22T10:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by from two fields and perform stats depending of the field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510394#M142854</link>
      <description>&lt;P&gt;what's your full query?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 10:25:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510394#M142854</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-07-22T10:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by from two fields and perform stats depending of the field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510411#M142859</link>
      <description>&lt;P&gt;This is it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;| tstats count from datamodel="Network_Traffic" where nodename="All_Traffic.Traffic_By_Action" All_Traffic.src_ip="*" AND All_Traffic.dest_ip="*" All_Traffic.action="blocked" by All_Traffic.src_ip, All_Traffic.dest_ip&lt;BR /&gt;| rename All_Traffic.* AS *, values(All_Traffic.*) AS *&lt;BR /&gt;| lookup ipgroups.csv ip AS src_ip OUTPUT group AS src_group | lookup ipgroups.csv ip AS dest_ip OUTPUT group AS dest_group | table&amp;nbsp;src_group,&amp;nbsp;dest_group, count&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 12:05:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510411#M142859</guid>
      <dc:creator>davietch</dc:creator>
      <dc:date>2020-07-22T12:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by from two fields and perform stats depending of the field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510443#M142862</link>
      <description>&lt;LI-CODE lang="markup"&gt;| tstats count from datamodel="Network_Traffic" where nodename="All_Traffic.Traffic_By_Action" All_Traffic.src_ip="*" AND All_Traffic.dest_ip="*" All_Traffic.action="blocked" by All_Traffic.src_ip, All_Traffic.dest_ip
| rename All_Traffic.* AS *, values(All_Traffic.*) AS *
| lookup ipgroups.csv ip AS src_ip OUTPUT group AS src_group | lookup ipgroups.csv ip AS dest_ip OUTPUT group AS dest_group 
| table src_group dest_group count

| eval group=mvappend(src_group,dest_group)
| mvexpand group
| eval src_count=if(src_group=group,count,NULL), dest_count=if(dest_group=group,count,NULL)
| stats sum(src_count) as src_count sum(dest_count) as dest_count by group&lt;/LI-CODE&gt;&lt;P&gt;maybe this query can work.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 13:34:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-by-from-two-fields-and-perform-stats-depending-of/m-p/510443#M142862</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-07-22T13:34:01Z</dc:date>
    </item>
  </channel>
</rss>

