<?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 evaluated columns into 3 specific columns  ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340557#M159652</link>
    <description>&lt;P&gt;@AditiKhare - You are quite welcome.  I added a line to the end of my code to give you your totals.  you can use the same line ( modify the &lt;CODE&gt;labelfield&lt;/CODE&gt; argument) after @woodcock's solution as well.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2017 18:14:43 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-08-02T18:14:43Z</dc:date>
    <item>
      <title>How to group evaluated columns into 3 specific columns  ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340552#M159647</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I am very new to splunk and wanted to know if someone can help me in groping columns fo rmy query below : &lt;BR /&gt;
source="metric.log" sourcetype="alerts" | &lt;BR /&gt;
eval Diff=strptime(alertTs, "%Y-%m-%d %H:%M:%S")-strpTime(tranTs, "%Y-%m-%d %H:%M:%S") |&lt;BR /&gt;
stats count(alertId) as Total, &lt;BR /&gt;
count(eval(Diff&amp;lt;60)) as Less_Than_1M, &lt;BR /&gt;
count(eval(Diff&amp;gt;=60 and Diff&amp;lt;300)) as Within_1M_5M, &lt;BR /&gt;
count(eval(Diff&amp;gt;=300)) as Greater_Than_5M|&lt;BR /&gt;
eval percent_Less_Than_1M=((Less_Than_1M/Total)*100)|&lt;BR /&gt;
eval percent_Within_1M_5M=((Within_1M_5M/Total)*100)|&lt;BR /&gt;
eval percent_Greater_Than_5M=((Greater_Than_5M/Total)*100)|&lt;BR /&gt;
stats values(Less_Than_1M) as Count_Less_Than_1min, values(percent_Less_Than_1M) as Percent_Less_Than_1min,&lt;BR /&gt;
 values(Within_1M_5M) as Count_Between_1-5min, values(percent_Within_1M_5M) as Percent_Between_1-5min,&lt;BR /&gt;
 values(Greater_Than_5M) as Count_More_Than_5min, values(percent_Greater_Than_5M) as Percent_More_Than_5min &lt;/P&gt;

&lt;P&gt;I want to display a table like this : &lt;BR /&gt;
&lt;IMG src="https://community.splunk.com/storage/temp/208757-output.jpg" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Thankyou for help &lt;BR /&gt;
Aditi&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:07:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340552#M159647</guid>
      <dc:creator>AditiKhare</dc:creator>
      <dc:date>2020-09-29T15:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to group evaluated columns into 3 specific columns  ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340553#M159648</link>
      <description>&lt;P&gt;Add this to the bottom of your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| transpose
| rename column AS "Time Range" "row 1" AS Count
| eventstats sum(Count) AS Total
| eval Percentage = round(100*Count/Total,2)
| fields - Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2017 00:38:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340553#M159648</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-02T00:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to group evaluated columns into 3 specific columns  ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340554#M159649</link>
      <description>&lt;P&gt;This version simplifies your entire search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="metric.log" sourcetype="alerts" 
| eval Diff=strptime(alertTs, "%Y-%m-%d %H:%M:%S")-strpTime(tranTs, "%Y-%m-%d %H:%M:%S") 
| stats count(eval(Diff&amp;lt;60)) as 1Less_Than_1min, 
        count(eval(Diff&amp;gt;=60 and Diff&amp;lt;300)) as 2Between_1-5min, 
        count(eval(Diff&amp;gt;=300)) as 3Greater_Than_5min
| rename COMMENT as "The above gets the count from the three possible timeframes. Use the names you want for the time ranges, with a one-digit number in front to set their sort order."


| rename COMMENT as "The following simulates the above search language.  User this line instead of the above for a run-anywhere test, delete it and use the above instead for your real data. "
| makeresults | eval 1Less_Than_1min = 15 , 2Between_1-5min=3,  3Greater_Than_5min=2


| rename COMMENT as "This section breaks up the three values into separate transactions, calculates the total and percentage, then gets rid of unneeded fields"
| eval junk=1
| untable junk TimeRange Count
| eventstats sum(Count) as Total
| eval Percentage=round(100*Count/Total,2)
| fields - junk - Total

| rename COMMENT as "Finally, we get rid of the number on the front that forces the sort order, and add totals at the end."
| rex mode=sed field=TimeRange "s/^\d//"
| addtotals row=f col=t labelfield=TimeRange label="Total"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;With this result...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TimeRange         Count Percentage
Less_Than_1min       15   75.00  
Between_1-5min        3   15.00  
Greater_Than_5min     2   10.00  
Total                20  100.00
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;updated to add totals.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 14:59:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340554#M159649</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-02T14:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to group evaluated columns into 3 specific columns  ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340555#M159650</link>
      <description>&lt;P&gt;Thankyou so much for the solution. it worked. Also, can i add Total in the last row ?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 18:01:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340555#M159650</guid>
      <dc:creator>AditiKhare</dc:creator>
      <dc:date>2017-08-02T18:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to group evaluated columns into 3 specific columns  ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340556#M159651</link>
      <description>&lt;P&gt;Thankyou so much for the detailed comments and answer it worked.  This is really helpful for me to understand splunk queries.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 18:03:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340556#M159651</guid>
      <dc:creator>AditiKhare</dc:creator>
      <dc:date>2017-08-02T18:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to group evaluated columns into 3 specific columns  ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340557#M159652</link>
      <description>&lt;P&gt;@AditiKhare - You are quite welcome.  I added a line to the end of my code to give you your totals.  you can use the same line ( modify the &lt;CODE&gt;labelfield&lt;/CODE&gt; argument) after @woodcock's solution as well.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 18:14:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340557#M159652</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-02T18:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to group evaluated columns into 3 specific columns  ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340558#M159653</link>
      <description>&lt;P&gt;@DalJeanis - Thanks alot.. this worked too. M really thankful &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 18:26:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340558#M159653</guid>
      <dc:creator>AditiKhare</dc:creator>
      <dc:date>2017-08-02T18:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to group evaluated columns into 3 specific columns  ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340559#M159654</link>
      <description>&lt;P&gt;Add these 2 lines:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| addtotals col=t row=f
| fillnull value="TOTAL"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2017 23:37:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-evaluated-columns-into-3-specific-columns/m-p/340559#M159654</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-02T23:37:20Z</dc:date>
    </item>
  </channel>
</rss>

