Splunk Search

How to count number of item that sastify condition by small group

nguyentu
New Member

For example, I have below data:

Shop1 Day1 sell 11
Shop1 Day2 sell 14
Shop1 Day3 sell 20
Shop2 Day1 sell 15
Shop2 Day2 sell 20
Shop2 Day3 sell 5
Shop2 Day4 sell 21
Shop3 Day1 sell 6
Shop3 Day2 sell 4

If one shop sell > 10 items in 2 consecutive day, that shop is mark as popular shop.
How can I count total of popular shop ?

0 Karma
1 Solution

DalJeanis
Legend

I would use streamstats

Let's assume that "day" is the Date portion of the _time, in a format that sorts normally (either in epoch time or "2017-02-01" format)

(your search here that produces  _time, shopname, sales)
| sort 0 shopname, _time
| streamstats window=2 global=t sum(sales) as sales2days by shopname
| where sales2days >= 10

That will get you a record for each day a shop was considered a popular shop. The following will get you information about each popular shop, including how many popular days they have had, and when the first and last were.

  | stats count as countpopulardays, min(_time) as firstpopularday, max(_time) as lastpopularday  by shopname

or, if you just want a list of shops that have ever qualified as popular, you can just

| dedup shopname

View solution in original post

0 Karma

DalJeanis
Legend

I would use streamstats

Let's assume that "day" is the Date portion of the _time, in a format that sorts normally (either in epoch time or "2017-02-01" format)

(your search here that produces  _time, shopname, sales)
| sort 0 shopname, _time
| streamstats window=2 global=t sum(sales) as sales2days by shopname
| where sales2days >= 10

That will get you a record for each day a shop was considered a popular shop. The following will get you information about each popular shop, including how many popular days they have had, and when the first and last were.

  | stats count as countpopulardays, min(_time) as firstpopularday, max(_time) as lastpopularday  by shopname

or, if you just want a list of shops that have ever qualified as popular, you can just

| dedup shopname
0 Karma

nguyentu
New Member

Thank you very much. I understood

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...