Write a DAX measure
Inputs
definition(required): What the measure should calculate, in plain language, including edge cases (for example "active customers = customers with at least one order in the last 90 days as of the selected date; exclude internal accounts").data_model(required): The tables, key columns, relationships (direction and cardinality), whether a marked date table exists, and existing measures to reuse.
Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.
- 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.
- Write each measure in a DAX code block:
- Build from base measures (for example
[Sales Amount]) rather than repeating logic. - Use
VAR … RETURNfor readability,DIVIDEfor 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 explicitFILTERlogic 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.
- Build from base measures (for example
- 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.
- 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.
- 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.