power-query-m-engineering
Skill2 starsChanged 5 months agoMITView on GitHub
Use when creating, debugging, or optimizing Power Query M in Excel or Power BI, including Excel.Workbook, Csv.Document, folders, joins, grouping, expansion, types, dependencies, refresh errors, or performance.
In this repository36 other files it gives its agents.
- AGENTS.mdAGENTS.md
- excel-ado-sql-data-accessSkill
- excel-bi-routerSkill
- excel-deliverable-publisherSkill
- excel-report-builderSkill
- excel-testing-fixturesSkill
- excel-vba-workbook-engineeringSkill
- excel-workbook-qa-auditorSkill
- mdx-cubevalue-extractionSkill
- office-environment-diagnosticsSkill
- power-bi-semantic-modelSkill
- power-pivot-dax-modelingSkill
- power-query-m-engineeringSkill
- excel-ado-sql-data-accessSkill
- excel-bi-routerSkill
- excel-deliverable-publisherSkill
- excel-report-builderSkill
- excel-testing-fixturesSkill
- excel-vba-workbook-engineeringSkill
- excel-workbook-qa-auditorSkill
- mdx-cubevalue-extractionSkill
- office-environment-diagnosticsSkill
- power-bi-semantic-modelSkill
- power-pivot-dax-modelingSkill
- power-query-m-engineeringSkill
- excel-ado-sql-data-accessSkill
- excel-bi-routerSkill
- excel-deliverable-publisherSkill
- excel-report-builderSkill
- excel-testing-fixturesSkill
- excel-vba-workbook-engineeringSkill
- excel-workbook-qa-auditorSkill
- mdx-cubevalue-extractionSkill
- office-environment-diagnosticsSkill
- power-bi-semantic-modelSkill
- power-pivot-dax-modelingSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Treat Power Query M as an ETL graph.
- Distinctive: line 17
Check row count risks before joins, expands, groups, and combines.
- Distinctive: line 19
Run the M source lint before importing changed query text into a workbook copy.
- Distinctive: line 21
If refresh fails, classify the refresh JSON or copied error text before rewriting M.
- Distinctive: line 77
No unexpected duplicated rows.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Power Query M Engineering
Core Rule
Treat Power Query M as an ETL graph. Inspect sources, query dependencies, row counts, types, and join cardinality before editing formulas.
Workflow
- Identify whether the query runs in Excel Power Query or Power BI.
- Extract or inspect the M code from workbook queries when possible.
- Map inputs, parameters, intermediate tables, and outputs.
- Check row count risks before joins, expands, groups, and combines.
- Edit M with clear step names and stable types.
- Run the M source lint before importing changed query text into a workbook copy.
- Validate refresh behavior, row counts, key columns, ordering, and final schema.
- If refresh fails, classify the refresh JSON or copied error text before rewriting M.
High-Risk Areas
Table.NestedJoinfollowed by expand can multiply rows when lookup keys are duplicated.Table.Groupcan change row order unless an order column is preserved.Table.PromoteHeaderscan corrupt files with extra title rows or inconsistent headers.Changed Typesteps can break when source columns are missing or localized.- Folder combine logic often fails on hidden
~$files or mixed.xls/.xlsx/.csv. - Dynamic columns require explicit missing-field handling.
Reference Selection
Read:
references/m-patterns.mdfor common M transformation patterns.references/m-style-guide.mdbefore writing or rewriting substantial M queries.references/m-lifecycle-vba.mdwhen using VBA/COM to add, edit, delete, refresh, wait for completion, or benchmark Power Query.references/m-troubleshooting.mdfor refresh and formula errors.references/m-validation.mdwhen validating row counts, schema, joins, and refresh behavior.references/official-docs-kb.mdandreferences/official-links.mdwhen exact function semantics, host behavior, or customer-facing citations are needed.
Scripts
scripts/export_power_queries_excel_com.ps1 -WorkbookPath <path> -OutDir <folder>exports workbook Power Query formulas through Windows Excel COM. Use this when exact M source is needed from an.xlsxor.xlsm.scripts/manage_power_queries_excel_com.ps1 -WorkbookPath <path> -Action List|Add|Update|Delete ...lists, inserts, updates, or deletes workbook queries through Excel COM. Add/update/delete require an output copy unless-InPlaceis explicitly supplied.scripts/refresh_power_queries_excel_com.ps1 -WorkbookPath <path> [-QueryName <name>] [-OutputWorkbookPath <path>]refreshes all queries or one query, waits for async completion, records timings, captures errors, and optionally saves a refreshed copy.scripts/build_power_query_refresh_report.py <refresh-json> [--max-elapsed-seconds <n>] [--require-completed] [--out-json <path>] [--out-md <path>]summarizes refresh completion, elapsed time, still-refreshing connections, background-refresh settings, and captured errors from refresh JSON. Use it after a refresh and before dependent VBA/report steps continue.scripts/classify_power_query_refresh_errors.py <refresh-json-or-error-text> [--out-json <path>] [--out-md <path>]classifies refresh errors into diagnostic buckets such as credentials, privacy firewall, missing source, missing columns, type conversion, syntax, provider/driver, timeout, and row-cardinality risks. Use it after refresh failures and before changing M code.scripts/create_power_query_fixture_excel_com.ps1 -OutputWorkbookPath <path>creates a small workbook with a Power Query formula loaded to a worksheet table, then refreshes synchronously. Use this to smoke-test query creation, load-to-sheet, and refresh behavior on Windows desktop Excel.scripts/invoke_power_query_excel_com.sh export|manage|refresh|fixture ...runs the Excel COM scripts from Windows Git Bash/MSYS/Cygwin.scripts/inspect_power_query_openxml.py <workbook> [--out-json <path>]performs cross-platform OpenXML inspection for connections, query tables, external links, and mashup-like package parts. It does not compile, refresh, or fully decode Excel's mashup binary.scripts/search_power_query_official_kb.py <keyword> [--json]searches the local official-documentation index and returns Microsoft Learn URLs plus online search queries for Power Query M, Excel-hosted refresh, and diagnostics topics.scripts/lint_power_query_m.py <source> [--warnings-as-errors] [--out-json <path>]statically checks.m,.pq, text, Markdown, or JSON-exported query source for query-shape issues, riskyFolder.Filesingestion, join cardinality risk, order restoration gaps, hard-coded expand columns, and unguardedList.Maxusage. Use it before add/update/import operations.- Package root
tools/build_power_query_lineage_report.py <query-dir> [--out-json <path>] [--out-md <path>] [--fail-on-high-risk]builds a static query dependency and source-risk report from exported.m/.pqfiles. Use it after exporting queries and before large rewrites or delivery reviews to flag query cycles, hard-coded local paths, web/database/cloud-service sources, native SQL pass-through viaValue.NativeQuery, credential-like literals or authorization keys, and mixed-source lineage that can trigger privacy or credential problems. It distinguishes workbook-table/config sources such asExcel.CurrentWorkbookso parameterized folder paths are visible without being treated as mixed-source privacy risk by themselves, and it recognizes common enterprise connectors such as OData, Azure Storage, Power Platform Dataflows, Dataverse, and additional database connectors. Credential-like evidence is redacted to indicators and counts; do not rely on this static check as a full secret scanner.
Validation
Minimum checks:
- Input file count and filtered file list.
- Query lineage and source-risk report reviewed when the workbook has multiple Power Query queries or external sources.
- M source lint passed before changed formulas were imported.
- Row counts before and after joins/expands/groups.
- Final columns and data types.
- No unexpected duplicated rows.
- Stable row order if the output is report-facing.
- Excel refresh tested when a workbook deliverable depends on refresh.
- Refresh timing/status report reviewed before downstream automation continues.
- Refresh failures classified and summarized when refresh did not complete.
- For package maintenance, the full release gate creates a loaded Power Query workbook, updates its M formula, refreshes and waits through Excel COM, saves a refreshed copy, exports the query, and verifies the worksheet table result. The structural release gate intentionally skips this Excel runtime fixture.
Cross-Platform Boundary
M code can be generated and reviewed anywhere. Exact query CRUD, refresh, load-to-sheet/model behavior, popup errors, credential prompts, and completion waiting must be tested in desktop Excel or Power BI.
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.

