<?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 edit my search to calculate the average number of tickets per week based on categories? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-the-average-number-of-tickets/m-p/227613#M67224</link>
    <description>&lt;P&gt;I am trying to determine the average number of tickets per week based on the unique number of categories for the tickets.&lt;/P&gt;

&lt;P&gt;I can run a search with a stat count to get the number of tickets by week number:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="tickets" | eval dateyearweek=strftime(_time,"%Y-%W") | eval Day1ofWeek = strftime(relative_time(_time,"@w1"),"%Y/%m/%d") | stats count by Day1ofWeek | sort -date_year | rename Day1ofWeek to "Week Starting"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can also run a search with stat dc(category) to get the unique number categories by week&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="tickets" | eval dateyearweek=strftime(_time,"%Y-%W") | eval Day1ofWeek = strftime(relative_time(_time,"@w1"),"%Y/%m/%d") | stats dc(category) by Day1ofWeek | sort -date_year | rename Day1ofWeek to "Week Starting"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am trying to determine the average number of tickets by category, but cannot figure out how to do the calculation.&lt;/P&gt;

&lt;P&gt;Should I use an append to do a new search inside the first search with an eval to then do the calculation?   I am a little stuck on the whole combining multiple search results.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jan 2017 23:52:39 GMT</pubDate>
    <dc:creator>pdumblet</dc:creator>
    <dc:date>2017-01-11T23:52:39Z</dc:date>
    <item>
      <title>How to edit my search to calculate the average number of tickets per week based on categories?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-the-average-number-of-tickets/m-p/227613#M67224</link>
      <description>&lt;P&gt;I am trying to determine the average number of tickets per week based on the unique number of categories for the tickets.&lt;/P&gt;

&lt;P&gt;I can run a search with a stat count to get the number of tickets by week number:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="tickets" | eval dateyearweek=strftime(_time,"%Y-%W") | eval Day1ofWeek = strftime(relative_time(_time,"@w1"),"%Y/%m/%d") | stats count by Day1ofWeek | sort -date_year | rename Day1ofWeek to "Week Starting"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can also run a search with stat dc(category) to get the unique number categories by week&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="tickets" | eval dateyearweek=strftime(_time,"%Y-%W") | eval Day1ofWeek = strftime(relative_time(_time,"@w1"),"%Y/%m/%d") | stats dc(category) by Day1ofWeek | sort -date_year | rename Day1ofWeek to "Week Starting"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am trying to determine the average number of tickets by category, but cannot figure out how to do the calculation.&lt;/P&gt;

&lt;P&gt;Should I use an append to do a new search inside the first search with an eval to then do the calculation?   I am a little stuck on the whole combining multiple search results.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 23:52:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-the-average-number-of-tickets/m-p/227613#M67224</guid>
      <dc:creator>pdumblet</dc:creator>
      <dc:date>2017-01-11T23:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate the average number of tickets per week based on categories?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-the-average-number-of-tickets/m-p/227614#M67225</link>
      <description>&lt;P&gt;First, calculate the number of tickets by category for the week:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| stats count by category
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To get the average number of tickets across all categories&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| stats count as Tickets by category
| appendpipe [ stats count as numCategories sum(Tickets) as TotalTickets
               | eval Tickets = round(TotalTicket/numCategories,2) 
               | fields Tickets | eval category="* Average number of tickets" ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are several ways to do this, but I think that this looks best. If you want to do this week-by-week:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| timechart span=1w count as Tickets by category
| addtotals
| appendpipe [ stats sum(*) as * count as TotalWeeks 
          | foreach * [eval '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'=if(isnum('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),round('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'/TotalWeeks,2),"") ] 
          | fields - TotalWeeks | eval category="* Average number of tickets" ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;HTH!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 00:23:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-the-average-number-of-tickets/m-p/227614#M67225</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2017-01-12T00:23:46Z</dc:date>
    </item>
  </channel>
</rss>

