Splunk Search
Highlighted

Percentage of value combinations in the dataset

Hello,

I am looking to figure out the percentage of times certain value combinations appear in the data.   The field I am looking to construct in the sample below is "combo."

Field1Field2combo
AY10
AZ20
BY20
BZ40
CZ10


In the sample the A value appears in 30% of all events, Y appears in 30% of all events, and the combination of AY appears in 10% of all events.  Pieces of the following code have worked by themselves but not together. 

... | stats count by Field1 Field2 as combo | eventstats sum(count) as total | eval perc=(combo/total)

Labels (2)
0 Karma
Highlighted

Re: Percentage of value combinations in the dataset

Motivator

You can simply use top command:

 

| top 10 field1,filed2 

 

10 gives - top 10 combinations with percentage from field1, field2

if you want to get % for all such combinations in your dataset use limit=0

 

| top limit=0 field1,filed2

0 Karma
Highlighted

Re: Percentage of value combinations in the dataset

That produces a result but it doesn't help me very much.  I need to perform this function on all the events in the dateset and use the percentage later in another function. 

Can you tell me how to find the percentage for all events and save the result?

0 Karma
Highlighted

Re: Percentage of value combinations in the dataset

Ultra Champion
| makeresults
| eval _raw="Field1	Field2	combo
A	Y	10
A	Z	20
B	Y	20
B	Z	40
C	Z	10"
| multikv forceheader=1
| table Field1	Field2	combo

| rename COMMENT as "this is logic"
| eval Field3=Field1.Field2
| untable combo name Fields
| eventstats sum(eval(if(name="Field3",combo,NULL))) as total
| stats sum(combo) as count max(total) as total by Fields
| eval perc=count/total * 100
0 Karma