Splunk Search

How do I get a distinct value count from two fields?

twh1
Communicator

I have two different fields (DB_INSTANCE_NAME & INSTANCE_NAME ) in two source types. These fields contain a similar value. I want distinct counts after combining both pieces of field data.

DB_INSTANCE_NAME= ansrp, flexp, sunopt, vlprod, buybprod, FDPOSPRD, aasprod, dcpscp, hydra, cidprod,  gcdprd, pspprod, HDMPRD
INSTANCE_NAME= obieep, cnavprd, gcdprd, pspprod, svdprod, tumss2, fepauth, rulesu, ecmsprod, HDMPRD, csprod, RFEP1, pcip, vlprod

I want the count of ansrp, flexp, sunopt, vlprod, buybprod, FDPOSPRD, aasprod, dcpscp, hydra, cidprod, gcdprd, pspprod, HDMPRD, obieep, cnavprd, svdprod, tumss2, fepauth, rulesu, ecmsprod, HDMPRD, csprod, RFEP1, pcip

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

What you do is combine them then count them.

index=foo (sourcetype=st1 OR sourcetype=st2) | eval combinedField=coalesce(DB_INSTANCE_NAME, INSTANCE_NAME) | stats dc(combinedField) as Count
---
If this reply helps you, Karma would be appreciated.

View solution in original post

nick405060
Motivator

Credit goes to @micahkemp:

| stats dc(eval(mvappend(field1, field2, field3)))

richgalloway
SplunkTrust
SplunkTrust

What you do is combine them then count them.

index=foo (sourcetype=st1 OR sourcetype=st2) | eval combinedField=coalesce(DB_INSTANCE_NAME, INSTANCE_NAME) | stats dc(combinedField) as Count
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...