persist_model_edit
Persist Power BI model edits into .pbix, automatically choosing the right route (live Desktop or offline) and preserving data with atomic saves and backups.
Instructions
THE single entry to fix a measure / relationship / calculated column in a model AND persist it to the .pbix. Picks the best route for target and reports what it did plus what is / isn't preserved. target = an open model sessionId (from connect_model) -> live edit + scripted Power BI Desktop File>Save; DATA PRESERVED for ANY model (needs the .pbix open in Desktop). target = a cold .pbix PATH -> offline engine edit (ImageLoad->edit->ImageSave->repack); DATA PRESERVED, no Desktop, but ONLY for M-free / engine-native models. If the .pbix imports via Power Query (M) - a normal data report - the offline route cannot host it and the result explains to open it in Desktop and pass the sessionId instead. edits = a JSON array of edit objects (see the tool-type summary). A .bak backup is taken and the write is atomic.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| edits | Yes | JSON array of edit objects, each with an "op" (add_measure, add_relationship, add_calculated_column, ...) | |
| target | Yes | an open model sessionId (data-preserving via Desktop) OR a cold .pbix path (offline, M-free only) | |
| pbixPath | No | the .pbix path to confirm the save landed (only used for the live/Desktop route; optional) | |
| saveRetries | No | scripted File>Save attempts before giving up (live route; default 2) |