<?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 calculate median, avg for total results? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635531#M220795</link>
    <description>&lt;P&gt;hey,&lt;/P&gt;
&lt;P&gt;I need to build a report, that contains approx 500 thousand events. the requirement is&amp;nbsp;&amp;nbsp;that the report will contain three rows -&lt;BR /&gt;I need to count if httpStatus is ok or not, and classify each eventId in its propper position. (the requirement is that we will have &lt;STRONG&gt;minimal&lt;/STRONG&gt; amount of rows!!! I cant duplicate or have more then 10 rows)&lt;BR /&gt;&lt;BR /&gt;so basically the report looks like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="badbuda_0-1679503456831.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24438i544BF03C909A7C62/image-size/medium?v=v2&amp;amp;px=400" role="button" title="badbuda_0-1679503456831.png" alt="badbuda_0-1679503456831.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I have uri column that contains all of my desired info, and all of my calculations of median, avg, precentage etc, are based on the time field as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;|*MY SEARCH *
|stats count(request.uri) as totalCount values(uri) as uri values(timeTaken.total) as newTime perc95(timeTaken.total) as prec95 perc5(timeTaken.total) as prec5 median(timeTaken.total) as med avg(timeTaken.total) as average max(date) as maxDate 
min(date) as minDate values(timeTaken.total) as time by status 

|table  uri totalCount prec95 prec5 med average status maxDate minDate time&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;now my question is-&lt;/P&gt;
&lt;P&gt;I need to add a new line of totals, based on the other lines.&lt;/P&gt;
&lt;P&gt;beacuse Im using functions such as avg, median etc, I dont think I can use |addtotals&lt;/P&gt;
&lt;P&gt;and a very important note is that all of my values in the columns time and uri are &lt;U&gt;&lt;STRONG&gt;not distinct&lt;/STRONG&gt;&lt;/U&gt;. that means they &lt;U&gt;&lt;STRONG&gt;can appear more then once&lt;/STRONG&gt;&lt;/U&gt;, and then my calculations are wrong, and I cant base a following stats based on the previous one. Ive tried using &lt;STRONG&gt;list&lt;/STRONG&gt;, but it has a limit of 100 values, and I have&amp;nbsp; hundred of thousands.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;what can I do to add another total row that will calculate all of my events ?&lt;/P&gt;
&lt;P&gt;Ive tried adding |appendPipe it this way based on the results Ive gotten in the stats command, but of course I got wrong values (because the time result is not distinct, and the values shown in the stats are distinct)&lt;/P&gt;
&lt;P&gt;thats my report after adding the total calculation (that didnt work)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="badbuda_1-1679504496994.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24439i74D56510AF85E2F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="badbuda_1-1679504496994.png" alt="badbuda_1-1679504496994.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;|*MY SEARCH *
|stats count(request.uri) as totalCount values(uri) as uri values(timeTaken.total) as newTime perc95(timeTaken.total) as prec95 perc5(timeTaken.total) as prec5 median(timeTaken.total) as med avg(timeTaken.total) as average max(date) as maxDate 
min(date) as minDate values(timeTaken.total) as time by status 

|appendpipe [stats sum(totalCount) as totalCount  values(uri) as uri values(newTime) as newTime perc95(time) as prec95 perc5(time) as prec5 median(time) as med avg(time) as average| eval status="TOTAL"]

|table  uri totalCount prec95 prec5 med average status maxDate minDate time&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really hope that Ive made my question clear&lt;/P&gt;
&lt;P&gt;thank's in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2023 20:35:55 GMT</pubDate>
    <dc:creator>badbuda</dc:creator>
    <dc:date>2023-03-22T20:35:55Z</dc:date>
    <item>
      <title>How to calculate median, avg for total results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635531#M220795</link>
      <description>&lt;P&gt;hey,&lt;/P&gt;
&lt;P&gt;I need to build a report, that contains approx 500 thousand events. the requirement is&amp;nbsp;&amp;nbsp;that the report will contain three rows -&lt;BR /&gt;I need to count if httpStatus is ok or not, and classify each eventId in its propper position. (the requirement is that we will have &lt;STRONG&gt;minimal&lt;/STRONG&gt; amount of rows!!! I cant duplicate or have more then 10 rows)&lt;BR /&gt;&lt;BR /&gt;so basically the report looks like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="badbuda_0-1679503456831.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24438i544BF03C909A7C62/image-size/medium?v=v2&amp;amp;px=400" role="button" title="badbuda_0-1679503456831.png" alt="badbuda_0-1679503456831.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I have uri column that contains all of my desired info, and all of my calculations of median, avg, precentage etc, are based on the time field as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;|*MY SEARCH *
|stats count(request.uri) as totalCount values(uri) as uri values(timeTaken.total) as newTime perc95(timeTaken.total) as prec95 perc5(timeTaken.total) as prec5 median(timeTaken.total) as med avg(timeTaken.total) as average max(date) as maxDate 
min(date) as minDate values(timeTaken.total) as time by status 

|table  uri totalCount prec95 prec5 med average status maxDate minDate time&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;now my question is-&lt;/P&gt;
&lt;P&gt;I need to add a new line of totals, based on the other lines.&lt;/P&gt;
&lt;P&gt;beacuse Im using functions such as avg, median etc, I dont think I can use |addtotals&lt;/P&gt;
&lt;P&gt;and a very important note is that all of my values in the columns time and uri are &lt;U&gt;&lt;STRONG&gt;not distinct&lt;/STRONG&gt;&lt;/U&gt;. that means they &lt;U&gt;&lt;STRONG&gt;can appear more then once&lt;/STRONG&gt;&lt;/U&gt;, and then my calculations are wrong, and I cant base a following stats based on the previous one. Ive tried using &lt;STRONG&gt;list&lt;/STRONG&gt;, but it has a limit of 100 values, and I have&amp;nbsp; hundred of thousands.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;what can I do to add another total row that will calculate all of my events ?&lt;/P&gt;
&lt;P&gt;Ive tried adding |appendPipe it this way based on the results Ive gotten in the stats command, but of course I got wrong values (because the time result is not distinct, and the values shown in the stats are distinct)&lt;/P&gt;
&lt;P&gt;thats my report after adding the total calculation (that didnt work)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="badbuda_1-1679504496994.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24439i74D56510AF85E2F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="badbuda_1-1679504496994.png" alt="badbuda_1-1679504496994.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;|*MY SEARCH *
|stats count(request.uri) as totalCount values(uri) as uri values(timeTaken.total) as newTime perc95(timeTaken.total) as prec95 perc5(timeTaken.total) as prec5 median(timeTaken.total) as med avg(timeTaken.total) as average max(date) as maxDate 
min(date) as minDate values(timeTaken.total) as time by status 

|appendpipe [stats sum(totalCount) as totalCount  values(uri) as uri values(newTime) as newTime perc95(time) as prec95 perc5(time) as prec5 median(time) as med avg(time) as average| eval status="TOTAL"]

|table  uri totalCount prec95 prec5 med average status maxDate minDate time&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really hope that Ive made my question clear&lt;/P&gt;
&lt;P&gt;thank's in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 20:35:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635531#M220795</guid>
      <dc:creator>badbuda</dc:creator>
      <dc:date>2023-03-22T20:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: calculating median, avg for total results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635551#M220804</link>
      <description>&lt;P&gt;Since you know the names of all of the fields, there's no reason why you can't use &lt;FONT face="courier new,courier"&gt;addtotals&lt;/FONT&gt; or (better) &lt;FONT face="courier new,courier"&gt;addcoltotals&lt;/FONT&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|*MY SEARCH *
|stats count(request.uri) as totalCount values(uri) as uri values(timeTaken.total) as newTime perc95(timeTaken.total) as prec95 perc5(timeTaken.total) as prec5 median(timeTaken.total) as med avg(timeTaken.total) as average max(date) as maxDate 
min(date) as minDate values(timeTaken.total) as time by status 

|table  uri totalCount prec95 prec5 med average status maxDate minDate time
|addcoltotals totalCount prec95 prec5 med average &lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 22 Mar 2023 19:22:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635551#M220804</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-03-22T19:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: calculating median, avg for total results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635552#M220805</link>
      <description>&lt;P&gt;Thank you for your answer,&lt;/P&gt;&lt;P&gt;But can I add averages (and medians, percentiles etc)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Addcoltotals will just sum these fields together, won't it?&lt;/P&gt;&lt;P&gt;Adding two averages together won't give me the right average I'm looking for&lt;/P&gt;&lt;P&gt;Am I wrong?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 19:38:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635552#M220805</guid>
      <dc:creator>badbuda</dc:creator>
      <dc:date>2023-03-22T19:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: calculating median, avg for total results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635555#M220806</link>
      <description>&lt;P&gt;You're absolutely right. Adding two averages doesn't give you a "total average" of course.&lt;/P&gt;&lt;P&gt;It seems your original idea was OK, just had small mistakes in the middle.&lt;/P&gt;&lt;PRE&gt;|*MY SEARCH *
|stats count(request.uri) as totalCount values(uri) as uri values(timeTaken.total) as newTime perc95(timeTaken.total) as prec95 perc5(timeTaken.total) as prec5 median(timeTaken.total) as med avg(timeTaken.total) as average max(date) as maxDate 
min(date) as minDate values(timeTaken.total) as time by status 

|appendpipe [stats count(request.uri) as totalCount values(uri) as uri values(timeTaken.total) as newTime perc95(timeTaken.total) as prec95 perc5(timeTaken.total) as prec5 median(timeTaken.total) as med avg(timeTaken.total) as average max(date) as maxDate min(date) as minDate values(timeTaken.total) as time| eval status="TOTAL"]&lt;/PRE&gt;&lt;P&gt;And you don't need table at the end.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 20:23:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635555#M220806</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-03-22T20:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: calculating median, avg for total results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635616#M220829</link>
      <description>&lt;P&gt;thanks, thats exactly what I tried doing at the beginning&lt;/P&gt;&lt;P&gt;but after doing stats for the first time, if Im not saving my fields in stats command, they will not appear in the following query. is there any way of saving previous data before stats command?&lt;/P&gt;&lt;P&gt;I did exactly as you said and these are my results&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="badbuda_0-1679550227238.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24459i2C7F6D2D2FC5FFB4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="badbuda_0-1679550227238.png" alt="badbuda_0-1679550227238.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 05:44:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635616#M220829</guid>
      <dc:creator>badbuda</dc:creator>
      <dc:date>2023-03-23T05:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate median, avg for total results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635619#M220831</link>
      <description>&lt;P&gt;I think I found my solution!&lt;BR /&gt;I've changed the first stats command to another appendpipe, so it wont ruin the totals-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|appendpipe [stats count(request.uri) as totalCount values(uri) as uri values(timeTaken.total) as newTime perc95(timeTaken.total) as prec95 perc5(timeTaken.total) as prec5 median(timeTaken.total) as med avg(timeTaken.total) as average max(date) as maxDate min(date) as minDate| eval finalStatus="TOTAL"]
|appendpipe [stats count(request.uri) as totalCount values(uri) as uri values(timeTaken.total) as newTime perc95(timeTaken.total) as prec95 perc5(timeTaken.total) as prec5 median(timeTaken.total) as med avg(timeTaken.total) as average max(date) as maxDate
min(date) as minDate values(timeTaken.total) as time by status | eval finalStatus="ok"]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now my results seems to make sense.&lt;BR /&gt;&lt;BR /&gt;thank you all!&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 06:15:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635619#M220831</guid>
      <dc:creator>badbuda</dc:creator>
      <dc:date>2023-03-23T06:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: calculating median, avg for total results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635635#M220835</link>
      <description>&lt;P&gt;Ahh, right. I don't often use appendpipe so I got confused by the example in the docs. Yes, appendpipe operates at the already aggregated values so it won't be very helpful here.&lt;/P&gt;&lt;P&gt;Unfortunately if you have a parameter which has to be calculated over the whole set you can't calculate it partially &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; Your solution will skew results a bit because with the first appendpipe you change the overall count of the results. And if I'm not mistaken it will not be that much more effective than eventstat so you could probably use that one instead.&lt;/P&gt;&lt;P&gt;The other solution could be to "manually" calculate the parameters - but that could be tedious.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 07:51:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-median-avg-for-total-results/m-p/635635#M220835</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-03-23T07:51:19Z</dc:date>
    </item>
  </channel>
</rss>

