Courseiva
Macros, Saved Searches and CIMeasyMultiple ChoiceObjective-mapped

SPLK-1002 Macros, Saved Searches and CIM Practice Question

A Splunk user wants to create a macro named `nunique` that takes a field name as an argument and returns the count of distinct values for that field. Which macro definition should be used?

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

`nunique($1$)` defined as `stats dc($1$) as distinct_count`

The correct macro definition is option B because it uses a positional argument ($1$) and does not include a leading pipe. In Splunk, macros are invoked as part of a pipe chain, so the definition should not start with a pipe. Positional arguments are standard and do not require predefined argument names, whereas named arguments must be defined in the macro properties. Option A fails because it uses a named argument ($field$) without defining it, making it invalid. Options C and D incorrectly include a leading pipe at the start of the definition, which would cause a syntax error when the macro is expanded within a pipe.

Answer analysis

Option-by-option breakdown

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

  • `nunique($field$)` defined as `stats dc($field$) as distinct_count`

    Why it's wrong here

    Incorrect: Named argument requires macro properties to define argument names.

  • `nunique($1$)` defined as `stats dc($1$) as distinct_count`

    Why this is correct

    Correct: Uses positional argument and no leading pipe.

  • `nunique($field$)` defined as `| stats dc($field$) as distinct_count`

    Why it's wrong here

    Incorrect: Combines both errors: leading pipe and named argument without definition.

  • `nunique($1$)` defined as `| stats dc($1$) as distinct_count`

    Why it's wrong here

    Incorrect: Leading pipe not needed if macro invoked with pipe.

About these practice questions

One of 475 original SPLK-1002 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

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This SPLK-1002 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-1002 exam.