<?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: Calculate the &amp;quot;month&amp;quot; after first appearance in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162214#M186007</link>
    <description>&lt;P&gt;Why not something like this&lt;/P&gt;

&lt;P&gt;... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval timestampMonth=relative_time(timestamp_of_first_appearance,"@mon")
| eval timestampMonth2=relative_time(timestamp_of_first_appearance,"+1mon@mon")
| eval timestampMonth3=relative_time(timestamp_of_first_appearance,"+2mon@mon")
| eval timestampEnd=relative_time(timestamp_of_first_appearance,"+3mon@mon")
| eval eventMonth = relative_time(timestamp_of_first_appearance,"@mon")
| eval whichMonth = case (eventMonth &amp;lt; timestampMonth,"before first appearance",
                                         eventMonth &amp;lt; timestampMonth2,"In month of appearance",
                                         eventMonth &amp;lt; timestampMonth3,"In second month since appearance",  
                                         eventMonth &amp;lt; timestampEnd,"In third month since appearance",
                                         1==1,"After third month of appearance")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 May 2014 01:25:00 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2014-05-15T01:25:00Z</dc:date>
    <item>
      <title>Calculate the "month" after first appearance</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162211#M186004</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm doing an analysis about users whose first event was in January 2014. I want to know, what they did in month 1,2,3 after their first appearance. For these users the January would be month "0". Feb would be "1", March  "2" and so on...&lt;/P&gt;

&lt;P&gt;So the goal is to add a field to every event: "month afer first appearance" with a numeric value.&lt;/P&gt;

&lt;P&gt;Is it possible to calculate to month after the first appearance?&lt;BR /&gt;
I already did something like this for the "day after first appearance". It looked like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| bucket span=1d timestamp_of_first_appearance
| bucket span=1d timestamp
| eval day=(timestamp-timestamp_of_first_appearance)/86400
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I can't do this for a monthly perspective, because the duration for the months varies&lt;/P&gt;

&lt;P&gt;BG&lt;/P&gt;

&lt;P&gt;Heinz&lt;/P&gt;</description>
      <pubDate>Tue, 13 May 2014 15:12:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162211#M186004</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2014-05-13T15:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the "month" after first appearance</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162212#M186005</link>
      <description>&lt;P&gt;How about adding this&lt;BR /&gt;
..your search..| eval month_of_first_appearance=tonumber(strftime(timestamp_of_first_appearance,"%m)) | eval month_of_current= tonumber(strftime(timestamp,"%m")) | eval month=if(month_of_current&amp;gt;month_of_first_appearance,month_of_current-month_of_first_appearance,12-month_of_first_appearance +month_of_current)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:35:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162212#M186005</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-09-28T16:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the "month" after first appearance</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162213#M186006</link>
      <description>&lt;P&gt;Thanks for your suggestion.&lt;BR /&gt;
Unfortunately this approach will cause problems, if month_of_current&amp;lt;=month_of_first_appearance.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:36:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162213#M186006</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2020-09-28T16:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the "month" after first appearance</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162214#M186007</link>
      <description>&lt;P&gt;Why not something like this&lt;/P&gt;

&lt;P&gt;... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval timestampMonth=relative_time(timestamp_of_first_appearance,"@mon")
| eval timestampMonth2=relative_time(timestamp_of_first_appearance,"+1mon@mon")
| eval timestampMonth3=relative_time(timestamp_of_first_appearance,"+2mon@mon")
| eval timestampEnd=relative_time(timestamp_of_first_appearance,"+3mon@mon")
| eval eventMonth = relative_time(timestamp_of_first_appearance,"@mon")
| eval whichMonth = case (eventMonth &amp;lt; timestampMonth,"before first appearance",
                                         eventMonth &amp;lt; timestampMonth2,"In month of appearance",
                                         eventMonth &amp;lt; timestampMonth3,"In second month since appearance",  
                                         eventMonth &amp;lt; timestampEnd,"In third month since appearance",
                                         1==1,"After third month of appearance")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 May 2014 01:25:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162214#M186007</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-05-15T01:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the "month" after first appearance</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162215#M186008</link>
      <description>&lt;P&gt;Hi lguinn,&lt;/P&gt;

&lt;P&gt;I've adjusted your approach to this and it seems to work fine:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| bucket span=1mon _time
| lookup lookup.csv userid OUTPUT first_appearance
| bucket span=1mon first_appearance

| eval month0=relative_time(first_appearance,"@mon")
| eval month1=relative_time(first_appearance,"+1mon@mon")
| eval month2=relative_time(first_appearance,"+2mon@mon")
| eval month3=relative_time(first_appearance,"+3mon@mon")
| eval month4=relative_time(first_appearance,"+4mon@mon")
| eval month5=relative_time(first_appearance,"+5mon@mon")
| eval month6=relative_time(first_appearance,"+6mon@mon")
.
.
.
| eval month_after_appearance=case(_time=month0, "0",
 _time=month1, "1",
 _time=month2, "2",
 _time=month3, "3",
 _time=month4, "4",
 _time=month5, "5",
 _time=month6, "6",)
.
.
.

| stats dc(userid) by month_after_appearance
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2014 12:35:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-the-quot-month-quot-after-first-appearance/m-p/162215#M186008</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2014-05-15T12:35:25Z</dc:date>
    </item>
  </channel>
</rss>

