<?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 get the month name for selecting previous month via date_month? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321825#M161822</link>
    <description>&lt;P&gt;Nope. Still way too complex. The users don't need to be able to select a month, we just need to be able to show them last month's data over the same month a year ago. We have a very seasonal business, and we want them to see how things have changed year over year for the most recent month.&lt;BR /&gt;
That's why I need to be able to limit the search to just the specified month name/number. If this were June of 2018, I want to display the sum of the counts for May of 2018 AND May of 2017.&lt;BR /&gt;
Accordingly, I went on a dig and read a lot more documentation and examples, and came up with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;tag=PeopleCounters earliest=-13mon@mon latest=@mon 
 | eval lastMonth=strftime(relative_time(now(),"-1mon@mon"),"%B")
 | where match(date_month,lower(lastMonth))
 | chart sum(count) as Traffic by date_year
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This does what I wanted. Thanks for trying!&lt;/P&gt;</description>
    <pubDate>Fri, 06 Apr 2018 16:49:03 GMT</pubDate>
    <dc:creator>aaron_sakovich</dc:creator>
    <dc:date>2018-04-06T16:49:03Z</dc:date>
    <item>
      <title>How to get the month name for selecting previous month via date_month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321820#M161817</link>
      <description>&lt;P&gt;We've got the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;tag=PeopleCounters earliest=-13mon@mon latest=@mon date_month=March
| chart sum(count) as Traffic by date_year
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This winds up looking great, giving us two bars -- one each for a month, year over year (e.g., March 2017 vs. March 2018). &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    date_year  Traffic
    2017       109113
    2018       126805
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, we want the date_month in the search to be variable so that we can put this in a dashboard panel, so the search only pulls data that happened in March (or next month, April).&lt;BR /&gt;
Suggestions on how to evaluate what the name of the previous month was and embed that into the search?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 21:53:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321820#M161817</guid>
      <dc:creator>aaron_sakovich</dc:creator>
      <dc:date>2018-04-05T21:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the month name for selecting previous month via date_month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321821#M161818</link>
      <description>&lt;P&gt;tag=PeopleCounters earliest=-13mon@mon latest=@mon date_month=March&lt;BR /&gt;
 | chart sum(count) as Traffic by date_year | where date_year&amp;gt;2016&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:53:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321821#M161818</guid>
      <dc:creator>sravankaripe</dc:creator>
      <dc:date>2020-09-29T18:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the month name for selecting previous month via date_month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321822#M161819</link>
      <description>&lt;P&gt;Nice try, but I've already limited the range of years with the &lt;A href="mailto:-13mon@mon"&gt;-13mon@mon&lt;/A&gt;. Instead, I need a variable with the month name so that I can search for date_month=$lastmonth$.&lt;BR /&gt;
Hope that makes more sense.&lt;BR /&gt;
Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 22:17:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321822#M161819</guid>
      <dc:creator>aaron_sakovich</dc:creator>
      <dc:date>2018-04-05T22:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the month name for selecting previous month via date_month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321823#M161820</link>
      <description>&lt;P&gt;Okay, so you have two different items here - the search time range, and the year-over-year comparison.&lt;/P&gt;

&lt;P&gt;This gets you all the data for the last 24 months.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search id="monthbase"&amp;gt;
   &amp;lt;query&amp;gt;
   tag=PeopleCounters 
   | eval month_num=strftime(_time,"%m")
   | stats  max(date_month) as date_month sum(count) as Traffic by date_year month_num 
   &amp;lt;/query&amp;gt;
   &amp;lt;earliest&amp;gt;-24mon@mon&amp;lt;/earliest&amp;gt; 
   &amp;lt;latest&amp;gt;@mon&amp;lt;/latest&amp;gt;
&amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above search gives you a nice little table that has this layout.  &lt;CODE&gt;| table date_year month_num date_month Traffic&lt;/CODE&gt; You do not need the &lt;CODE&gt;table&lt;/CODE&gt; code, it's just to show you the record format at that point. Put the above in a base search in your dashboard, and let them choose the month from a dropdown. Populate the dropdown with that same base search after passing it through this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;input type="dropdown" token="month_nbr"&amp;gt;
   &amp;lt;search base="monthbase"&amp;gt;
   &amp;lt;query&amp;gt;
    | stats max(date_month) as date_month by month_num
   &amp;lt;/query&amp;gt;
&amp;lt;/search&amp;gt;
&amp;lt;fieldForLabel&amp;gt;date_month&amp;lt;/fieldForLabel&amp;gt;
&amp;lt;fieldForValue&amp;gt;month_num&amp;lt;/fieldForValue&amp;gt;
&amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above dropdown will set the token &lt;CODE&gt;$month_nbr$&lt;/CODE&gt; to the selected value for &lt;CODE&gt;month_num&lt;/CODE&gt;.  (We only changed the name so you can see which is which.)&lt;/P&gt;

&lt;P&gt;Finally, in the dashboard panel, use a postprocess query/filter, with the same base search and a filter on the token selected from the dropdown to select only the month they want, which will give you exactly two values, just like your original search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   &amp;lt;search base="monthbase"&amp;gt;
     &amp;lt;query&amp;gt;
     | where month_num = $month_nbr$
     | chart sum(Traffic) as Traffic by date_year
     &amp;lt;/query&amp;gt;    
   &amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 01:56:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321823#M161820</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-04-06T01:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the month name for selecting previous month via date_month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321824#M161821</link>
      <description>&lt;P&gt;If you wanted, you could set a  token off the base search in order to set a default for the dropdown.  You'd do this by grabbing the last record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search base="monthbase"&amp;gt;
  &amp;lt;query&amp;gt;
  | tail 1
  | table month_num 
  &amp;lt;/query&amp;gt;    
  &amp;lt;done&amp;gt;
        &amp;lt;set token="month_nbr"&amp;gt;$result.month_num$&amp;lt;/set&amp;gt;
   &amp;lt;/done&amp;gt;
&amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 02:06:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321824#M161821</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-04-06T02:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the month name for selecting previous month via date_month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321825#M161822</link>
      <description>&lt;P&gt;Nope. Still way too complex. The users don't need to be able to select a month, we just need to be able to show them last month's data over the same month a year ago. We have a very seasonal business, and we want them to see how things have changed year over year for the most recent month.&lt;BR /&gt;
That's why I need to be able to limit the search to just the specified month name/number. If this were June of 2018, I want to display the sum of the counts for May of 2018 AND May of 2017.&lt;BR /&gt;
Accordingly, I went on a dig and read a lot more documentation and examples, and came up with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;tag=PeopleCounters earliest=-13mon@mon latest=@mon 
 | eval lastMonth=strftime(relative_time(now(),"-1mon@mon"),"%B")
 | where match(date_month,lower(lastMonth))
 | chart sum(count) as Traffic by date_year
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This does what I wanted. Thanks for trying!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 16:49:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321825#M161822</guid>
      <dc:creator>aaron_sakovich</dc:creator>
      <dc:date>2018-04-06T16:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the month name for selecting previous month via date_month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321826#M161823</link>
      <description>&lt;P&gt;Sure.  So, you really have users who never ever need to see the prior month?  Interesting.  &lt;/P&gt;

&lt;P&gt;Glad you got what you needed.  &lt;/P&gt;</description>
      <pubDate>Sun, 08 Apr 2018 18:07:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321826#M161823</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-04-08T18:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the month name for selecting previous month via date_month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321827#M161824</link>
      <description>&lt;P&gt;Oh, sure they do, but that’s easy, and in a different panel on their dashboard; they get to see the whole of the previous 3 years with an annual timewrap. This single month over month is just a single panel on that dashboard that they’re used to seeing from our old manually collected and processed stats report.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 13:09:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321827#M161824</guid>
      <dc:creator>aaron_sakovich</dc:creator>
      <dc:date>2018-04-09T13:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the month name for selecting previous month via date_month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321828#M161825</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/37207"&gt;@aaron_sakovich&lt;/a&gt;, try the following dashboard. It uses a dummy search to set the previous month as token to be used in the base search of your query. This way you will be filtering &lt;CODE&gt;date_month&lt;/CODE&gt; as previous month in your base search itself. This would run faster as in your current search you are pulling last 13 months data and then filtering 2 months data afterward.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard&amp;gt;
  &amp;lt;label&amp;gt;Filter records for previous month over year&amp;lt;/label&amp;gt;
  &amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;| makeresults
      | eval prevMonth=lower(strftime(relative_time(_time,"-1mon@d"),"%B"))
      | fields - _time
    &amp;lt;/query&amp;gt;
    &amp;lt;progress&amp;gt;
      &amp;lt;set token="tokPrevMonth"&amp;gt;$result.prevMonth$&amp;lt;/set&amp;gt;
    &amp;lt;/progress&amp;gt;
  &amp;lt;/search&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Previous Month: $tokPrevMonth$&amp;lt;/title&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;tag=PeopleCounters  date_month="$tokPrevMonth$"
| chart count as Traffic by date_year&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-13mon@mon&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;@mon&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please try out and confirm.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:57:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-month-name-for-selecting-previous-month-via-date/m-p/321828#M161825</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T18:57:20Z</dc:date>
    </item>
  </channel>
</rss>

