Splunk Search

How to group different values and count the number of transactions?

auaave
Communicator

Hi guys,

I have 2 data sources (source 1 and source 2) with different locations and transactions.
How can I group the locations to Inbound and Outbound and count the transactions?

Thank you.

Source 1
Location        Transaction
Location/dock/1     ok
Location/rec/1      ok
Location/pack/1     ok
Location/ship/1     ok


Source 2
Location        Transaction
Location/dock/1     not ok
Location/rec/1      not ok
Location/pack/1     not ok
Location/ship/1     not ok

Groupings
Inbound = Location/dock/1 , Location/rec/1  
Outbound = Location/pack/1, Location/ship/1

Result
Location       Ok   not ok
Inbound     2          2
Outbound        2          2
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi @auaave ,
Can you please try this?

YOUR_SEARCH | | eval Location=case(like(Location,"%dock%") OR like(Location,"%rec%"),"Inbound",like(Location,"%pack%") OR like(Location,"%ship%"),"Outbound") | chart count over Location by  Transaction

My Sample Search:

| makeresults | eval Location="Location/dock/1,Location/rec/1,Location/pack/1,Location/ship/1" | eval Location=split(Location,",")| mvexpand Location | eval Transaction="ok" | append [| makeresults | eval Location="Location/dock/1,Location/rec/1,Location/pack/1,Location/ship/1" | eval Location=split(Location,",")| mvexpand Location | eval Transaction="not ok"] | eval Location=case(like(Location,"%dock%") OR like(Location,"%rec%"),"Inbound",like(Location,"%pack%") OR like(Location,"%ship%"),"Outbound") | chart count over Location by  Transaction

Thanks

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi @auaave ,
Can you please try this?

YOUR_SEARCH | | eval Location=case(like(Location,"%dock%") OR like(Location,"%rec%"),"Inbound",like(Location,"%pack%") OR like(Location,"%ship%"),"Outbound") | chart count over Location by  Transaction

My Sample Search:

| makeresults | eval Location="Location/dock/1,Location/rec/1,Location/pack/1,Location/ship/1" | eval Location=split(Location,",")| mvexpand Location | eval Transaction="ok" | append [| makeresults | eval Location="Location/dock/1,Location/rec/1,Location/pack/1,Location/ship/1" | eval Location=split(Location,",")| mvexpand Location | eval Transaction="not ok"] | eval Location=case(like(Location,"%dock%") OR like(Location,"%rec%"),"Inbound",like(Location,"%pack%") OR like(Location,"%ship%"),"Outbound") | chart count over Location by  Transaction

Thanks

auaave
Communicator

@kamlesh_vaghela, thanks for your help! The groupings works well but I changed the last part to take into account the 2 types of sources.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...