Courseiva
Basic Searching and Transforming CommandshardMultiple ChoiceObjective-mapped

Using stats dc() for Distinct Count in Splunk

A large financial institution uses Splunk to consolidate logs from thousands of ATMs. Each ATM sends a heartbeat event every 5 minutes containing fields: atm_id, timestamp, status (OK or ERROR), and firmware_version. The operations team wants to find the number of ATMs that have reported at least one ERROR status in the last hour. The initial search is: index=atm sourcetype=heartbeat status=ERROR | dedup atm_id | stats count. However, this search returns a count that is too high because some ATMs report multiple errors within the hour. The team needs an accurate count of ATMs that had any error, regardless of how many error events each ATM generated. The search must be efficient due to the high volume of events. Which approach should be used?

Quick Answer

The original search, dedup atm_id followed by stats count, produces an inflated number because dedup removes duplicate events based on the field value as they stream through the pipeline, and it doesn't reliably collapse every ATM down to a single representative event before counting in the way the team expected, which is why the reported total was too high. The stats dc(atm_id) approach solves this more directly by using Splunk's distinct-count aggregation, which counts the number of unique atm_id values across the entire result set in a single pass, regardless of how many ERROR events any individual ATM generated. This gets to exactly what the operations team needs, one qualifying count per ATM, without requiring an intermediate deduplication step at all. It's also more efficient at scale, since dc() is a native statistical function, purpose built to compute the answer in one pass over the data rather than relying on stream-level deduplication logic followed by a separate count. Whenever a scenario describes wanting to count how many unique entities, such as devices or users, experienced a condition, regardless of how many times each one triggered it, and especially when efficiency over high event volume matters, stats dc(field) is the tool built precisely for that requirement, and it should be preferred over dedup-plus-count patterns.

⚠ Common exam trap

Test-takers frequently think `dedup atm_id` followed by `stats count` is necessary to get unique ATMs, but they overlook that `stats dc(atm_id)` achieves the same result more efficiently and is the standard Splunk command for distinct counts.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

index=atm sourcetype=heartbeat status=ERROR | stats dc(atm_id) as errored_atms

`stats dc(atm_id)` computes the distinct count of `atm_id` values, directly giving the number of unique ATMs that had at least one ERROR event in the last hour. This is efficient as it processes all matching events in a single pass without needing intermediate deduplication or subsearches, which is critical for high-volume ATM log data.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • index=atm sourcetype=heartbeat status=ERROR | stats count(atm_id) as error_events | eval error_events

    Why it's wrong here

    This gives total errors, not distinct ATMs.

  • index=atm sourcetype=heartbeat status=ERROR | stats dc(atm_id) as errored_atms

    Why this is correct

    Distinct count of atm_id gives the number of ATMs with any error.

  • index=atm sourcetype=heartbeat status=ERROR | stats count by atm_id | where count >=1 | dedup atm_id | stats count

    Why it's wrong here

    This is inefficient and the dedup after stats is unnecessary.

  • index=atm sourcetype=heartbeat status=ERROR | stats values(atm_id)

    Why it's wrong here

    values lists the ATMs but does not count them directly; also it's less direct.

About these practice questions

One of 502 original SPLK-1001 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on SPLK-1001

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A search includes the command '| stats dc(user) by host'. What does this command return?

hard
  • A.The number of unique hosts per user
  • B.The count of events per host
  • C.The sum of user values per host
  • D.The number of distinct users per host

Why D: The `dc(user)` function in the `stats` command calculates the distinct count of the `user` field values. When combined with `by host`, it returns the number of unique users for each host. This is why option D is correct.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This SPLK-1001 practice question is part of Courseiva's free Splunk certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SPLK-1001 exam.