Splunk Dev

How to count the number of values in a multivalue field in or with a stats command

rberman
Path Finder

I have the following search query that I've been using so far to display the unique values in lists of Ids:

<search>
| eval ids=if(group_id >= 4, id, '')
| eval type_x_ids=if((group_id >= 4 AND is_type_x="true"), id, '')
| eval non_type_x_ids=if((group_id >= 4 AND is_type_x="false"), id, '')
| stats count as total_count, values(type_x_ids) as list_of_x_ids, values(non_type_x_ids) as list_of_non_x_ids, values(ids) as list_of_all_ids by some_characteristic

Now that I've seen which Ids are in the lists, I would like to change the query to count the number of unique ids in the lists split up by some characteristic. mvcount doesn't seem to work in the stats command the way I tried it:

attempt 1:
| stats count as total_count, mvcount(type_x_ids) as num_of_x_ids, mvcount(non_type_x_ids) as num_of_non_x_ids, mvcount(ids) as num_of_all_ids by some_characteristic

attempt 2:
| stats count as total_count, mvcount(values(type_x_ids)) as num_of_x_ids, mvcount(values(non_type_x_ids)) as num_of_non_x_ids, mvcount(values(ids)) as num_of_all_ids by some_characteristic

How should I write the stats line so I would get a table that shows the number of unique of Ids in each list of Ids split by some characteristic? I would like the following fields in my resulting table:

|  some_characteristic  |  total_count  |  num_of_x_ids  |  num_of_non_x_ids  |  num_of_all_ids  | 

I would appreciate any help you can give!!

0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| stats count as total_count, values(type_x_ids) as list_of_x_ids, dc(type_x_ids) as count_of_x_ids, values(non_type_x_ids) as list_of_non_x_ids, dc(non_type_x_ids) as count_of_non_x_ids, values(ids) as list_of_all_ids, dc(ids) as count_of_all_ids by some_characteristic

View solution in original post

rberman
Path Finder

dc was exactly what I was looking for! Thank you so much!

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| stats count as total_count, values(type_x_ids) as list_of_x_ids, dc(type_x_ids) as count_of_x_ids, values(non_type_x_ids) as list_of_non_x_ids, dc(non_type_x_ids) as count_of_non_x_ids, values(ids) as list_of_all_ids, dc(ids) as count_of_all_ids by some_characteristic
Get Updates on the Splunk Community!

Splunk Observability Cloud | Unified Identity - Now Available for Existing Splunk ...

Raise your hand if you’ve already forgotten your username or password when logging into an account. (We can’t ...

Index This | How many sides does a circle have?

February 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

Registration for Splunk University is Now Open!

Are you ready for an adventure in learning?   Brace yourselves because Splunk University is back, and it's ...