Splunk Search

chart after using stats latest()

jared_anderson
Path Finder

I have the following command:

sourcetype="sourcetype" eventid=731 OR eventid=730
| stats latest(eventid) by target
| chart count by eventid

the 2nd line works as expected, but when I add in the 3rd line, i get "No results found"

I want to display the results of the 2nd line in a pie chart rather than a table.

1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi
add AS eventid to your stats command

sourcetype="sourcetype" eventid=731 OR eventid=730
| stats latest(eventid) AS eventId by target
| chart count by eventid

Bye.
Giuseppe

View solution in original post

niketn
Legend

@jared_anderson, following should also give you same result. Dedup will get latest events for each target which enables you to count latest eventid for unique targets.

sourcetype="sourcetype" eventid=731 OR eventid=730
| dedup target
| chart count by eventid
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi
add AS eventid to your stats command

sourcetype="sourcetype" eventid=731 OR eventid=730
| stats latest(eventid) AS eventId by target
| chart count by eventid

Bye.
Giuseppe

jared_anderson
Path Finder

why is the AS eventid needed?

0 Karma

gcusello
SplunkTrust
SplunkTrust

Because if you don't use it, the stats result field name is latest(eventId) as you can see in the column header running Your first two tows.
Bye.
Giuseppe

Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...