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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

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 GA in US-AWS!

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