Splunk Search

How to use values from inputlookup for date comparison?

Jochen_Widmaier
Engager

Hi,

I want to create a dashboard, where a user has a drop down input to select a named time frame ($value$). The start and end date of the time frame are defined in a lookup table. 

Each of my events has a milestone date. I want to filter to those events where the milestone date is between the start and end date from the lookup table.

I tried something like this:

index=my_index
| where milestone_date_epoch > [inputlookup mapping_lookup WHERE time_frame = $value$
    | eval startdate = strptime(Start_date, "%Y-%m-%d")
    | return startdate]
| where milestone_date_epoch < [inputlookup mapping_lookup WHERE time_frame = $value$
    | eval enddate = strptime(End_date, "%Y-%m-%d")
    | return enddate]

But I get an error message 😞 Can you help me to get this fixed?

0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
index=my_index
| where milestone_date_epoch > [inputlookup mapping_lookup WHERE time_frame = $value$
    | head 1
    | eval query = strptime(Start_date, "%Y-%m-%d")
    | table query
    | format]
| where milestone_date_epoch < [inputlookup mapping_lookup WHERE time_frame = $value$
    | head 1
    | eval query = strptime(End_date, "%Y-%m-%d")
    | table query
    | format]

View solution in original post

0 Karma

Jochen_Widmaier
Engager

The error message says:

Error in 'where' command: The operator at '="1630879200.000000"' is invalid.

I assume that the number is the epoch I have evaluated from the inputlookup. 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

index=my_index
| where milestone_date_epoch > [inputlookup mapping_lookup WHERE time_frame = $value$
    | eval query = strptime(Start_date, "%Y-%m-%d")
    | format]
| where milestone_date_epoch < [inputlookup mapping_lookup WHERE time_frame = $value$
    | eval query = strptime(End_date, "%Y-%m-%d")
    | format]
0 Karma

Jochen_Widmaier
Engager

I tried your proposal. From the Splunk documentation I would have guessed it needs to work now (thank you for pointing me there, I didn't now the format command earlier). But unfortunately I get a new error message:

Error in 'where' command: Type checking failed. 'AND' only takes boolean arguments.

But I don't have any AND in my query?!?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
index=my_index
| where milestone_date_epoch > [inputlookup mapping_lookup WHERE time_frame = $value$
    | head 1
    | eval query = strptime(Start_date, "%Y-%m-%d")
    | table query
    | format]
| where milestone_date_epoch < [inputlookup mapping_lookup WHERE time_frame = $value$
    | head 1
    | eval query = strptime(End_date, "%Y-%m-%d")
    | table query
    | format]
0 Karma

Jochen_Widmaier
Engager

Thank you very much @ITWhisperer . Now it is working fine 👍. You are a true legend.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

What error message are you getting?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...