To undo a deleted step in Power Query, you cannot use a traditional "Undo" button (Ctrl+Z) because Power Query records transformations as a sequential list of instructions rather than a live document. Instead, you must locate the deleted step in the Applied Steps pane and manually restore it, or if the step was deleted using the X icon, you must re-apply that specific transformation or use the Advanced Editor to recover the M code. If you have not yet saved and closed the query, you can sometimes recover the logic by checking the formula bar for remnants of the previous state, but generally, "undoing" a deletion means re-inserting the step into the sequence of the Applied Steps list.

What You'll Need

  • A computer with Microsoft Excel or Power BI Desktop installed.
  • An active data query open in the Power Query Editor window.
  • Basic familiarity with the Applied Steps pane located on the right side of the editor.
  • Access to the original data source to ensure that re-applying steps does not create conflicts with updated source data.

Step-by-Step

  1. Open the Power Query Editor: If you are in Excel, go to the Data tab and select Queries & Connections. Right-click your query and select Edit. If you are in Power BI, click Transform Data from the Home ribbon. This opens the environment where all transformation steps are managed. Note that labels and menu paths may differ slightly depending on your version of Excel or Power BI, or your regional settings.

  2. Locate the Applied Steps Pane: Look at the right-hand side of the screen. The Applied Steps pane lists every action you have taken since the data was first imported (e.g., Source, Navigation, Changed Type). This is the "audit trail" of your data cleaning process. Each step is a line of M code that transforms the table from the state it was in during the previous step.

  3. Identify the Gap: Since Power Query does not have a "Recycle Bin" for deleted steps, you cannot simply click an "Undo" button to bring back a step you clicked the "X" on. You must determine exactly which transformation was removed. For example, if you deleted a "Filtered Rows" step, your data will suddenly show records that were previously hidden. Check the data preview to see which columns or rows have reappeared or changed format to identify what is missing.

  4. Re-apply the Transformation: The most direct way to "undo" the deletion is to perform the action again. If you deleted a column, go to the column you want to remove, right-click, and select Remove. If you deleted a filter, click the dropdown arrow on the column header and re-select the criteria you had previously chosen. Power Query will add this as a new step at the bottom of the list. If you deleted a "Split Column" action, select the column again, go to the Transform tab, and repeat the split settings (e.g., by delimiter or number of characters).

  5. Reposition the Step via the Advanced Editor: If the deleted step needs to happen before other subsequent steps to avoid errors (such as a column name change that subsequent steps rely on), you cannot simply drag and drop the step in the Applied Steps list. Go to the Home tab and click Advanced Editor. This opens a text window showing the entire M script. You will see a series of lines starting with a step name and ending with a comma. To restore a step in the middle, you must manually write the M code for that transformation and ensure the step immediately following it references the restored step's name. For example, if Step A was deleted and Step B now references the Source, you must re-insert Step A and change Step B's reference from "Source" to "Step A".

  6. Verify Data Integrity: After restoring the step, click through each subsequent step in the Applied Steps pane. If you see a yellow warning bar or a red error message saying "The column 'X' of the table wasn't found," it means the restored step changed the data structure in a way that the following steps no longer recognize. You will need to either update the subsequent steps to match the new column names or re-do those steps entirely.

Understanding the M Code Logic

To effectively undo a deletion, it is helpful to understand how Power Query handles steps. Every action you take in the user interface is translated into a language called M. When you delete a step by clicking the X, you are essentially deleting a line of code and telling the next line of code to look at the step that came before the deleted one. This is why simply re-adding the step at the end of the list often doesn't fix the logic if the deleted step was a prerequisite for others.

For example, if your sequence was: Source > Filtered Rows > Changed Type. If you delete "Filtered Rows," the "Changed Type" step now looks directly at the "Source." If you then re-add the filter at the end, your sequence becomes: Source > Changed Type > Filtered Rows. While the end result might look the same, the performance can differ, and if the filter removed rows that had incompatible data types, the "Changed Type" step might now throw an error because it is processing data that was previously filtered out.

Common Mistakes

One of the most common mistakes is attempting to use Ctrl+Z to recover a deleted step. This keyboard shortcut only works for certain UI interactions, such as typing in a formula bar or renaming a query; it does not restore a deleted transformation step from the Applied Steps pane. Another frequent error is deleting a step and then continuing to build the query, only to realize later that the deleted step was critical for data cleaning. Because Power Query doesn't have a version history for individual queries, this often results in the user having to delete half of their work to re-insert the missing step in the correct sequence.

Users also frequently forget to check the formula bar before deleting a step. The formula bar shows the exact M code for the selected step. If you are unsure if you need a step, copying the code from the formula bar into a Notepad document before deleting it provides a manual backup that allows for an exact restoration via the Advanced Editor.

Tips

To avoid the stress of deleted steps, use the "Duplicate" feature. Before performing a complex series of transformations that you might want to undo, right-click the query in the Queries pane and select Duplicate. This creates a carbon copy of your current progress. If you make a mistake or delete a critical step in the primary query, you can simply go back to the duplicate and start over from that point.

Another professional tip is to name your steps clearly. Instead of leaving a step as "Filtered Rows1," right-click it and rename it to "Filter_Out_Null_Dates." When you accidentally delete a step, a clearly named list makes it immediately obvious which specific transformation is missing, reducing the time spent auditing the data to find the gap.

Troubleshooting

If you re-apply a deleted step and the query fails with an error, first check the formula bar for the step immediately following the restored one. Ensure the name in the parentheses matches the name of your restored step exactly. M code is case-sensitive; "FilteredRows" is not the same as "Filteredrows." If the names do not match, the query will break.

If the data looks incorrect after restoration, check for "ghost" steps. Sometimes, when we try to fix a deleted step, we accidentally create multiple versions of the same transformation (e.g., two "Changed Type" steps). This can lead to confusion and slow performance. Review the Applied Steps list and remove any redundant actions.

If you have closed and saved the workbook after deleting a step and no longer have the M code, your only option is to re-perform the transformation manually. To prevent this in the future, consider saving a backup copy of your Excel or Power BI file before starting major query overhauls.