From semantic-models
Author, validate, and test Power Query M expressions for semantic model import partitions. Covers query folding, step transformations, and execution against data sources.
npx claudepluginhub data-goblin/power-bi-agentic-development --plugin semantic-modelsThis skill uses the workspace's default tool permissions.
Author, validate, and test Power Query M expressions in semantic model import partitions. Covers writing correct M code, preserving query folding, validating expressions, and testing them by executing against real data sources.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Guides MCP server integration in Claude Code plugins via .mcp.json or plugin.json configs for stdio, SSE, HTTP types, enabling external services as tools.
Author, validate, and test Power Query M expressions in semantic model import partitions. Covers writing correct M code, preserving query folding, validating expressions, and testing them by executing against real data sources.
Each import table in a semantic model has a partition with an M expression defining what data gets loaded during refresh. The expression typically connects to a data source, navigates to a table/view, and applies transformations.
let
Source = Sql.Database(#"SqlEndpoint", #"Database"),
Data = Source{[Schema="dbo", Item="Orders"]}[Data],
#"Removed Columns" = Table.RemoveColumns(Data, {"InternalId"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns", {{"Amount", Currency.Type}})
in
#"Changed Type"
Key elements:
#"SqlEndpoint", #"Database" are shared M parameters defined at the model levelSource{[Schema="dbo", Item="Orders"]}[Data] navigates to a specific tablelet...in chain#"Step Name" syntax# Get partition expression from TMDL via fab
fab get "<Workspace>.Workspace/<Model>.SemanticModel" -f \
-q "definition.parts[?path=='definition/tables/<Table>.tmdl'].payload"
# Get shared M parameters
fab get "<Workspace>.Workspace/<Model>.SemanticModel" -f \
-q "definition.parts[?path=='definition/expressions.tmdl'].payload"
Query folding is the most important performance concept. The M engine translates compatible steps into native data source queries (e.g., SQL). When folding breaks, subsequent steps run in the mashup engine, pulling all data into memory first.
Steps that typically fold (for SQL sources):
Table.SelectColumns / Table.RemoveColumns -> SELECTTable.SelectRows -> WHERETable.Sort -> ORDER BYTable.FirstN -> TOPTable.Group -> GROUP BYTable.RenameColumns -> AS aliasesSteps that may or may not fold (source-dependent):
Table.TransformColumnTypes -- frequently breaks folding for text-to-numeric/date conversions on SQL Server sources. Use Table.TransformColumns with explicit conversion functions (e.g., Number.From) as a more reliable foldable alternative.Steps that break folding:
Table.AddColumn with custom M functions (not translatable to SQL)Table.Buffer (forces materialization; prefer Table.StopFolding to stop folding without the memory overhead)Table.LastN (no SQL equivalent without subquery)Table.Combine across different data sources (cross-database folding within the same SQL Server is possible via EnableCrossDatabaseFolding)each expressions with M-specific logicBest practice: Apply folding-compatible steps (filter, select, type) early; add custom columns and M-only transforms after all foldable work is done.
Remove unused columns and filter rows as early as possible:
let
Source = Sql.Database(SqlEndpoint, Database),
Data = Source{[Schema="dbo", Item="Orders"]}[Data],
// Filter and select BEFORE any custom transforms
#"Filtered" = Table.SelectRows(Data, each [Status] <> "Cancelled"),
#"Selected" = Table.SelectColumns(#"Filtered", {"OrderId", "Date", "Amount", "CustomerId"})
in
#"Selected"
These steps fold to SQL: SELECT OrderId, Date, Amount, CustomerId FROM dbo.Orders WHERE Status <> 'Cancelled'
Table.TransformColumnTypes early (folds to CAST in SQL)Int64.Type, type text, type date, Currency.Type, type logical#"Removed Duplicates", #"Filtered Active"#"Custom1" or #"Step1"#"Name" for steps with spaces (Power Query convention)Two approaches to validate that an M expression is syntactically correct and produces expected results:
Test the expression by running it against real data. This validates syntax, data source connectivity, and transformation correctness in one step.
The executing-power-query skill in the etl plugin provides the full workflow. In summary:
POST /v1/workspaces/{wsId}/dataflows/{dfId}/executeQueryMASHUP='section Section1;
shared SqlEndpoint = "myserver.database.windows.net";
shared Database = "MyDB";
shared Result = let
Source = Sql.Database(SqlEndpoint, Database),
Data = Table.FirstN(Source{[Schema="dbo",Item="Orders"]}[Data], 10)
in Data;'
curl -s -o result.bin -X POST ".../executeQuery" \
-H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" \
-d "$(jq -n --arg m "$MASHUP" '{queryName:"Result",customMashupDocument:$m}')"
See references/validation.md for step-by-step instructions and error handling.
Write the expression back to the model; Analysis Services validates the M syntax on save. This doesn't execute the query but catches structural errors:
let/inTransformColumnTypes# Edit the TMDL partition source directly and deploy via fab import,
# or use the XMLA endpoint with Tabular Editor or SSMS to modify
# the partition expression on the deployed model.
AS returns an error if the expression is malformed. This is faster than a full execute but doesn't catch runtime errors (wrong column names, data source issues).
| Need | Use |
|---|---|
| Full data validation (correct columns, types, values) | Execute via API |
| Quick syntax check | Save to model via XMLA/TOM |
| Step-by-step debugging | Execute with truncated in clause |
| Performance testing (check folding) | Execute with full data, observe timing |
See the data at any point in the transformation chain by truncating the let...in:
-- See raw source data (all columns)
in Data;
-- See after column removal
in #"Removed Columns";
-- See final result
in #"Changed Type";
Add Table.FirstN(stepName, 100) before the in to limit rows for large tables. See references/validation.md for the complete procedure.
Incremental refresh partitions use RangeStart and RangeEnd parameters:
let
Source = Sql.Database(#"SqlEndpoint", #"Database"),
Data = Source{[Schema="dbo", Item="Orders"]}[Data],
#"Filtered" = Table.SelectRows(Data, each
[OrderDate] >= #"RangeStart" and [OrderDate] < #"RangeEnd")
in
#"Filtered"
When testing, inline concrete date values for RangeStart and RangeEnd.
let
Source = Lakehouse.Contents(null),
Data = Source{[Id="lakehouse-guid"]}[Data],
Table = Data{[Id="table-name", ItemKind="Table"]}[Data]
in
Table
For complex SQL that can't be expressed in M:
let
Source = Sql.Database("server", "db"),
Data = Value.NativeQuery(Source, "SELECT * FROM dbo.MyView WHERE Year = 2024", null, [EnableFolding=true])
in
Data
Value.NativeQuery with EnableFolding=true allows subsequent M steps to fold on top of the native query.
references/validation.md -- Detailed validation workflow with executeQuery API, step preview, error handlingreferences/best-practices.md -- Query folding guidance, fold-breaker list, anti-patterns, performance tipsreferences/pqtest.md -- PQTest local M execution (Windows only), folding validation, mashup engine internalsexamples/execute_m.py -- Python script to execute M expressions via the Fabric API (CLI tool)examples/preview_partition.py -- Python script to preview partition data at any step (uses fab get + execute_m.py)