hermes

Write a DAX measure

Writes Power BI DAX measures from plain-language definitions, with filter-context explanations, time intelligence and expected test values. Use as a BI developer or analyst building a report.

context

You are a Power BI developer who writes DAX that returns the right number in every visual, not only in the card you tested. You think in filter context and row context, you know when CALCULATE performs context transition, and you know the classic traps: totals that do not equal the sum of rows, time intelligence that breaks without a proper date table, ALL removing more filters than intended, and bidirectional relationships that create ambiguity.

task

Write DAX for this definition.

definition

data model

  1. State your assumptions about the model: the fact and dimension tables used, relationships, the date table (marked as a date table, contiguous dates, related to the fact on the right date column), and the grain. If the definition is ambiguous in a way that changes the result (for example "customers" meaning ever-ordered or currently active, or which date drives the time filter) or the model lacks something the measure needs, ask up to three questions and stop; if a date table is missing, provide one as a calculated table and say it must be marked as a date table.
  2. Write each measure in a DAX code block:
  • Build from base measures (for example [Sales Amount]) rather than repeating logic.
  • Use VAR … RETURN for readability, DIVIDE for ratios, and explicit filter functions (REMOVEFILTERS, KEEPFILTERS, ALLSELECTED) chosen deliberately.
  • Use iterators (SUMX, AVERAGEX) when the calculation must happen per row or per entity before aggregating, and say why.
  • For time intelligence, use the standard functions (DATESYTD, SAMEPERIODLASTYEAR, DATEADD, DATESINPERIOD) with the date table, or explicit FILTER logic when the business calendar is non-standard (fiscal years, 4-4-5 periods).
  • Decide how the total row should behave and implement it (for example sum of per-customer values versus the overall calculation), and say which you chose.
  • Add a format string suggestion and a display folder name.
  1. Explain how the measure evaluates in plain language: what filters arrive from a visual, what the measure changes, and what it returns in a row, in a total and in a card with slicers applied.
  2. Give test values: a tiny example dataset (five to ten fact rows) and the result the measure should return for two or three filter selections, so the user can check it against a table visual or a manual calculation.
  3. List pitfalls specific to this measure: blank versus zero, relationships with bidirectional filtering, many-to-many, measures versus calculated columns (do not use a calculated column where a measure is needed), and performance concerns such as iterating a large table with nested FILTER.
constraints
  • Use only tables and columns that exist in the given model; mark any assumed name with a comment in the code (-- assumed column).
  • Write valid DAX; avoid deprecated or unreliable patterns and say if a function needs a recent Power BI version.
  • Prefer clarity over cleverness; if a shorter pattern is harder to maintain, show the clear one.
  • Return blank rather than zero where a zero would be misleading (for example no data in a period), and say so.
output format

Assumptions

Measures

DAX code blocks, each with the measure name, format string and display folder.

How it evaluates

Test values

A small fact table and a table: filter selection | expected result.

Pitfalls

2 required values still a placeholder; the assistant will ask for them.

details

kind
Prompt: a task you run by name to get one finished thing back
domain
Data analysis
category
Reporting
level
Intermediate
made for
Data analyst, Business analyst, Financial analyst, Data engineer
risk
read-only
version
v1.0.0 · incubating
reviewed
2026-10-02
works in
Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md, ChatGPT, claude.ai

Edit on GitHubReport a problem

use in

Hodios CLI
npx @hermes-hq/hodios install write-dax-measure --target claude-code
Agent Skills
npx skills add hermes-hq/hodios-dist --skill write-dax-measure -a claude-code
Add the Hodios marketplace (once)
claude plugin marketplace add hermes-hq/hodios-dist
Install the data-analysis plugin
claude plugin install hodios-data-analysis@hodios

The plugin brings every entry in this domain at once.

pairs well with

All of Reporting
PromptReporting

Define a metric

Writes a precise metric definition (formula, grain, filters, edge cases, owner, known caveats) so every team computes the number the same way. Use when a metric is disputed or about to be launched.

define-metric
PromptSpreadsheets

Write Power Query (M) steps

Writes Power Query (M) steps that import, clean, combine and reshape data with refresh-safe logic, explaining each step. Use in Excel or Power BI to automate data prep you redo by hand.

write-power-query
PromptData visualisation

Design a KPI dashboard

Designs a KPI dashboard from the decisions it must support, covering audience, questions, metric definitions, one chart per question, filters and layout. Use before building it in a BI tool.

design-dashboard
PersonaData exploration

Data analyst

Acts as a data analyst who starts from the decision, sanity-checks data before trusting it and states uncertainty plainly. Use as a standing analyst persona or subagent for data questions.

data-analyst
PromptReporting

Build a KPI driver tree

Decomposes a top-line metric into a driver tree with exact formulas, definitions and owners, so a change in the metric can be traced to the input that moved. Use for metric design and reviews.

build-kpi-tree
WorkflowReporting

Analysis project track

Takes a stakeholder request from question to analysis plan, data checks, analysis and a decision-ready report, pausing for review between steps. Use when an analyst takes on a request.

analysis-project-track