name: powerbi-dax description: Query Power BI / Microsoft Fabric semantic models with DAX to answer data questions, generate KPI summaries, or explore the model schema. Use this skill whenever the user asks about their Power BI data, semantic model, datasets, reports, measures, tables, or any phrase like "what were sales last quarter", "how many active users", "top customers", "show me the model", "what tables exist", or anything that implies pulling business data from Power BI / Fabric. Trigger this even if the user does not say "Power BI" explicitly — if the request is a business-data question and a Power BI dataset is configured, use this skill.
Power BI DAX Skill
This skill lets Claude query a Power BI / Fabric semantic model by executing DAX through the Power BI REST API, using device-code authentication cached on the local machine.
When to use this skill
Use it whenever the user asks a question that can only be answered by their business data sitting in Power BI. Examples:
- "What were our top 10 customers by revenue last quarter?"
- "Show me month-over-month sales growth this year."
- "What tables are in the model?"
- "What measures are available for the Sales fact table?"
- "Are there any relationships between Customer and Product?"
Do NOT use it for: general DAX-language questions ("explain CALCULATE"), Power BI UI questions ("how do I publish a report"), or anything that doesn't need to hit the user's specific dataset.
How the skill works at a glance
The skill has three modes. Pick the right one based on the question:
| Mode | When | Script |
|---|---|---|
| schema | User asks about the model structure, available tables, columns, or measures | scripts/introspect_schema.py |
| query | User asks a data question that needs a DAX query | scripts/query_dax.py |
| workspaces | User wants to discover what's available | scripts/list_workspaces.py |
All scripts handle authentication transparently via scripts/auth.py (device code flow with token caching to ~/.powerbi-dax/token_cache.bin).
First-time setup check
Before running any script, check if the user has a .env file at the repo root. If not, point them to README.md — they need to fill in PBI_TENANT_ID and PBI_CLIENT_ID before anything works. The workspace and dataset IDs are hard-coded as defaults but can be overridden via PBI_WORKSPACE_ID and PBI_DATASET_ID.
On first run, the auth script will print a code and URL — the user opens the URL in a browser, enters the code, and signs in. The token is then cached and reused for ~60-90 minutes; refresh tokens extend this further.
Step-by-step workflow
Step 1: Introspect the model (almost always do this first)
Unless you already have the schema cached from earlier in the conversation, run:
python scripts/introspect_schema.py
This dumps tables, columns, measures, and relationships as JSON. Read the output and build a mental model of what's available. The script also writes a copy to .cache/schema.json so you don't have to re-run it for follow-up questions.
If the user asks "what's in the model" — this script's output IS the answer. Summarize it cleanly for them.
Step 2: Translate the user's question into DAX
DAX query syntax for the REST API uses an EVALUATE statement. The most useful patterns:
Pattern A — straight table dump (filtered):
EVALUATE
FILTER(
'Sales',
'Sales'[OrderDate] >= DATE(2024, 1, 1)
)
Pattern B — aggregation with grouping (most common for business questions):
EVALUATE
SUMMARIZECOLUMNS(
'Customer'[CustomerName],
"Total Revenue", [Total Sales]
)
ORDER BY [Total Revenue] DESC
Pattern C — top N:
EVALUATE
TOPN(
10,
SUMMARIZECOLUMNS(
'Customer'[CustomerName],
"Total Revenue", [Total Sales]
),
[Total Revenue], DESC
)
Pattern D — time intelligence (YoY, MoM):
EVALUATE
SUMMARIZECOLUMNS(
'Date'[Year],
'Date'[Month],
"Sales", [Total Sales],
"Sales LY", CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date]))
)
DAX rules to remember:
- Table names go in single quotes when they contain spaces:
'Sales Orders' - Column references:
'Table'[Column] - Measure references:
[Measure Name](no table qualifier needed) - A query MUST start with
EVALUATEand return a table - Use existing measures when possible — they encode business logic you don't want to re-derive
Step 3: Execute the query
python scripts/query_dax.py --dax "EVALUATE ..."
Or, for multi-line queries, write to a file and pass --file path/to/query.dax. The script prints results as a clean table to stdout and also saves the raw JSON to .cache/last_result.json.
If the query fails:
- Syntax error — re-read the DAX, fix it, retry
- Column/measure not found — re-check
.cache/schema.json; the user may have used a friendly name that doesn't match the actual column - Auth error — delete
~/.powerbi-dax/token_cache.binand re-run; the user signs in again
Step 4: Interpret the result for the user
Don't just dump the table. Answer their actual question:
- Lead with the headline number / finding
- Show a small results table (markdown) if helpful
- Note any caveats (e.g., "this excludes returns because the model defines [Total Sales] that way")
- Suggest a natural follow-up if relevant
Worked example end-to-end
User asks: "Who were our top 5 customers last quarter?"
- Check
.cache/schema.json(or run introspect if missing). Confirm there's aCustomertable withCustomerNameand a measure like[Total Sales]or[Revenue]. - Determine "last quarter" relative to today — if today is May 2026, last quarter = Q1 2026 = Jan-Mar 2026.
- Construct DAX:
EVALUATE TOPN( 5, CALCULATETABLE( SUMMARIZECOLUMNS( 'Customer'[CustomerName], "Revenue", [Total Sales] ), 'Date'[Year] = 2026, 'Date'[Quarter] = 1 ), [Revenue], DESC ) - Run via
query_dax.py. - Reply with a short narrative + a markdown table of the 5 customers and their revenue.
Files in this skill
SKILL.md— this fileREADME.md— human-facing setup guide (Entra ID app reg, install, first-run)scripts/auth.py— device code flow + token cachingscripts/introspect_schema.py— dump tables/columns/measures/relationshipsscripts/query_dax.py— execute a DAX query and return resultsscripts/list_workspaces.py— discover available workspaces and datasetsrequirements.txt— Python dependencies (msal, requests, python-dotenv, tabulate).env.example— template; copy to.envand fill in.gitignore— keeps secrets and token cache out of git
Important guardrails
- Never print
PBI_CLIENT_ID, the token cache contents, or anything from.envin chat output. - Never commit
.envor~/.powerbi-dax/token_cache.binto git (the.gitignorehandles this, but double-check). - If a query would return more than ~10,000 rows, warn the user and suggest aggregating instead. The Power BI Execute Queries API caps results at 100,000 rows and 15MB anyway.
- If a measure doesn't exist, propose creating it as a DAX expression inline rather than inventing a fake measure name.