Protect Power Query Code While Allowing Excel Refresh and Editing
Question details
The user needs to completely hide and protect Power Query code and the Data Model without restricting users from refreshing the data or freely modifying the workbook structure.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Sharing an Excel workbook containing sensitive Power Query transformation logic where users still need full access to refresh data and use worksheet features.
- Observed behavior
- Native Excel workbook and worksheet protection cannot fully secure the Power Query M code and Data Model while simultaneously allowing users to refresh data and edit the workbook structure.
Ensure you have access to a Power BI account with permissions to create dataflows, as this solution relies on moving the transformation logic outside of the Excel environment.
Store Power Query Logic in a Power BI Dataflow
By moving the transformation logic to a Power BI dataflow, you can completely hide the Power Query code from Excel users while securely allowing them to refresh the imported data.
Microsoft Excel's native protection features cannot simultaneously hide Power Query code and allow full workbook flexibility. The most secure workaround is to separate the data transformation layer from the presentation layer.
Using Power BI dataflows keeps your proprietary M code strictly within the Power BI cloud environment. Excel only connects to the finished, transformed data.
Open the Power BI Service in your web browser, navigate to your desired workspace, click 'New', and select 'Dataflow'. Paste or recreate your Power Query (M code) logic here.
Save the dataflow and ensure that the users who will be using the Excel file have the appropriate read permissions for this workspace or dataflow.
Open your Excel workbook, go to the 'Data' tab on the ribbon, click 'Get Data', navigate to 'From Power Platform', and select 'From Power BI' or 'From Dataflows'.
Select the dataflow you just created and load the transformed data into your worksheet. Users can now refresh the data and use slicers without ever accessing the backend Power Query code.

Need a Lightweight Alternative for Data Processing? Try WPS Office
While advanced Power Query code isolation requires specialized enterprise setups like Power BI, everyday data analysis doesn't have to be complicated. WPS Office provides a highly compatible, fast, and free alternative to Microsoft Office for your daily spreadsheet processing needs.
- 1. Download and Install: Get WPS Office for free from the official website and install it on your device.
- 2. Open Your Workbooks: Launch WPS Spreadsheets and open your existing Excel files effortlessly with full formatting retention.
- 3. Analyze Data Securely: Utilize built-in data tools to analyze, protect, and share your spreadsheet data safely.

Frequently Asked Questions
Can I password-protect just the Power Query editor in Excel?
No, Excel does not currently offer a native feature to selectively password-protect or lock the Power Query editor while keeping the rest of the workbook unlocked for data refreshes and editing.
Does Excel workbook protection prevent Power Query data refreshes?
Yes, if the workbook or worksheet structure is protected, it often restricts background actions like inserting new rows or tables during a data refresh, which will cause the Power Query refresh to fail.
Can I hide the queries pane from users in Excel?
You can close the 'Queries & Connections' pane, but any user with basic Excel knowledge can easily reopen it from the 'Data' tab to view or edit the queries unless the data transformation is moved externally, such as to a Power BI dataflow.




