Splunk Search

Calculating a total for use later to calculate a percentage

lehrfeld
Path Finder

I am trying to calculate an overall total value for use later in my pipeline in a percentage calculation. My data looks like this

Bucket  userID  ...
1        mike
1        joe
1        sally
2        mike
2        tim
2        sally
3        mike

Report would look like this

userID #_of_buckets_in percentage
mike      3              100
joe       1              33.3
sally     2              66.6

My base search looks like this

| stats count by userID

This gives be userID and the #_of_buckets_in. When I try to add | dc(bucket) as totalBuckets to the search it only tallies up the buckets that the user is in and not the Total number of buckets.

All the data is in the same sourcetype. Thanks for any suggestions!

Mike

Tags (3)
0 Karma
1 Solution

somesoni2
Revered Legend

Try this

your base search | eventstats dc(bucket) as UniqBuckets | stats count as #_of_buckets_in by UserID, UniqBuckets | eval percentage=round((#_of_buckets_in*100)/UniqBuckets,1) | fields - UniqueBuckets

View solution in original post

somesoni2
Revered Legend

Try this

your base search | eventstats dc(bucket) as UniqBuckets | stats count as #_of_buckets_in by UserID, UniqBuckets | eval percentage=round((#_of_buckets_in*100)/UniqBuckets,1) | fields - UniqueBuckets
Get Updates on the Splunk Community!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

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 ...