Splunk Search

How to calculate distinct count for present values and 7 days ago values for a given field?

POR160893
Builder

Hi,

My initial Splunk query was:
index="ABC" sourcetype="DEF"
| stats dc(fruit) AS "Fruits" by Diet
| sort -"Fruits"

However, I need to add a new field "Fruits 7 days ago" which finds the distinct count of "fruit" by "Diet". My current query is as follows:

index="ABC" sourcetype="DEF"
| stats dc(fruit) AS "Fruits" by Diet
|append [search earliest=-1w@w latest=@w
index="ABC" sourcetype="DEF"
| stats dc(fruit) AS "Fruits 7 days ago" by Diet ]
| sort -"Fruits", "Fruits 7 days ago"


Can you please help as I should be getting 3 outputted fields: "Diet", "Fruits", "Fruits 7 days ago" BUT I am still only getting  "Diet" and "Fruits".

Can you please help?


Many thanks!


Labels (4)
0 Karma
Get Updates on the Splunk Community!

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...

Splunk App Dev Community Updates – What’s New and What’s Next

Welcome to your go-to roundup of everything happening in the Splunk App Dev Community! Whether you're building ...

The Latest Cisco Integrations With Splunk Platform!

Join us for an exciting tech talk where we’ll explore the latest integrations in Cisco + Splunk! We’ve ...