Splunk Search

Search and lookup table fields comparison

DomenicoFumarol
Explorer

Hello everyone,
I have the challenge to compare two date fields, one coming from a search and the other one is reported in a lookup table. Of these two dates I would like to get the most recent one.
Let's say that the search can give me the "last time a specific user came into our shop" and in the lookup table instead we report "last time the user bought something in our shop"
Assuming that the two dates always exist, I would like to get the most recent of the twos.

Appreciated your help.

Labels (3)
Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @DomenicoFumarola,
I haven't your logs, so I put some assumptions:

  • the field in search is last_time_1
  • the column in lookup is last_time_2
  • please, don't use (if possible) fields with spaces!
  • the time format is the same in both search and lookup and it's yyyy-mm-dd hh:mm:ss

So I can suppose something like this:

index=your_index
| lookup your_lookup.csv user OUTPUT last_time_2
| eval last_time_1=strptime(last_time_1,"%Y-%m-%d %H:%M:%S"), last_time_2=strptime(last_time_2,"%Y-%m-%d %H:%M:%S")
| stats latest(last_time_1) AS last_time_1 latest(last_time_2) AS last_time_2 BY user
| eval recent=if(last_time_1>last_time_2,last_time_1,last_time_2)
| table user recent

Ciao.
Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @DomenicoFumarola,
I haven't your logs, so I put some assumptions:

  • the field in search is last_time_1
  • the column in lookup is last_time_2
  • please, don't use (if possible) fields with spaces!
  • the time format is the same in both search and lookup and it's yyyy-mm-dd hh:mm:ss

So I can suppose something like this:

index=your_index
| lookup your_lookup.csv user OUTPUT last_time_2
| eval last_time_1=strptime(last_time_1,"%Y-%m-%d %H:%M:%S"), last_time_2=strptime(last_time_2,"%Y-%m-%d %H:%M:%S")
| stats latest(last_time_1) AS last_time_1 latest(last_time_2) AS last_time_2 BY user
| eval recent=if(last_time_1>last_time_2,last_time_1,last_time_2)
| table user recent

Ciao.
Giuseppe

0 Karma

DomenicoFumarol
Explorer

worked like a charm!

Grazie

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

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

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...