Splunk Search

Can't find the count of individual values in multi-value field?

dinesh16
Engager

Hello

| index=fruits

| transaction fruit_id

| rex max_match=0 “using rex to get the Type”
| eval TypeList=mvdedup(Type)
| eval Typecount=mvcount(TypeList)

| table fruit_id TypeList Typecount Type

 

Fruit_id

TypeList

Typecount

Type

1

Apple

Banana

Orange

3

Apple

Banana

Orange

Banana

Orange

Apple

Orange

Apple

 

Expected Output :

Fruit_id

TypeList

Typecount

Type

1

Apple

Banana

Orange

3

Apple - 3

Banana - 2

Orange - 3

 

I couldn't find the count of individual values in multi-value field. Can someone help me?. Thanks in advance.



Labels (1)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@dinesh16 

Can you please try this?

| index=fruits
| transaction fruit_id
| stats count by Type, Fruit_id 
| eval TypeOne = Type."-".count 
| stats values(TypeOne) as Type, values(Type) as TypeList , dc(Type) as Typecount by Fruit_id

| index=fruits
| transaction fruit_id
| stats count by Type, Fruit_id 
| eval TypeOne = Type."-".count 
| stats values(TypeOne) as Type, values(Type) as TypeList , dc(Type) as Typecount by Fruit_id
| table Fruit_id TypeList Typecount Type

 

My Sample Search :

| makeresults 
| eval Type="Apple|Banana|Orange|Banana|Orange|Apple|Orange|Apple",Type=split(Type,"|") , Fruit_id=1
| stats count by Type, Fruit_id 
| eval TypeOne = Type."-".count 
| stats values(TypeOne) as Type, values(Type) as TypeList , dc(Type) as Typecount by Fruit_id
| table Fruit_id TypeList Typecount Type

 

 

Screenshot 2023-02-02 at 11.39.42 PM.png

 

I hope this will help you.

Thanks
KV
If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.

View solution in original post

dinesh16
Engager

Thanks a lot @kamlesh_vaghela. It was very helpful and I successful evaluated the individual count of mv field.

In my real scenario, I have two multi-value fields (like - Type). So, we cannot expand (mvexpand) the second multi-value field right that would collapse the result. 

In this case, when we've two multi-value fields and we need to find the individual count of both multi-value fields. Do we have solution for this?.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@dinesh16 

Can you please share your sample data and expected OP for your current scenario?

Like 

Fruit_id

TypeList

Typecount

Type

???

 

and 

expected

??

KV

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@dinesh16 

Can you please try this?

| index=fruits
| transaction fruit_id
| stats count by Type, Fruit_id 
| eval TypeOne = Type."-".count 
| stats values(TypeOne) as Type, values(Type) as TypeList , dc(Type) as Typecount by Fruit_id

| index=fruits
| transaction fruit_id
| stats count by Type, Fruit_id 
| eval TypeOne = Type."-".count 
| stats values(TypeOne) as Type, values(Type) as TypeList , dc(Type) as Typecount by Fruit_id
| table Fruit_id TypeList Typecount Type

 

My Sample Search :

| makeresults 
| eval Type="Apple|Banana|Orange|Banana|Orange|Apple|Orange|Apple",Type=split(Type,"|") , Fruit_id=1
| stats count by Type, Fruit_id 
| eval TypeOne = Type."-".count 
| stats values(TypeOne) as Type, values(Type) as TypeList , dc(Type) as Typecount by Fruit_id
| table Fruit_id TypeList Typecount Type

 

 

Screenshot 2023-02-02 at 11.39.42 PM.png

 

I hope this will help you.

Thanks
KV
If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.

Get Updates on the Splunk Community!

Automatic Discovery Part 1: What is Automatic Discovery in Splunk Observability Cloud ...

If you’ve ever deployed a new database cluster, spun up a caching layer, or added a load balancer, you know it ...

Real-Time Fraud Detection: How Splunk Dashboards Protect Financial Institutions

Financial fraud isn't slowing down. If anything, it's getting more sophisticated. Account takeovers, credit ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...