dax-authoring
Skill29 starsChanged 11 days agoMITView on GitHub
Write and test DAX queries against Power BI semantic models. Covers DAX syntax rules, query patterns, time intelligence, and an iterative test workflow using `npx fabric-app-semantic-model-tools run-dax-query --dax <file> --alias <name>`.
9 other projects use a version of this, 9 of them edited.
Adopted by
Most recently taken up by
- microsoft/DataHub-App-for-Microsoft-Copilot-Agents-Cowork-and-Autopilotsedited, first seen Nov 8, 2026
- microsoft/ValueLens-for-Microsoft-Copilotedited, first seen Oct 25, 2026
- microsoft/ConsumptionCentral-for-Microsoft-Copilotedited, first seen Oct 25, 2026
- microsoft/frontiertour27-LTG291-turn-your-data-into-production-apps-with-rayfinedited, first seen Oct 17, 2026
- microsoft/frontiertour27-BRK390-building-ai-applications-with-microsoft-databases-and-fabricedited, first seen Oct 17, 2026
- microsoft/rayfinedited, first seen Oct 13, 2026
Used with
Projects with it also use rayfin-functions.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
MicrosoftSkillrayfin-functions
Use when writing Rayfin user-defined functions (UDFs), invoking functions from frontend code, or using functions CLI commands. Triggers: rayfin functions, udf.func, UserDataFunctions, RayfinContext, FabricContext, AppFunctionsSchema, functions init, dev functions apply, client.functions, invoke, func start, function_app.ts, types.ts, rayfin/functions/, FunctionClient, FunctionsSchema, fabric-user-data-functions, functionsBaseUrl, VITE_RAYFIN_FUNCTIONS_URL, bootstrap.ts, rayfinClient.ts
Also in 3 projects that use this
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 9
- microsoft/rayfin★ 64677% same
- microsoft/ConsumptionCentral-for-Microsoft-Copilot★ 3377% same
- microsoft/ValueLens-for-Microsoft-Copilot★ 2377% same
- microsoft/AnalyticsHub-Dashboard★ 1077% same
- microsoft/DataHub-App-for-Microsoft-Copilot-Agents-Cowork-and-Autopilots★ 1077% same
- microsoft/aitour27-LTG291-turn-your-data-into-production-apps-with-rayfin★ 277% same
- microsoft/frontiertour27-LTG291-turn-your-data-into-production-apps-with-rayfin★ 277% same
- microsoft/aitour27-BRK390-building-ai-applications-with-microsoft-databases-and-fabric★ 177% same
- microsoft/frontiertour27-BRK390-building-ai-applications-with-microsoft-databases-and-fabric★ 177% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository7 other files it gives its agents.
- AGENTS.mdAGENTS.md
- app-designSkill
- query-designSkill
- schema-querySkill
- semantic-model-dataSkill
- visual-interactivitySkill
- visualsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. 4 are common, 9 are distinctive, and 5 are very specific to this project.
4
Common
Most of the 9 edited versions we read keep these.
9
Distinctive
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 41
Always test generated DAX before using it in app code.
- Very specific: line 43
Run DAX through run-dax-query, not npx rayfin connector invoke.
- Very specific: line 45
Use fully-qualified 'Table'[Column] for column references
- Very specific: line 46
Use simple [Measure] for measure references
- Common: line 47
Use DEFINE for VAR and local MEASURE declarations (single DEFINE block, no commas)
- Distinctive: line 48
Use existing model measures for requested business metrics.
- Distinctive: line 53
Do not implement the UI until the final DAX has executed successfully and its output passes the planned shape and semantic validation …
- Common: line 72
EVALUATE Statement: Not a function but a statement.
- Very specific: line 73
Use the fully-qualified name 'Table'[Column] for column references, and the simple name [Measure] for measure references.
- Common: line 76
Do not use SUMMARIZECOLUMNS when there is no aggregation and the groupby columns belong to more than one table.
- Common: line 77
When using SELECTCOLUMNS or CALCULATETABLE, include any columns needed downstream (ORDER BY, FILTER).
- Distinctive: line 134
Use the completed schema-query plan: exact shipped measures, grouping columns, filters, relationship path, expected columns, and row shape
- Distinctive: line 138
Treat an execution error as a query failure.
- Distinctive: line 145
If an error or semantic mismatch remains, inspect the output-binding map, helper or parameter filter context, relationships, and filters.
- Distinctive: line 149
Stop each distinct planned query after it returns a structurally and semantically consistent result.
- Distinctive: line 158
Before running a query, check whether a previous result already contains the answer.
- Distinctive: line 165
If every grouped row returns the same measure value, first investigate a disconnected grouping table or ineffective filter propagation.
- Distinctive: line 168
If every row ranks 1, verify that the rank expression evaluates over the intended comparison set and that filters did not collapse that set …
“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DAX Authoring
Table of Contents
| Task | Reference | Notes |
| Must/Prefer/Avoid | SKILL.md: Must/Prefer/Avoid | Guardrails for DAX query generation |
| Generating DAX Queries | SKILL.md: Generating DAX Queries | Core rules, inline examples, EVALUATE/DEFINE patterns |
| DAX Query Structure & Syntax | dax-query-patterns.md: Query Structure | DEFINE / EVALUATE / ORDER BY / START AT |
| DAX Query Key Components | dax-query-patterns.md: Key Components | DEFINE VAR, DEFINE MEASURE, table expressions |
| DAX Query Worked Examples | dax-query-patterns.md: Common Patterns | 11 annotated examples from simple aggregation to cross-table joins |
| DAX Query Anti-Patterns | dax-query-patterns.md: Anti-Patterns | What to avoid in DAX queries |
| CALCULATE & CALCULATETABLE | dax-core-reference.md: CALCULATE & CALCULATETABLE | Context transition, filter types, boolean restrictions, common patterns |
| SUMMARIZECOLUMNS | dax-core-reference.md: SUMMARIZECOLUMNS | Argument order, auto-blank elimination, filter args, vs SUMMARIZE |
| ALL & ALLEXCEPT | dax-core-reference.md: ALL & ALLEXCEPT | CALCULATE modifier vs table function; percentage patterns |
| TREATAS | dax-core-reference.md: TREATAS | Virtual relationships, multi-column filtering |
| DAX Syntax Rules | dax-core-reference.md: DAX Syntax Rules | EVALUATE, CALCULATE, naming, SQL keywords, DEFINE rules |
| Common Mistakes | dax-core-reference.md: Common Mistakes | Variable naming, quoting, escaping, scalar EVALUATE, multi-table SUMMARIZECOLUMNS |
| BLANK Semantics | dax-core-reference.md: BLANK Semantics | BLANK vs NULL, propagation, equality, ISBLANK, DIVIDE, non-empty semantics |
| Time Intelligence Patterns | SKILL.md: Time Intelligence | When to consult TI reference |
| Date Table Prerequisites | dax-time-intelligence.md: Prerequisites | Date table requirements, mark as date table |
| YTD / QTD / MTD | dax-time-intelligence.md: Period-to-Date | TOTALYTD, DATESYTD, DATESINPERIOD patterns |
| Year-over-Year / Period Comparisons | dax-time-intelligence.md: Period Comparisons | SAMEPERIODLASTYEAR, DATEADD, PARALLELPERIOD |
| Rolling Windows | dax-time-intelligence.md: Rolling Windows | DATESINPERIOD rolling 12-month patterns |
| Opening/Closing Balances | dax-time-intelligence.md: Balances | Semi-additive measures, LASTDATE, LASTNONBLANK |
| TI in DAX Queries (Critical Rules) | dax-time-intelligence.md: Critical Rules for TI in Queries | CALCULATETABLE + TREATAS pattern for query context |
| TI Common Mistakes | dax-time-intelligence.md: Common Mistakes | Missing date table, wrong granularity, fiscal calendar |
| Testing & Iteration | SKILL.md: Testing & Iteration | Execute → inspect → fix → re-test workflow |
Must / Prefer / Avoid
Must
- Always test generated DAX before using it in app code. Execute each planned
.daxfile once throughnpx fabric-app-semantic-model-tools run-dax-queryand compare its report with the schema-query plan - Run DAX through
run-dax-query, notnpx rayfin connector invoke;run-dax-queryruns Rayfin CLI calls one at a time. - Use fully-qualified
'Table'[Column]for column references - Use simple
[Measure]for measure references - Use DEFINE for VAR and local MEASURE declarations (single DEFINE block, no commas)
- Use existing model measures for requested business metrics. Raw aggregation is allowed only when
the schema workflow established that no suitable shipped measure exists. Never replace a shipped
measure with raw
SUM,COUNT,COUNTROWS,AVERAGE,DISTINCTCOUNT, or a local approximation - Generate DAX from the completed schema-query plan; do not rediscover or substitute model objects
- Do not implement the UI until the final DAX has executed successfully and its output passes the planned shape and semantic validation gates, with every warning resolved or explained by the request
Prefer
- SUMMARIZECOLUMNS as the primary grouping function for queries
- TREATAS for filter arguments in SUMMARIZECOLUMNS
- Variables (VAR) to improve readability and avoid repeated calculations
- Shipped measures from measure-heavy KPI tables
Avoid
- SQL keywords (SELECT, WHERE, HAVING, etc.) within DAX expressions
- EVALUATE with scalar functions directly (wrap in ROW or table function)
Generating DAX Queries
DAX Syntax Rules
- Measures are named objects in the semantic model. They specify how to aggregate data. Measures should be used first to answer user requests before a new DAX formula is used to aggregate data.
- EVALUATE Statement: Not a function but a statement. It must always precede a table expression. Avoid pairing EVALUATE with scalar functions like CONCATENATEX, SUMX, DISTINCTCOUNT, etc.
- Use the fully-qualified name
'Table'[Column]for column references, and the simple name[Measure]for measure references. - CALCULATE takes a scalar expression as its first argument. CALCULATETABLE takes a table expression as its first argument.
- SUMMARIZECOLUMNS requires a specific order: groupby columns, then filters, then aggregations/measures.
- Do not use SUMMARIZECOLUMNS when there is no aggregation and the groupby columns belong to more than one table; use VALUES, SUMMARIZE, or SELECTCOLUMNS instead.
- When using SELECTCOLUMNS or CALCULATETABLE, include any columns needed downstream (ORDER BY, FILTER).
- Filters propagate across relationships based on unidirectional or bidirectional settings.
- INTERSECT, UNION, EXCEPT require identical column counts in both inputs.
- For current date/time, use TODAY() or NOW().
Inline Examples
Simple filtered aggregation:
// Total sales for red products
EVALUATE
ROW("Total Sales Amount", CALCULATE([Total Amount], 'Product'[Color] == "Red"))Multi-filter grouping with SUMMARIZECOLUMNS:
DEFINE
VAR _Filter1 = TREATAS({"Consumer Electronics"}, 'Product'[Category])
VAR _Filter2 = FILTER(ALL('Calendar'[Year]), 'Calendar'[Year] >= 2022 && 'Calendar'[Year] <= 2023)
EVALUATE
SUMMARIZECOLUMNS(
'Calendar'[Year],
'Calendar'[Month],
_Filter1,
_Filter2,
"Total Quantity", SUM('Sales'[Order Quantity]),
"Discount", [Total Discount]
)TopN with filtering:
DEFINE
VAR _Filter = TREATAS({"Red", "Black"}, 'Product'[Color])
VAR _Core = SUMMARIZECOLUMNS('Product'[Name], _Filter, "Total Sales", [Total Amount])
EVALUATE
TOPN(10, _Core, [Total Sales], DESC)For full syntax reference, worked examples, and anti-patterns, see dax-query-patterns.md. For function details, see dax-core-reference.md.
Time Intelligence
Time intelligence functions enable period-based analysis (YTD, YoY, rolling windows, etc.). They require a properly configured Date table.
Consult dax-time-intelligence.md whenever the user's request involves:
- Period-to-date calculations (YTD, QTD, MTD)
- Period comparisons (Year-over-Year, Month-over-Month)
- Rolling windows (last 12 months, last 30 days)
- Opening/closing balances
- Custom date ranges
Testing & Iteration
- Use the completed schema-query plan: exact shipped measures, grouping columns, filters, relationship path, expected columns, and row shape
- Author one
EVALUATEfor each distinct query the plan requires, and execute each final query once withrun-dax-query(see Query Execution) - Treat an execution error as a query failure. A successful result is not by itself proof of correctness, and an empty one is not an error. Compare the reported columns, row count, sample, and warnings with the plan's exact output columns, row shape, filters, ordering, grain, and value expectations
- Reject all-blank output, unexplained all-zero grouped output, distinct requested outputs that repeat the same measure/value, and all-rank-1 output when comparison or ordering is expected. These are semantic mismatches even when the command succeeds; do not build the UI from them
- If an error or semantic mismatch remains, inspect the output-binding map, helper or parameter filter context, relationships, and filters; consult dax-core-reference.md, make one evidence-based correction to only the failing query, and re-test it
- Stop each distinct planned query after it returns a structurally and semantically consistent result. Across the task, run one optional grain diagnostic for a shared ambiguity; for each distinct query, run one validation and at most one evidence-based corrective retry. Do not use this allowance for exploratory model probing or repeated discovery
Preserve the selected candidate by editing the validated query rather than regenerating it.
Result reuse and stopping
- Before running a query, check whether a previous result already contains the answer. Never rerun an identical or equivalent DAX query.
- A zero scalar is valid. An all-zero grouped result is not validated for a task that expects meaningful comparison unless task or catalog evidence shows that all zeros are legitimate.
- For a blank or empty result, inspect the shipped measure, relationship path, grouping dimension, helper-table filter context, and filters. Make one correction; accept a corrected blank only when the requested semantics allow no data.
- If every grouped row returns the same measure value, first investigate a disconnected grouping table or ineffective filter propagation. Do not rewrite or replace the measure to manufacture variation.
- If every row ranks 1, verify that the rank expression evaluates over the intended comparison set and that filters did not collapse that set before accepting the result.
- On timeout, narrow filters, reduce grouping cardinality, apply
TOPN, or simplify only the failing planned query. Never retry the same query unchanged. - Preserve successful batched outputs. Correct only failed or semantically inconsistent files.
Query Execution
Use:
npx fabric-app-semantic-model-tools run-dax-query \
--dax src/queries/revenue.dax \
--alias <alias>Each .dax file must contain one EVALUATE; otherwise nothing executes. For two to four planned
queries, repeat --dax in one call:
npx fabric-app-semantic-model-tools run-dax-query --dax src/queries/a.dax --dax src/queries/b.dax --alias <alias>The queries run one at a time, through the same connector operation as the running app. For each
query the command prints its status, output column names, row count, first rows
(--sample <n>, default 5), and warnings, not the full result. Warnings flag no rows, an all-blank
column, or a measure output (not a Table[Column] grouping column) that is all zero, constant, all
rank 1, or identical to another output; identical outputs are reported as one group. Warnings are
nonfatal prompts for review, not proof of correctness. A shortened preview is not complete shape
evidence.
A failed query keeps its own entry beside the successful ones, and the call exits 2: correct only
the failed queries. Missing, malformed, unreadable, or overflowed results never pass, and input or
read failures also exit nonzero; an error message alone does not show that a query ran. An
overflow result has no table; see
semantic-model-data.
Row count: a query returns every row unless you bound it. Bound it with the aggregation the plan
calls for, and use TOPN(...) only when the request asks for a ranked subset or to bound a query
that timed out. --limit <n> is a guard, not a cap: validation fails when more than n rows come
back.
Troubleshooting
| Problem | Solution |
| A connector query fails because no Power BI token can be acquired without a sign-in prompt | Follow the recovery text printed with the error; re-running npx rayfin login does not fix it. |
query-schema cannot resolve the connector, or a query names a connector that rayfin/rayfin.yml does not declare | Run npx rayfin connector list to check declared connectors, then npx rayfin connector add to register the intended model (see AGENTS.md) |
| DAX syntax errors | Consult dax-core-reference.md — check reserved keywords, quoting rules, EVALUATE/scalar mistakes |
| Unexpected query results | Check filter context, relationship direction, BLANK handling in dax-core-reference.md |
| Time intelligence returns wrong values | Check date table prerequisites and critical rules in dax-time-intelligence.md |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

