Splunk Search

How to edit my search to remove duplicates from a table?

dsiob
Communicator

hi, I am using table which shows up duplicates, shown below. Here some track has multiple status (eg: Yellow and Red). In this case, row having 'Yellow' status for that track should appear.

Tags (3)
0 Karma
1 Solution

dineshraj9
Builder

Try setting a priority field and using the same to get desired results -

<your search>  | eval priority=case(Status=="GREEN", 1, Status=="Yellow", 2, Status=="Red", 3) | stats min(priority) as priority by Track_Name | eval Status=case(priority==1, "GREEN", priority==2,"Yellow", priority==3,"Red") | table Track_Name Status

View solution in original post

dineshraj9
Builder

Try setting a priority field and using the same to get desired results -

<your search>  | eval priority=case(Status=="GREEN", 1, Status=="Yellow", 2, Status=="Red", 3) | stats min(priority) as priority by Track_Name | eval Status=case(priority==1, "GREEN", priority==2,"Yellow", priority==3,"Red") | table Track_Name Status

kmorris_splunk
Splunk Employee
Splunk Employee

What is the reasoning behind showing the row with "Yellow". Is this the latest status?

If so, you could try:

[YOUR CURRENT SEARCH]
| sort -Status
| dedup Track_Name
0 Karma

dsiob
Communicator

Red and Yellow represents Priority level. I have to pick least priority that is Yellow.

0 Karma

aakwah
Builder

Hello,

Generally you can filter out results in your search query as per the following:

Status!=Red

Regards

dsiob
Communicator

Red and Yellow shows the priority level. So if there is multiple priority for one track, row with least priority (Yellow) should be selected.
If any track having only single status (Red or Yellow), it should show as it is.

0 Karma

aakwah
Builder

Thanks for the clarification.

Then you need to use transaction command to create one big event that contains all the statuses for single track.

Now Status filed became multivalue filed as it may contains Red and Yellow at the same time, then we count the values with Status_count=mvcount(Status).

Finally we use case statements to determine the count of status, if it equals 2, then Status will be Yellow if not it will have the original value.

The complete query:

Search query | transaction Track_Name | eval Status_count=mvcount(Status) | eval Status=case(Status_count == 2, "Yellow", Status_count ==1 , Status)  | table Track_Name, Status

Hope this helps.

Regards

0 Karma

dsiob
Communicator

thanks a lot for your working solution!!

0 Karma

aakwah
Builder

It is my pleasure !

0 Karma
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 ...