<?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 How to Summarize on distinct value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654592#M226149</link>
    <description>&lt;P&gt;Hello there,&lt;BR /&gt;&lt;BR /&gt;I would like some help with my query.&lt;BR /&gt;&lt;BR /&gt;I want to summarize 2 fields into 2 new columns&lt;/P&gt;
&lt;P&gt;One field is unique, but the other is not&lt;BR /&gt;The field fhost is not unique.&lt;/P&gt;
&lt;P&gt;I want the sum of field "cores" by unique combination of the columns&amp;nbsp; &amp;nbsp; "clname" and&amp;nbsp; "fhost"&lt;BR /&gt;&lt;BR /&gt;I am struggle how to do this properly and how i can use the sum unique for column "fhost"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;| makeresults&lt;BR /&gt;| eval clname="clusterx", fhost="f-hosta", vhost="v-hosta",cores=2,cpu=1&lt;BR /&gt;| append [| makeresults | eval clname="clusterx", fhost="f-hosta", vhost="v-hostb" ,cores=2,cpu=1 ]&lt;BR /&gt;| append [| makeresults | eval clname="clusterx", fhost="f-hostb", vhost="v-hostc" ,cores=4,cpu=1 ]&lt;BR /&gt;| append [| makeresults | eval clname="clusterx", fhost="f-hostc", vhost="v-hostd" ,cores=6,cpu=1 ]&lt;BR /&gt;&lt;BR /&gt;| eventstats sum(cpu) as total_vhost_cpus by clname&lt;BR /&gt;&lt;BR /&gt;``` This is not working ```&lt;BR /&gt;| eventstats sum(cores) as total_fhost_cores by clname fhost&lt;BR /&gt;&lt;BR /&gt;`` The output should be in table format ```&lt;/P&gt;
&lt;P&gt;| table clname cores cpu fhost vhost&amp;nbsp; total_vhost_cpus&amp;nbsp; total_fhost_cores&lt;BR /&gt;&lt;BR /&gt;Thank you in advance.&lt;BR /&gt;&lt;BR /&gt;Harry&lt;/P&gt;</description>
    <pubDate>Thu, 17 Aug 2023 18:00:55 GMT</pubDate>
    <dc:creator>hvdtol</dc:creator>
    <dc:date>2023-08-17T18:00:55Z</dc:date>
    <item>
      <title>How to Summarize on distinct value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654592#M226149</link>
      <description>&lt;P&gt;Hello there,&lt;BR /&gt;&lt;BR /&gt;I would like some help with my query.&lt;BR /&gt;&lt;BR /&gt;I want to summarize 2 fields into 2 new columns&lt;/P&gt;
&lt;P&gt;One field is unique, but the other is not&lt;BR /&gt;The field fhost is not unique.&lt;/P&gt;
&lt;P&gt;I want the sum of field "cores" by unique combination of the columns&amp;nbsp; &amp;nbsp; "clname" and&amp;nbsp; "fhost"&lt;BR /&gt;&lt;BR /&gt;I am struggle how to do this properly and how i can use the sum unique for column "fhost"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;| makeresults&lt;BR /&gt;| eval clname="clusterx", fhost="f-hosta", vhost="v-hosta",cores=2,cpu=1&lt;BR /&gt;| append [| makeresults | eval clname="clusterx", fhost="f-hosta", vhost="v-hostb" ,cores=2,cpu=1 ]&lt;BR /&gt;| append [| makeresults | eval clname="clusterx", fhost="f-hostb", vhost="v-hostc" ,cores=4,cpu=1 ]&lt;BR /&gt;| append [| makeresults | eval clname="clusterx", fhost="f-hostc", vhost="v-hostd" ,cores=6,cpu=1 ]&lt;BR /&gt;&lt;BR /&gt;| eventstats sum(cpu) as total_vhost_cpus by clname&lt;BR /&gt;&lt;BR /&gt;``` This is not working ```&lt;BR /&gt;| eventstats sum(cores) as total_fhost_cores by clname fhost&lt;BR /&gt;&lt;BR /&gt;`` The output should be in table format ```&lt;/P&gt;
&lt;P&gt;| table clname cores cpu fhost vhost&amp;nbsp; total_vhost_cpus&amp;nbsp; total_fhost_cores&lt;BR /&gt;&lt;BR /&gt;Thank you in advance.&lt;BR /&gt;&lt;BR /&gt;Harry&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 18:00:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654592#M226149</guid>
      <dc:creator>hvdtol</dc:creator>
      <dc:date>2023-08-17T18:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize on distinct value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654598#M226151</link>
      <description>&lt;P&gt;It would help if you describe what "this is not working" actually means. &amp;nbsp;What is the result you get and what is the result you expect? &amp;nbsp;What is the logic between your data and your expected result?&lt;/P&gt;&lt;P&gt;Using your sample data and your sample stats, this is the table&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;clname&lt;/TD&gt;&lt;TD&gt;cores&lt;/TD&gt;&lt;TD&gt;cpu&lt;/TD&gt;&lt;TD&gt;fhost&lt;/TD&gt;&lt;TD&gt;vhost&lt;/TD&gt;&lt;TD&gt;total_vhost_cpus&lt;/TD&gt;&lt;TD&gt;total_fhost_cores&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;clusterx&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;f-hosta&lt;/TD&gt;&lt;TD&gt;v-hosta&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;clusterx&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;f-hosta&lt;/TD&gt;&lt;TD&gt;v-hostb&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;clusterx&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;f-hostb&lt;/TD&gt;&lt;TD&gt;v-hostc&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;clusterx&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;f-hostc&lt;/TD&gt;&lt;TD&gt;v-hostd&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Can you explain why this not what you expect? &amp;nbsp;What is the problem you are trying to solve using two eventstats command with raw events, not a stats?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 06:20:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654598#M226151</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-08-17T06:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize on distinct value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654617#M226159</link>
      <description>&lt;P&gt;Sorry, i was not clear. I am trying to get a sum of unique fhost by cluster.&lt;BR /&gt;&lt;BR /&gt;So the outcome should be&lt;BR /&gt;f-hosta cores=2 f-hostb cores=4 f-hostc cores=6&lt;BR /&gt;&lt;BR /&gt;2+4+6=10 in field "total_fhost_cores"&lt;BR /&gt;&lt;BR /&gt;Regards, Harry&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 07:30:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654617#M226159</guid>
      <dc:creator>hvdtol</dc:creator>
      <dc:date>2023-08-17T07:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize on distinct value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654634#M226162</link>
      <description>&lt;P&gt;Assuming cores relates to fhosts and cpus relates to vhosts, your data has mixed where these counts are coming from, so you need to split them out. Try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval clname="clusterx", fhost="f-hosta", vhost="v-hosta",cores=2,cpu=1
| append [| makeresults | eval clname="clusterx", fhost="f-hosta", vhost="v-hostb" ,cores=2,cpu=1 ]
| append [| makeresults | eval clname="clusterx", fhost="f-hostb", vhost="v-hostc" ,cores=4,cpu=1 ]
| append [| makeresults | eval clname="clusterx", fhost="f-hostc", vhost="v-hostd" ,cores=6,cpu=1 ]
| eval fhost-{fhost}=cores
| eventstats values(fhost-*) as fhost-cores-* by clname
| eval total_fhost_cores=0
| foreach fhost-cores-*
    [| eval total_fhost_cores=total_fhost_cores + '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']
| fields - fhost-*
| eventstats sum(cpu) as total_vhost_cpus by clname
| table clname cores cpu fhost vhost  total_vhost_cpus  total_fhost_cores&lt;/LI-CODE&gt;&lt;P&gt;btw, unless you are working in base 12, 2+4+6=12 not 10!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 09:22:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654634#M226162</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-08-17T09:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize on distinct value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654640#M226165</link>
      <description>&lt;P&gt;Of course is should be 12.&amp;nbsp; I am ashamed.&lt;span class="lia-unicode-emoji" title=":smirking_face:"&gt;😏&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But thank you very much&lt;/P&gt;&lt;P&gt;The | eval fhost-{fhost}=cores is a very nice solution&lt;BR /&gt;I did not know thos was possible.&lt;/P&gt;&lt;P&gt;Thank you for your help&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Harry&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 09:37:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Summarize-on-distinct-value/m-p/654640#M226165</guid>
      <dc:creator>hvdtol</dc:creator>
      <dc:date>2023-08-17T09:37:48Z</dc:date>
    </item>
  </channel>
</rss>

