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
Revered Legend

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
Revered Legend

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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...