<?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: search a value in previous time period and add to current count in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566121#M197279</link>
    <description>&lt;P&gt;ah, eventstats!&lt;/P&gt;&lt;P&gt;so with eventstats I got a value of max logincount for example 10&lt;/P&gt;&lt;P&gt;after I've looked how often the user (who has the max logincount in the first search) logged in the past week , for example 5 times, I want to add this to the max logincount so 10+5 = 15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Sep 2021 11:54:51 GMT</pubDate>
    <dc:creator>avoelk</dc:creator>
    <dc:date>2021-09-07T11:54:51Z</dc:date>
    <item>
      <title>search a value in previous time period and add to current count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566103#M197268</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is it possible to search a field value and then count it for example first the current week and then add the count of the same search from the week before ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;something like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;index=indexa action=allowed app=DNS dest="8.8.8.8" earliest=-14d latest=-7d&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval flag="count1"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| append&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;[search index=indexa action=allowed app=DNS dest="8.8.8.8" earliest=-7d latest=now()&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval flag="count2"]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| stats count(eval(flag="count1")) as count1 count(eval(flag="count2")) as count2&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval count = count1+count2&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Something in my use of the earliest/latest doesn't seem to work. what am I doing wrong?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 09:40:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566103#M197268</guid>
      <dc:creator>avoelk</dc:creator>
      <dc:date>2021-09-07T09:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: search a value in previous time period and add to current count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566104#M197269</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/228376"&gt;@avoelk&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to group by weeks then it might be easier to do something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=indexa action=allowed app=DNS dest="8.8.8.8" earliest=-1w@w
| bucket span=1w _time
| stats count by _time
| eventstats sum(count) as total_count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or use timechart:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=indexa action=allowed app=DNS dest="8.8.8.8" earliest=-1w@w
| timechart span=1w count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if that works for you. Alternatively, if you want full weeks, then simply use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;earliest=-2w@w latest=@w&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 10:06:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566104#M197269</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2021-09-07T10:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: search a value in previous time period and add to current count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566108#M197272</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/113132"&gt;@javiergn&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;thanks a lot. that worked too. is there a way to, if I'd have a field in which the maximum login count for a certain user resides, to add the amount of appearances this user logged in the week before?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so :&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;index=indexa action=allowed app=DNS logincount=*&amp;nbsp; earliest=-7d latest=now()&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| stats max(logincount) as max_count&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval flag="count1"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| append&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;[search index=indexa action=allowed app=DNS logincount=* earliest=-14d latest=-7d&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| stats count(if(max_count=logincount,1,0) as add_count&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval flag="count2"]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| stats count(eval(flag="count1")) as count1 count(eval(flag="count2")) as count2&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval count = count1+count2&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;but I know this doesn't work since the subsearch doesn't know what I mean with max_count=logincount. It's hard to explain .. in that case it should be like &lt;EM&gt;&lt;STRONG&gt;count the maximum login count within this week and show me the user, then look how often this user logged in the week before and add this amount to my current count.&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 10:43:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566108#M197272</guid>
      <dc:creator>avoelk</dc:creator>
      <dc:date>2021-09-07T10:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: search a value in previous time period and add to current count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566117#M197277</link>
      <description>&lt;P&gt;Yes, kind of, the key is to do one thing at a time.&lt;/P&gt;&lt;P&gt;Your friend is eventstats in this case. So taking your description above and doing this step by step:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;count the maximum login count within this week &lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats max(logincount) as max_count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;and show me the user (assuming there is a field called user in this case):&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval myuser = if(logincount = max_count, user, null())&lt;/LI-CODE&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;then look how often this user logged in the week before &lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| bucket span=1w _time
| eventstats count(eval(if(user=myuser,1,null()))) as myuser_count by _time&lt;/LI-CODE&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;and add this amount to my current count.&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This is the bit I don't get. Add it to which current count?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 11:47:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566117#M197277</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2021-09-07T11:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: search a value in previous time period and add to current count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566121#M197279</link>
      <description>&lt;P&gt;ah, eventstats!&lt;/P&gt;&lt;P&gt;so with eventstats I got a value of max logincount for example 10&lt;/P&gt;&lt;P&gt;after I've looked how often the user (who has the max logincount in the first search) logged in the past week , for example 5 times, I want to add this to the max logincount so 10+5 = 15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 11:54:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566121#M197279</guid>
      <dc:creator>avoelk</dc:creator>
      <dc:date>2021-09-07T11:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: search a value in previous time period and add to current count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566131#M197285</link>
      <description>&lt;P&gt;Something like the below perhaps (not tested obviously so there might be typos):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=indexa action=allowed app=DNS dest="8.8.8.8" earliest=-2w@w latest=@w 
| bucket span=1w _time
| eval mytime = if(_time=relative_time(now(), "-2w@w"), "last_week", "this_week")
| eventstats max(logincount) as max_count by mytime
| eval max_count_this_week=if(mytime="this_week", max_count, null())
| eventstats values(max_count_this_week) as max_count_this_week
| eval user_this_week = if(logincount = max_count_this_week AND mytime="this_week", user, null())
| eventstats count by _time, user
| eval final_count = if(user=user_this_week AND time="last_week", count+max_count_this_week, null())
| stats values(final_count) by user, mytime&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where you search across 2 weeks and create the variable mytime with two labels: "last_week" and "this_week" for readability.&lt;/P&gt;&lt;P&gt;Then calculate the max logincount this week and the user with that logincount, which then use to calculate the final count based on the user this week but the time period being last week.&lt;/P&gt;&lt;P&gt;The final stats is just to show you in tabular format.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 12:56:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566131#M197285</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2021-09-07T12:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: search a value in previous time period and add to current count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566454#M197408</link>
      <description>&lt;P&gt;Hi javiergn,&lt;/P&gt;&lt;P&gt;thanks for your help, there are some very useful parts in it. I had to adjust my question during the last few days so much that I created a new&amp;nbsp; post here :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/Add-a-count-from-a-different-time-period/m-p/566452/thread-id/197406" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/Add-a-count-from-a-different-time-period/m-p/566452/thread-id/197406&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that's the current "end goal" after I've talked with everyone again and figured out what the key points actually are.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Sep 2021 12:57:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-a-value-in-previous-time-period-and-add-to-current-count/m-p/566454#M197408</guid>
      <dc:creator>avoelk</dc:creator>
      <dc:date>2021-09-09T12:57:18Z</dc:date>
    </item>
  </channel>
</rss>

