hermes

Write Power Query (M) steps

Writes Power Query (M) steps that import, clean, combine and reshape data with refresh-safe logic, explaining each step. Use in Excel or Power BI to automate data prep you redo by hand.

context

You write Power Query for people who will press Refresh every week without opening the editor. The query must keep working when a new file lands in the folder, when a column is added at the source, when a month has no rows, or when someone's locale writes dates differently. You know the M language well (let … in, Table.*, List.*, each, try … otherwise), the patterns the UI generates and where those patterns are brittle, for example the automatic "Changed Type" step that hard-codes every column name.

task

Write the Power Query (M) that turns this source:

source description

into this output:

desired output

  1. Restate the transformation as a short plan: source → steps → output grain (one row per what). If the source layout, the header row or the output grain is unclear in a way that changes the code, ask up to three specific questions and stop instead of guessing.
  2. Write the full query as one let … in block with descriptive step names (for example #"Removed blank rows"). If several queries are needed (a file-combine helper function, a lookup table, a parameter), give each separately and say which to load and which to set to connection only.
  3. Use refresh-safe patterns:
  • File paths and other environment values as parameters, not literals in the code.
  • For folders of files, filter by extension and name pattern, ignore temporary files (names starting with ~$), and combine with a function applied to each file, so a new file is picked up automatically.
  • Promote headers and set types explicitly for the columns you need, using a locale (Table.TransformColumnTypes(…, "en-GB") or similar) when dates or decimals depend on it; select the needed columns by name with MissingField.UseNull or MissingField.Ignore where a missing column should not break the refresh.
  • Reshape with Table.UnpivotOtherColumns so new period columns are included, rather than unpivoting a hard-coded list.
  • Remove totals, blank and repeated header rows by a rule (a filter on a key column), not by fixed row positions, unless the layout guarantees them.
  • Use try … otherwise only for expected bad values, and keep a way to see rows that failed (for example an errors query), never silently drop them.
  • Merge queries on cleaned keys (trimmed, consistent case and type), and say whether the join can duplicate rows.
  1. Explain each step in one plain sentence: what it does and why.
  2. Note query folding where the source is a database: which steps will fold and which will break folding, and order the steps to keep folding as long as possible.
  3. Give checks the user can run after refresh: row counts against the source, a total that should match, a count of nulls in key columns.
constraints
  • Write valid M. Use only functions that exist in Power Query; if you are not sure a function or option is available in the user's version, say so.
  • Do not invent column names or sample values. Use the names given; where you must assume one, mark it in the code with a comment (// assumed column name).
  • Comment non-obvious steps inside the code with // comments.
  • Mention privacy levels if the query combines sources of different kinds (for example a file and a web source), because they can block refresh.
  • Keep it as simple as the job allows; prefer UI-reproducible steps where possible so the user can still maintain the query in the editor.
output format

Plan

Source → steps → output grain, in three to six lines.

Query

One fenced code block per query, each with its name and whether it loads.

Step by step

A numbered list: step name — what it does and why.

Refresh safety

What happens when a new file, a new column, an empty month or a renamed column arrives, and how the query handles it.

Checks

Checks to run after the first refresh.

Questions

Only if anything is still assumed.

2 required values still a placeholder; the assistant will ask for them.

details

kind
Prompt: a task you run by name to get one finished thing back
domain
Data analysis
category
Spreadsheets
level
Intermediate
made for
Data analyst, Business analyst, Financial analyst, Operations
risk
read-only
version
v1.0.0 · incubating
reviewed
2026-10-02
works in
Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md, ChatGPT, claude.ai

Edit on GitHubReport a problem

use in

Hodios CLI
npx @hermes-hq/hodios install write-power-query --target claude-code
Agent Skills
npx skills add hermes-hq/hodios-dist --skill write-power-query -a claude-code
Add the Hodios marketplace (once)
claude plugin marketplace add hermes-hq/hodios-dist
Install the data-analysis plugin
claude plugin install hodios-data-analysis@hodios

The plugin brings every entry in this domain at once.

pairs well with

All of Spreadsheets
PromptSpreadsheets

Clean a messy spreadsheet

Cleans messy tabular data (headers, types, duplicates, inconsistent categories, stray totals) and logs every change it makes. Use before analysing an export or a hand-maintained sheet.

clean-messy-spreadsheet
PromptReporting

Write a DAX measure

Writes Power BI DAX measures from plain-language definitions, with filter-context explanations, time intelligence and expected test values. Use as a BI developer or analyst building a report.

write-dax-measure
PromptData exploration

Reconcile two datasets

Reconciles two datasets that should agree, such as bank versus ledger or CRM versus billing, by matching records, listing mismatches and explaining likely causes. Use for month-end checks.

reconcile-datasets
PersonaSpreadsheets

Spreadsheet expert

Spreadsheet expert who builds clean, auditable Excel and Google Sheets workbooks, prefers simple formulas over clever ones and explains each step. Use as a standing spreadsheet helper.

spreadsheet-expert
PromptSpreadsheets

Extract tables from a PDF

Extracts tables from PDF or scanned text into clean CSV, Markdown or JSON, keeps values exactly as printed, flags likely OCR errors and validates totals against the source. Use before analysis.

extract-tables-from-pdf
PromptSpreadsheets

Run a what-if analysis

Builds a scenario and sensitivity analysis for a decision (best, base and worst cases, a tornado chart and breakevens) as a spreadsheet layout with exact formulas. Use before committing to a plan.

run-what-if-analysis