Splunk Search

eval values of a formula in a timechart command

mtrochym
Observer

Hi,
I am using the below query to timechart the values of offers (STATUS=ACCEPTED) from midnight, of the current day, and compare them to lastweek. I had found this query on these forums, plugged it in and it works beautifully!

index="offers" STATUS="ACCEPTED" earliest=-7d@d

| eval StartTime=relative_time(now(), "@d")

| eval Series=case(
_time >=StartTime, "today",
_time <= relative_time(now(), "-6d@d"), "LastWk")

| timechart span=5m count by Series

| eval Time = strftime(_time, "%H:%M")

| chart sum(LastWk) as LastWeek, sum(today) as Today by Time
| eval Today=if(Today==0, "", Today)

My problem is I am trying to insert the below "eval Percent..." so I can compare "Percent" today vs lastweek, in the above "Series".
count(STATUS) AS total, count(eval(STATUS="ACCEPTED")) AS Accepted
eval Percent=((Accepted/total)*100)

I tried timewrap, but while that is nice, it is a super slow process and only compares a 24h "moving window"

I tried doing things like:
| timechart span=5m count(STATUS) AS total, count(eval(STATUS="ACCEPTED")) AS Accepted by Series

|eval Percent=((Accepted/total)*100)

and a few other combinations but none seemed to work.
Any help would be appreciated!

Tags (1)
0 Karma

mtrochym
Observer

Hmm. I think I see where you're going with this but I tried this and unfortunately it did not work. The search took about 45min to run and didn't return any results.

0 Karma

somesoni2
Revered Legend

Give this a try

index="offers" STATUS="*" earliest=-7d@d 
| eval StartTime=relative_time(now(), "@d") 
| eval Series=case(
_time >=StartTime, "today",
_time <= relative_time(now(), "-6d@d"), "LastWk") 
| where isnotnull(Series)
| eval _time=if(Series="LastWk",_time+(86400*7),_time)
| bucket span=5m  _time
| chart count(STATUS) AS total, count(eval(STATUS="ACCEPTED")) AS Accepted by _time Series
| eval 'Percent: Today'=(('Accepted: Today'/'total: Today')*100)
| eval 'Percent: LastWk'=(('Accepted: LastWk'/'total: LastWk')*100)
| eval Time = strftime(_time, "%H:%M") | fields -_time
| table Time Percent* *
0 Karma

jamojamil
New Member

yesssss great

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

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

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...