Splunk Search

Why is eval failing after join?

rakeshkiit
Engager
index=na160 starttime="02/02/2023:00:00:00" endtime="02/02/2023:24:00:00" requestId="TID:131610985000004c2d"
|stats count as 240_COUNT by logRecordType
| join logRecordType type=outer
[search index=na160 starttime="02/08/2023:00:00:00" endtime="02/08/2023:24:00:00" requestId="TID:348627200000212ea7"
| stats count as 242_COUNT by logRecordType]
| eval difference = (242_COUNT - 240_COUNT)
| table logRecordType, 240_COUNT, 242_COUNT, difference

Above eval fails after joining two dataset 
Error in 'eval' command: The expression is malformed. 

Appreciate your help here to mitigate this issue. 

Labels (2)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

On the right hand side of an eval statement if the field name starts with numbers or contains '.' or other non standard characters, you must wrap the field name in single quotes

| eval difference = ('242_COUNT' - '240_COUNT')

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Note that using join is not good practice, as it's rarely necessary in Splunk and has limitations, which can give unpredictable results.

You can achieve the same thing using stats

index=na160 (starttime="02/02/2023:00:00:00" endtime="02/02/2023:24:00:00" requestId="TID:131610985000004c2d") OR
            (starttime="02/08/2023:00:00:00" endtime="02/08/2023:24:00:00" requestId="TID:348627200000212ea7")

| stats count(eval(requestId="TID:131610985000004c2d")) as 240_COUNT count(eval(requestId="TID:348627200000212ea7")) as 242_COUNT by logRecordType 
| eval difference = (242_COUNT - 240_COUNT)
| table logRecordType, 240_COUNT, 242_COUNT, difference
0 Karma

rakeshkiit
Engager

Given example is simplified version of query,  however in actual requestId is coming from another dataset

0 Karma

bowesmana
SplunkTrust
SplunkTrust

All good - just it's useful to not start your Splunk life with join - it's really worth getting your head around how to use stats+eval to join data sets. You will not regret it 😁 join can often lead you down a miserable path wondering why things don't do what you expect.

0 Karma

bowesmana
SplunkTrust
SplunkTrust

On the right hand side of an eval statement if the field name starts with numbers or contains '.' or other non standard characters, you must wrap the field name in single quotes

| eval difference = ('242_COUNT' - '240_COUNT')
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!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...