DAX query authoring, testing, and optimization for Power BI and Microsoft Fabric semantic models. Use when writing DAX measures, debugging calculations, querying semantic models, or optimizing DAX performance.
npx claudepluginhub francoisbgdw/claude-skillsThis skill is limited to using the following tools:
Write, test, and optimize DAX queries for Power BI and Microsoft Fabric semantic models.
Authors Power BI semantic models: creates/edits DAX measures/tables/relationships, analyzes best practices, deploys to Fabric, manages PBIP/TMDL, troubleshoots performance.
Guides Power BI semantic model design: star schemas, DAX measures/columns, relationships, RLS, naming/documentation, performance optimization. Analyzes active model via MCP tools.
Provides DAX reference for Power BI measures, columns, tables: evaluation contexts, CALCULATE, time intelligence, iterators, table functions, optimization, patterns.
Share bugs, ideas, or general feedback.
Write, test, and optimize DAX queries for Power BI and Microsoft Fabric semantic models.
pip install semantic-link semantic-link-labs
import sempy.fabric as fabric
# Run a DAX query against a semantic model
result = fabric.evaluate_dax(
dataset="<semantic-model-name>",
dax_string="""
EVALUATE
SUMMARIZECOLUMNS(
'Date'[Year],
'Date'[Month],
"Total Sales", [Total Sales],
"Order Count", [Order Count]
)
""",
workspace="<workspace-name>"
)
print(result)
Note: evaluate_dax() does not auto-refresh the semantic model. Refresh first if needed:
fabric.refresh_dataset(dataset="<name>", workspace="<workspace>")
az rest --method POST \
--url "https://api.powerbi.com/v1.0/myorg/groups/<workspace-id>/datasets/<dataset-id>/executeQueries" \
--body '{"queries": [{"query": "EVALUATE ROW(\"Test\", 1)"}]}'
Total Profit =
VAR _Revenue = [Total Revenue]
VAR _Cost = [Total Cost]
RETURN
_Revenue - _Cost
-- Apply a filter context modification
Online Sales =
CALCULATE(
[Total Sales],
'Channel'[Channel] = "Online"
)
-- Remove filters
All Product Sales =
CALCULATE(
[Total Sales],
REMOVEFILTERS('Product')
)
-- GOOD: Aggregator (single scan)
Total Sales = SUM('Sales'[Amount])
-- USE WHEN NEEDED: Iterator (row-by-row, then aggregate)
Weighted Avg Price =
DIVIDE(
SUMX('Sales', 'Sales'[Quantity] * 'Sales'[UnitPrice]),
SUM('Sales'[Quantity])
)
For a comprehensive pattern library, see dax-patterns.md.
-- GOOD: Engine-optimized
EVALUATE
SUMMARIZECOLUMNS(
'Product'[Category],
"Total", [Total Sales]
)
-- AVOID: Less efficient
EVALUATE
ADDCOLUMNS(
SUMMARIZE('Sales', 'Product'[Category]),
"Total", [Total Sales]
)
-- BAD: Evaluates [Total Sales] twice
Margin % = DIVIDE([Total Sales] - [Total Cost], [Total Sales])
-- GOOD: Evaluate once with VAR
Margin % =
VAR _Sales = [Total Sales]
RETURN
DIVIDE(_Sales - [Total Cost], _Sales)
-- GOOD: Column filter
CALCULATE([Total Sales], 'Date'[Year] = 2024)
-- AVOID: Table filter (creates a full table scan)
CALCULATE([Total Sales], FILTER('Date', 'Date'[Year] = 2024))
-- Intersects with existing filter context instead of replacing
Category Sales =
CALCULATE(
[Total Sales],
KEEPFILTERS('Product'[Category] = "Electronics")
)
-- Quick test of a measure
EVALUATE ROW("Result", [My Measure])
-- Test with filter context
EVALUATE
CALCULATETABLE(
ROW("Result", [My Measure]),
'Date'[Year] = 2024
)
Debug Filters =
VAR _Filters = CONCATENATEX(
FILTERS('Product'[Category]),
'Product'[Category],
", "
)
RETURN "Filters: " & _Filters
EVALUATE INFO.TABLES()
EVALUATE INFO.COLUMNS()
EVALUATE INFO.MEASURES()
EVALUATE INFO.RELATIONSHIPS()