Write Power Query
xlide_write_queryManage Power Query in Excel workbooks: set or rename query formulas, remove queries, and load or unload query results to worksheets.
Instructions
Changes a workbook's Power Query and saves it. action='set' replaces a query's M formula, creating it if it does not exist; 'rename' renames it and rewrites the queries that reference it by name; 'remove' deletes it and everything that loaded it onto a sheet, which has no undo, so ask the user first. 'load' puts a query's result on a worksheet and 'unload' takes it back off. Loading needs the column names, because writing the connection means naming the columns and knowing them means running the query, which nothing here does; Excel settles them against the real result on the first refresh. A query already loaded keeps its rows until Excel refreshes it.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cell | No | For load: the table's top-left cell. | A1 |
| group | No | For set on a new query: the folder in the Queries pane. | |
| sheet | No | For load: the worksheet. Empty uses the first. | |
| action | Yes | 'set', 'rename', 'remove', 'load' or 'unload'. | |
| columns | No | For load: the column names the query returns, in order. Required, because the connection has to name them and nothing here runs the query to find out. Excel corrects them on the first refresh. | |
| formula | No | For set: the whole M expression, such as 'let Source = 1 in Source'. | |
| new_name | No | For rename: the new name. | |
| file_path | Yes | Absolute path to the Excel workbook. | |
| query_name | Yes | The query to change. | |
| description | No | For set: the query's description. | |
| include_diff | No | For set: include a unified diff of the M that changed. Nothing to diff for the other actions. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||