Splunk Search

Does distinct_count() in a timechart count unique instances per time slice or per chart?

nosignal
Explorer

Hi,

I was reading Example 3 in this tutorial - to do with distinct_count().

I would like to know when you apply distinct_count() to a timechart, if it is counting something as distinct for a single time slice (i.e. counting it again in the next time slice) or if it is counting something as distinct across the entire chart.

So, applied to Example 3, I think it would be

sourcetype=access_* action=purchase category_id=flowers | timechart dc(clientip)

Which I would expect to generate a timechart with the count of distinct/unique clientip over time. I.e. count a user when they first purchased flowers, and never count them again.

Is this what is happening, or does it count the user once in the first month, and then count them once again in the second month (assuming time slices are in months)?

The reason I am asking is that I want a time chart of the number of new users over time, so I do not want to count the same user ever again.

Many thanks.

jlelli
Path Finder

Since this thread seems to be still active and unsolved i'll post my solution: expanding the logic proposed by @gkanapathy you can count the _time of the first occurrence of a new IP address:

| stats earliest(_time) as _time by clientip | timechart count(_time)

The only problem with this logic is that Ip addresses that have first appeared earlier than the time range considered will be counted in the first time span. It's a problem that's going to matter less the longer your time range and span are but, honestly, i don't know even if this can be solved and how.

0 Karma

varunbiswas
New Member

I think ... | timechart dc(clientIP) as clientIP is a better option.

0 Karma

splunkreal
Motivator

this works too 🙂

* If this helps, please upvote or accept solution 🙂 *
0 Karma

mschaaf
Path Finder

I downvoted this post because this shows unique per bucket, not per search period, which is what the requester was looking for.

0 Karma

kimikoyan
Explorer

this one works! thank you!!

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

No, it tells you the number of different people in each group-by clause (of which the time-slice is a part). If you want just the number of new users at any time, it's easier to just only count the first time you see a user:

... | stats earliest(clientip) as clientip | timechart count
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...