Splunk Search

How to divide events in a field by events in another field?

Ragate
Explorer

I want to divide events in one field by events in another field that would then display in a dashboard as a single value. I have two fields that are currently display in my dashboard. One is a list of different Revenue Numbers and the other is a list of Documents Processed. It Looks like this:

"Total Active Subscription Revenue _converted"   ----------------         " DocCount"
234542  -------------------------------------------------------------------------------           5  
341324  -------------------------------------------------------------------------------           3
34253   ---------------------------------------------------------------------------------        2
2314      -----------------------------------------------------------------------------------1

The query I have so far is this:

source="c:\\users\\ragate\\desktop\\splunk\\jsondump.txt" | eval "License Key Identifier"=substr('context.custom.dimensions{}.LicenseKey' ,4,7)  | join type=left "License Key Identifier" [search source="LMCustomerRevLicense1.csv"] | stats distinct_count("context.custom.dimensions{}.DocumentSessionId") by "Account Name" "Total Active Subscription Revenue _converted" | rename distinct_count("context.custom.dimensions{}.DocumentSessionId") AS DocCount |

I tried using |eval DocCost= "Total Active Subscription Revenue _converted"/DocCount | but this just brings me back and error saying "type checking failed. '/' only takes numbers"
Any Suggestions?

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try this

source="c:\\users\\ragate\\desktop\\splunk\\jsondump.txt" | eval "License Key Identifier"=substr('context.custom.dimensions{}.LicenseKey' ,4,7) | join type=left "License Key Identifier" [search source="LMCustomerRevLicense1.csv"] | stats distinct_count("context.custom.dimensions{}.DocumentSessionId") as DocCount by "Account Name" "Total Active Subscription Revenue _converted" 
| eval DocCost='Total Active Subscription Revenue _converted'/DocCount

Fields with special characters/spaces in their name should be used within single quotes in eval-expression (and where expression). With double quotes they're treated as literal string and give that typecast error.

View solution in original post

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try this

source="c:\\users\\ragate\\desktop\\splunk\\jsondump.txt" | eval "License Key Identifier"=substr('context.custom.dimensions{}.LicenseKey' ,4,7) | join type=left "License Key Identifier" [search source="LMCustomerRevLicense1.csv"] | stats distinct_count("context.custom.dimensions{}.DocumentSessionId") as DocCount by "Account Name" "Total Active Subscription Revenue _converted" 
| eval DocCost='Total Active Subscription Revenue _converted'/DocCount

Fields with special characters/spaces in their name should be used within single quotes in eval-expression (and where expression). With double quotes they're treated as literal string and give that typecast error.

0 Karma

Ragate
Explorer

Thank you!

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...