Splunk Search

How can I concatenate tables from the same search at different time periods ?

Clovisa
Path Finder

Hi, I am trying to compare the top sales of the latest week to the top sales of the previous week.
I am trying to get a table that looks like :

Product   | Rank    | Rank previous week
Table     | 1       | 2
Chair     | 2       | 1

index=sales earliest=-2w latest=-w
| stats count as Sales by Product| sort -Sales
| table Product
| streamstats count as Rank

I succeeded in having the latest rank or the previous rank (see query above) but I don't see how I can combine them. Do you know how I could do this ? Thanks !

Tags (1)
0 Karma
1 Solution

renjith_nair
Legend

Hi @Clovisa,

Try

index=sales earliest=-2w latest=@w|bucket span=1w _time
 |stats count as Sales by Product,_time|sort _time,-count
 |streamstats count as rank by _time
 |sort Product
 |streamstats current=f last(rank) as prev_rank by Product reset_on_change=true|where prev_rank!=""
 |table Product,rank,prev_rank|sort rank
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

renjith_nair
Legend

Hi @Clovisa,

Try

index=sales earliest=-2w latest=@w|bucket span=1w _time
 |stats count as Sales by Product,_time|sort _time,-count
 |streamstats count as rank by _time
 |sort Product
 |streamstats current=f last(rank) as prev_rank by Product reset_on_change=true|where prev_rank!=""
 |table Product,rank,prev_rank|sort rank
---
What goes around comes around. If it helps, hit it with Karma 🙂

Clovisa
Path Finder

It is perfect, thanks a lot 😄

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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