<?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 search the count of unique users in a certain time range? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153098#M42944</link>
    <description>&lt;P&gt;it didn't work still! I tried that initially. No worries though, the answer that's accepted does it beautifully!&lt;/P&gt;</description>
    <pubDate>Mon, 03 Aug 2015 22:04:11 GMT</pubDate>
    <dc:creator>faramarz</dc:creator>
    <dc:date>2015-08-03T22:04:11Z</dc:date>
    <item>
      <title>How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153088#M42934</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;

&lt;P&gt;I am trying to run a search where it counts the number of new users who have made purchases in the previous day, and the number of old users who have purchased in the previous day. A sample log is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"2015-07-27 05:15:34" splunk_index_order=20150727052534, id=1182317, number="R539008334", item_total=1000.00, total=1084.25, state="complete", adjustment_total=14.25, user_id=845817, completed_at=1437974134993, bill_address_id=12502, ship_address_id=12501, payment_total=84.25, shipping_method_id=0, shipment_state="ready", payment_state="paid", email="insertemailhere@yahoo.com", special_instructions="NULL", created_at=1437973787491, updated_at=1437974145529, currency="USD", last_ip_address="NULL", created_by_id=1178357, oms_id="NULL", campaign_source="NULL", has_gift_box=## NOT SUPPORTED TYPE ##, abandoned_email_sent_at=NULL
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically, the issue is, the only way to check if a user is distinct is by their user_id tag. How can I find the unique user_id fields in the past day?&lt;/P&gt;

&lt;P&gt;Before anyone writes &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | dc(user_id) | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;that doesn't work, as it doesn't do a true distinct count because the user could have ordered two days previously or three years previously, and would still show up as a unique user as the time range isn't constricted.&lt;/P&gt;

&lt;P&gt;Is this search possible in Splunk?  I can't seem to figure it out. &lt;/P&gt;

&lt;P&gt;Thanks for any and all answers. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 06:52:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153088#M42934</guid>
      <dc:creator>faramarz</dc:creator>
      <dc:date>2020-09-29T06:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153089#M42935</link>
      <description>&lt;P&gt;This should give you what you need to start; let's say you run this for "Last 30 days":&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;latest=0d@d YourBaseSearchHere | stats values(user_id) AS user_id | eval type=Last30Days | append [search earliest=0@d latest = now YourBaseSearchHere | stats values(user_id) AS user_id | eval type=Yesterday]  | stats dc(type) AS numTypes values(*) AS * BY user_id | eval userType=if((numTypes==1), "New User", "Old User") | where type=Yesterday
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this search if a user is in the logs for the last 29 days, he is an "old user" but if he is only  today, he is a "new user".  This is probably not exactly what you need but you can modify the mechanics easily enough now that you have a starting point.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2015 17:45:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153089#M42935</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-03T17:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153090#M42936</link>
      <description>&lt;P&gt;Amazing. Perfect Answer. One issue. It throws an error at the "earliest" part. &lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2015 17:49:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153090#M42936</guid>
      <dc:creator>faramarz</dc:creator>
      <dc:date>2015-08-03T17:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153091#M42937</link>
      <description>&lt;P&gt;I see you already you have accept an answer but here is another way.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval rt=relative_time(now(),"-1d@d")| eval ts=_time| eval purchasedToday=if(rt=&amp;lt;ts, userID, null()) | purchasedYesterday=(rt&amp;gt;ts, userID, null()) | table userID, purchasedToday, purchasedYesterday | selfjoin userID | stats dc(userID) as TotalDC, dc(purchasedToday) as purchasedTodayDC, dc(purchasedYesterday) as purchasedYesterdayDC
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Aug 2015 18:15:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153091#M42937</guid>
      <dc:creator>bmacias84</dc:creator>
      <dc:date>2015-08-03T18:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153092#M42938</link>
      <description>&lt;P&gt;Doesn't work. purchasedYesterday isn't a command is the error thrown. What command did you want before purchasedYesterday? &lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2015 18:18:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153092#M42938</guid>
      <dc:creator>faramarz</dc:creator>
      <dc:date>2015-08-03T18:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153093#M42939</link>
      <description>&lt;P&gt;ACK!  I had a typo.  Try it now (edited and resaved).&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2015 18:26:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153093#M42939</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-03T18:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153094#M42940</link>
      <description>&lt;P&gt;Try something like this (probably the fastest)&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Update- Following search may give incorrect result as I forgot to add constraint to consider only yesterday's data for. Try the updated query&lt;/STRONG&gt;*&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your base search earliest=-30d@d latest=@d | eval PurchaseDate=strftime(_time,"%Y-%m-%d") | stats first(PurchaseDate) as First last(PurchaseDate) as LastPurchaseDate by user_id | where LastPurchasedDate=strftime(now()-86400,"%Y-%m-%d")| eval UserType=if(First=LastPurchaseDate ,"New User","Old User") | table user_id, UserType, LastPurchaseDate 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Aug 2015 18:27:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153094#M42940</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-03T18:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153095#M42941</link>
      <description>&lt;P&gt;Oh wow... that was amazingly simple. I should have thought of it that way. How are you so damn good at splunk...&lt;BR /&gt;
You've literally answered every single one of the questions I have asked lol.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2015 18:30:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153095#M42941</guid>
      <dc:creator>faramarz</dc:creator>
      <dc:date>2015-08-03T18:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153096#M42942</link>
      <description>&lt;P&gt;typo you need a eval. *&lt;EM&gt;eval purchasedYesterday=(rt&amp;gt;ts, userID, null()) *&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2015 20:03:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153096#M42942</guid>
      <dc:creator>bmacias84</dc:creator>
      <dc:date>2015-08-03T20:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153097#M42943</link>
      <description>&lt;P&gt;success! But if you look above at the accepted answer, he does it really nicely and simply instead of in a separate nested search. &lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2015 22:03:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153097#M42943</guid>
      <dc:creator>faramarz</dc:creator>
      <dc:date>2015-08-03T22:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153098#M42944</link>
      <description>&lt;P&gt;it didn't work still! I tried that initially. No worries though, the answer that's accepted does it beautifully!&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2015 22:04:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153098#M42944</guid>
      <dc:creator>faramarz</dc:creator>
      <dc:date>2015-08-03T22:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153099#M42945</link>
      <description>&lt;P&gt;Yes, sometimes I answer the question as asked and sometimes I go smarty-pants and answer the question that you &lt;EM&gt;should&lt;/EM&gt; have asked.  In this case, since I was already making several broad assumptions, I figured I would stick closer to what you asked.  I do thank you for the up-vote, though.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2015 22:05:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153099#M42945</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-03T22:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the count of unique users in a certain time range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153100#M42946</link>
      <description>&lt;P&gt;Also do note that you should be able to "Accept" more than one answer if more than one of them works.  This would be totally appropriate in this case.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2015 04:59:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-count-of-unique-users-in-a-certain-time-range/m-p/153100#M42946</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-10T04:59:41Z</dc:date>
    </item>
  </channel>
</rss>

