Sub topic 9
Generating DAX measures with Copilot
This chapter assumes you can read basic DAX, know what a measure is, understand filter context, and have a star-schema model with a marked date table. Copilot drafts measures from a plain-language description. You still decide whether each measure is correct.
How Copilot writes a measure
You describe the calculation in the Copilot pane. In Power BI Desktop you can also use the quick measure suggestions or DAX query view. Copilot reads your table names, column names, existing measures, and any descriptions in the model. It then returns a DAX expression and a short explanation of what it does.
Copilot works from your model's metadata. If a column is called Amt2, it has to guess. Clear names and descriptions, covered in earlier chapters, directly improve the output.
Start with a base measure
Define simple base measures yourself first. Copilot can then build on them instead of repeating raw aggregations in every expression.
Total Sales = SUM ( Sales[SalesAmount] )Other measures, and Copilot's suggestions, can now reference [Total Sales]. This keeps logic in one place. If the definition of sales changes, you edit one measure.
Write a prompt that states the definition
A vague prompt such as "show me order value" forces Copilot to pick a definition. State the business rule and the edge case instead.
Write a measure that returns the average order value: total sales divided by the number of distinct orders. Handle the case where there are no orders.This prompt names the formula, names the denominator, and states what to do when there is no data. Copilot might return the following.
Average Order Value =
DIVIDE ( [Total Sales], DISTINCTCOUNT ( Sales[OrderID] ) )DIVIDE returns a blank instead of an error when the denominator is zero. That is how the expression satisfies the edge-case request.
Time intelligence
Time-based measures depend on your date table. Copilot can produce a year-over-year pair like this.
Sales LY =
CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
Sales YoY % =
DIVIDE ( [Total Sales] - [Sales LY], [Sales LY] )This works only if 'Date' is a proper date table: one row per day, no gaps, marked as the model's date table, and related to the fact table. If it is not, SAMEPERIODLASTYEAR can return blanks or wrong values, and Copilot will not warn you.
The workflow
Review what Copilot returns
Check each generated measure against this list before you keep it.
| Check | What to look for |
|---|---|
| Columns and tables | Does it use the columns you intended, not a similarly named one? |
| Aggregation | Is it `SUM`, `AVERAGE`, or `DISTINCTCOUNT` as the definition requires? |
| Filter context | Does `CALCULATE` add or remove filters you did not ask for? |
| Date table | Is the date column from the marked date table? |
| Blanks and zeros | Does it use `DIVIDE` or otherwise handle an empty denominator? |
| Naming | Does the name follow your model's conventions? |
Ask Copilot to explain a measure line by line if any part is unclear. If the explanation does not match your intent, the DAX probably does not either.
Iterate with follow-up prompts
When the first result is close, correct it in the same conversation. For example: "Exclude returned orders using the Sales[IsReturned] column" or "Rename the measure to AOV and add a description." Specific corrections work better than asking Copilot to try again.
Exercise
You ask Copilot for a measure and get Sales YoY % = DIVIDE ( [Total Sales] - [Sales LY], [Sales LY] ). The card shows blank for every year. Name two things to check first.
Show answer
Check that Sales LY is defined and returns values, and that the model has a date table marked as the date table, with a relationship to the fact table. If SAMEPERIODLASTYEAR has no valid date column to work from, Sales LY is blank, so the percentage is blank too.
Exercise
Rewrite this prompt so Copilot is less likely to guess: "Give me a measure for order value."
Show answer
For example: "Write a measure that returns the average order value: total sales divided by the number of distinct orders, using [Total Sales] and Sales[OrderID]. Return a blank when there are no orders." It states the formula, the inputs, and the empty case.