Refreshing Queries to Automate Data Preparation in Excel
Course: Advanced Excel
Topic: Refreshing Queries to Automate Data Preparation
Course Link: Advanced Excel Course
Demo Link: Register for a Course Demo
Website: JustAcademy
1. Introduction to Refreshing Queries
In business reporting, data is frequently updated. Sales transactions arrive daily, inventory records change, customer information is modified, and financial reports are generated every month. Repeating the same cleaning and preparation steps manually can consume time and introduce errors.
Microsoft Excel provides Power Query, a data connection and transformation tool that helps users import, clean, combine, and organize data from different sources. Once a query has been created, its transformation steps can be applied again when the source data changes by refreshing the query.
Refreshing a query means updating its results using the configured data source and transformation steps. Instead of manually copying, cleaning, and rearranging every new dataset, users can refresh an existing query and reuse the established preparation workflow.
Learning Objectives
- Understand Power Query and query refreshing.
- Learn how to refresh a single query and all workbook connections.
- Automate recurring data-cleaning and preparation tasks.
- Configure refresh settings and understand their limitations.
- Import updated files from folders and combine new records.
- Identify and troubleshoot common refresh errors.
- Use refreshed data for PivotTables, charts, and dashboards.
- Build a reliable, repeatable data-preparation workflow.
2. What Is Power Query?
Power Query is a tool available in modern Excel versions that connects to data sources and provides a structured environment for transforming data before loading it into a worksheet or the Excel Data Model.
It records transformation steps such as removing blank rows, changing column names, filtering records, splitting columns, merging tables, replacing values, and setting data types. These steps can be applied again when the query is refreshed.
Common Data Sources
- Excel workbooks.
- CSV and text files.
- Folders containing multiple compatible files.
- Supported databases and organizational data systems.
- Other connectors available in the user's Excel version.
Example
Suppose a sales team receives a new CSV file every day. Each file contains Order ID, Order Date, Product, Region, and Sales. A Power Query workflow can import the data, standardize column names, remove blank records, convert dates, and set Sales to a numeric data type.
When the source data is updated, the query can be refreshed to apply the same transformation steps to the available records, provided the source structure remains compatible.
3. Understanding Queries and Refreshing
A query is a saved set of instructions that connects to a source, retrieves data, and applies transformation steps. The query stores the preparation process rather than requiring users to repeat each action manually.
| Term |
Meaning |
Example |
| Source |
The file, folder, database, or other location containing the original data. |
Monthly_Sales.csv |
| Query |
A saved connection and set of data preparation instructions. |
Sales_Cleaning_Query |
| Transformation |
An operation applied to the source data. |
Remove blank rows or change a column type. |
| Refresh |
Runs the query again to retrieve and transform data from its source. |
Update the report after a new sales file arrives. |
| Load Destination |
The location where the query results are made available. |
Worksheet table or Data Model. |
| Refresh All |
Requests a refresh of supported workbook connections and queries. |
Update multiple connected datasets. |
4. Why Refreshing Queries Is Important
Refreshing queries improves efficiency by reducing repeated manual work and keeping reports aligned with their configured data sources.
Key Benefits
- Automation: Previously defined preparation steps can be reused.
- Consistency: The same transformation logic is applied to each refresh.
- Time savings: Repetitive copying and formatting can be reduced.
- Reduced manual errors: Fewer repeated manual operations are needed.
- Scalability: A query can process new records and compatible files as the dataset grows.
- Improved reporting: Refreshed data can support updated summaries and dashboards.
- Traceability: Applied Steps in Power Query help users review the preparation process.
Refreshing does not guarantee that all source data is correct. Users should still validate the results, investigate errors, and confirm that the transformations match the business requirements.
5. Creating a Query Before Refreshing
Before a query can be refreshed, it must be created and configured. The following example demonstrates how to import and prepare sales data.
Step-by-Step Procedure
- Open the destination workbook in Excel.
- Select the Data tab.
- Choose Get Data or the relevant import command.
- Select the source type, such as From Excel Workbook, From Text/CSV, or From Folder.
- Browse to the required file or folder.
- Preview the available data.
- Select Transform Data to open Power Query Editor.
- Remove unnecessary rows and columns.
- Rename columns and correct data types.
- Standardize text values and handle errors where appropriate.
- Select Close & Load or configure the desired load destination.
- Give the query a clear, meaningful name.
Example Query Name
Instead of using a generic name such as Query1, use a descriptive name like Sales_Data_Cleaned. Meaningful query names make workbooks easier to maintain when multiple data sources are involved.
6. How Query Refreshing Works
When you refresh a query, Excel attempts to retrieve data from its configured source and execute the saved transformation steps. The results are then updated in the configured destination, subject to the query type, connection settings, and successful completion of the refresh.
- Connect: Excel accesses the configured data source.
- Retrieve: The source data is read according to the query configuration.
- Transform: Saved steps are applied, such as filtering, replacing values, or changing data types.
- Validate: The query processes the data and reports any encountered errors.
- Load: The resulting data is updated in the configured destination when the refresh succeeds.
- Report: Dependent summaries or visualizations can be updated as needed.
If the source file has been moved, renamed, deleted, or changed unexpectedly, the refresh may fail or produce different results. A reliable workflow includes checking the refresh status and verifying important totals.
7. Refreshing a Single Query
Refreshing a single query is useful when you want to update one dataset without intentionally refreshing every connection in the workbook.
Method 1: Using the Data Tab
- Open the workbook containing the query.
- Select the Data tab.
- Open Queries & Connections if available in your Excel version.
- Locate the query you want to update.
- Right-click the query and select Refresh.
- Wait for the operation to complete.
- Check the resulting table or connection status.
Method 2: Refreshing from a Loaded Table
For a query loaded to a worksheet table, you may be able to right-click the table and choose Refresh. The exact available options depend on the Excel version and connection type.
When to Use a Single-Query Refresh
- Updating a particular sales dataset.
- Refreshing a customer list without refreshing unrelated sources.
- Testing a query after changing its source data.
- Checking whether a specific query is working correctly.
8. Using Refresh All
Refresh All is useful when a workbook contains multiple connected datasets. It requests an update of supported connections and queries rather than requiring users to refresh each one individually.
Step-by-Step Procedure
- Open the workbook.
- Go to the Data tab.
- Select Refresh All.
- Wait for the refresh operations to complete.
- Review any errors or connection warnings.
- Check the key tables, totals, and reporting outputs.
Example
A business reporting workbook contains three queries:
| Query Name |
Source |
Purpose |
| Sales_Data |
Sales CSV files |
Sales analysis. |
| Customer_Data |
Customer workbook |
Customer details. |
| Product_Data |
Product master workbook |
Product descriptions and categories. |
Refresh All can request updates to these connected sources. If a source is unavailable or its structure changes, the relevant query may fail even if other queries refresh successfully.
9. Automating Data Preparation with Applied Steps
Power Query's Applied Steps list records the operations used to prepare a dataset. These steps are executed again during refresh, helping users automate repeatable cleaning tasks.
Example of an Automated Preparation Sequence
- Source: Connect to a sales CSV file.
- Promoted Headers: Use the first row as column headers.
- Changed Type: Set Order Date to Date and Sales to Decimal Number.
- Trimmed Text: Remove unnecessary spaces from selected text fields.
- Filtered Rows: Exclude blank or irrelevant records according to the reporting rules.
- Replaced Values: Standardize known regional abbreviations.
- Removed Columns: Exclude fields not required for the report.
- Loaded Results: Load the cleaned dataset to Excel.
Once configured, these steps can be reapplied when the query refreshes. However, if a source column is renamed or removed, a step that depends on it may fail and require modification.
10. Refreshing Data from a Folder
Folder-based queries are particularly useful when the same type of file is received regularly. For example, a company might store daily transaction exports or monthly sales reports in a dedicated folder.
Example Folder Structure
MonthlySales/
Sales_January.csv
Sales_February.csv
Sales_March.csv
If the files have compatible structures, Power Query can combine their records into a consolidated dataset.
Setup Procedure
- Place the intended source files in a dedicated folder.
- Open Excel and select Data > Get Data > From File > From Folder.
- Select the folder containing the files.
- Review the file list and exclude unrelated or temporary files if necessary.
- Select Combine & Transform Data.
- Choose the correct worksheet, table, or data object if prompted.
- Inspect the combined output and standardize column names and data types.
- Load the result into the destination workbook.
Adding New Files
When a new compatible file is placed in the configured folder, refreshing the query can include its records, provided that the query's folder path, filters, and transformation steps allow the file to be processed.
Best Practices for Folder Queries
- Use consistent column headers across files.
- Keep file structures compatible.
- Exclude backup files and unrelated exports from the folder query.
- Check for repeated header rows inside the combined dataset.
- Verify that each new file contains valid dates, numbers, and identifiers.
- Test the query after adding a new file.
11. Configuring Query Refresh Properties
Excel may provide connection properties that control when and how certain queries refresh. Available options depend on the Excel version, source connector, and type of connection.
Common Refresh Settings
| Setting |
Purpose |
Important Consideration |
| Refresh on Open |
Requests a refresh when the workbook opens. |
The source must be available and accessible. |
| Refresh Every N Minutes |
Refreshes supported connections at a configured interval. |
May not be available for every query type and can affect performance. |
| Background Refresh |
Allows supported connections to refresh while you continue working. |
Results may not be ready immediately. |
| Refresh All |
Requests refreshes for supported workbook connections and queries. |
Review completion status and dependent reporting outputs. |
| Connection Properties |
Provides settings for a supported data connection. |
Options vary by connection and Excel version. |
How to Check Refresh Settings
- Open the Data tab.
- Open Queries & Connections or the relevant connection properties interface.
- Locate the connection or query whose settings you want to review.
- Open its properties if the option is available.
- Inspect the available refresh controls.
- Enable only the settings that suit the reporting workflow.
- Save the workbook and test the behavior.
Do not assume that every Power Query connection supports every refresh option. Confirm which settings are available in your Excel installation.
12. Understanding Manual, On-Open, and Scheduled Refreshing
| Refresh Approach |
Description |
Suitable Scenario |
| Manual Refresh |
The user initiates a refresh. |
Occasional reports or controlled updates. |
| Refresh on Open |
A supported connection is configured to refresh when the workbook opens. |
Workbooks that should attempt to retrieve current data on opening. |
| Interval-Based Refresh |
A supported connection refreshes at a configured interval. |
Use cases where periodic updates are appropriate and supported. |
| External Scheduled Automation |
An approved automation workflow runs a supported refresh process. |
Operational reporting that must update without a user opening Excel manually. |
Excel's built-in refresh settings do not automatically provide unattended scheduling for every workbook and connector. A process that must run reliably without a user present may require a supported service or automation platform, suitable licensing, credentials, and appropriate permissions.
13. Refreshing Queries and Updating PivotTables
Power Query can prepare data for PivotTables and charts. When source data changes, the query may need to be refreshed first, followed by any dependent summaries that do not update automatically in the same workflow.
Recommended Update Sequence
- Update the source file or add the new source records.
- Refresh the Power Query connection.
- Confirm that the loaded table or Data Model contains the expected records.
- Refresh dependent PivotTables if needed.
- Check formulas, charts, and dashboard summaries.
- Validate totals against the source data.
For a PivotTable based on a query output, refreshing the query and refreshing the PivotTable are distinct operations. Depending on the workbook configuration, Refresh All may handle supported dependent connections, but the final report should still be checked.
Example
A sales report initially contains transactions from January to March. In April, the source folder receives a new April file. After refreshing the folder query, verify that April transactions are present, refresh the relevant PivotTable, and confirm that the chart and total sales figures reflect the new period.
14. Refreshing Queries with Changed Source Data
Refreshing works most reliably when the source structure remains consistent. Changes to column names, data types, sheet names, table names, or file locations may affect the query.
Examples of Source Changes
| Source Change |
Possible Effect |
Recommended Action |
| A new row is added. |
The new record may appear after refresh. |
Refresh and verify the row count. |
| A new compatible file is added to a folder. |
The query may include the file if it passes the query's filters. |
Refresh and verify the new records. |
| A column is renamed. |
Later transformation steps may fail. |
Update the affected query steps. |
| A required column is deleted. |
Formulas or transformation steps may fail. |
Restore the column or redesign the transformation. |
| A source file is moved. |
The query may not find the file. |
Update the source path or restore the file location. |
| A number column contains text. |
Data type conversion errors may occur. |
Investigate the unexpected values and define a suitable conversion rule. |
| Column headers become inconsistent. |
Combined files may create extra columns or missing values. |
Standardize headers or add a transformation to handle variations. |
15. Handling Errors During Query Refresh
Refresh errors can occur because of unavailable files, changed source structures, authentication issues, invalid values, or network problems. A successful workflow includes identifying the cause rather than repeatedly refreshing without investigation.
Common Errors and Solutions
| Error |
Likely Cause |
Solution |
| File not found |
The source file was renamed, deleted, or moved. |
Check and update the source path. |
| Access denied |
The user lacks permission to access the source. |
Confirm file permissions and approved credentials. |
| Authentication failure |
Credentials have expired or changed. |
Review the connection's authentication settings. |
| Column not found |
A required source column was renamed or removed. |
Review the source structure and update dependent steps. |
| Data type conversion error |
A column contains values that cannot be converted to the expected type. |
Inspect error rows and correct the data or conversion logic. |
| Query takes too long |
Large files, complex transformations, or slow source connections. |
Reduce unnecessary columns and rows early and review the query design. |
| New files are not included |
Folder filters or filename rules exclude the files. |
Review the folder query's filters and source location. |
| Report totals do not change |
The source did not change, the refresh failed, or the report has not been refreshed. |
Check the query output and refresh dependent PivotTables or calculations as required. |
16. Best Practices for Reliable Query Automation
- Use stable source locations: Store recurring files in predictable folders.
- Adopt consistent file structures: Keep column names, data types, and table layouts consistent.
- Use meaningful query names: Names such as Monthly_Sales_Cleaned are easier to maintain than Query1.
- Remove unnecessary data early: Filter irrelevant records and columns when appropriate.
- Document transformation logic: Use understandable step names and record important assumptions.
- Protect source files: Keep original files available for comparison and recovery.
- Handle errors deliberately: Do not remove error rows automatically without understanding their impact.
- Control access: Use approved credentials and permissions for sensitive data sources.
- Validate refreshes: Compare record counts, date ranges, and important totals after updating.
- Test with changed source files: Confirm that the query still works when new records or files are introduced.
- Monitor performance: Large queries may need optimized transformations or a different data-loading strategy.
- Maintain dependencies: Check related PivotTables, formulas, charts, and dashboards after important refreshes.
17. Practical Exercise: Automate Monthly Sales Preparation
Scenario: A company receives a separate CSV file for each month's sales. The files contain Order ID, Order Date, Product, Region, and Sales. The reporting team currently combines the files manually and repeats the same cleaning steps every month.
Exercise Tasks
- Create a folder named MonthlySales.
- Place at least three compatible monthly CSV files in the folder.
- Create a new Excel workbook and import the folder through Get Data.
- Combine and transform the files using Power Query.
- Set Order Date to Date and Sales to a numeric type.
- Trim text fields and standardize known region labels.
- Remove unnecessary columns and blank records according to the business rules.
- Load the cleaned data into Excel.
- Create a PivotTable summarizing sales by region and month.
- Add a new compatible monthly file to the source folder.
- Refresh the query and confirm that the new records appear.
- Refresh the PivotTable if necessary and compare the totals with the source data.
Expected Outcome
The workbook should contain a repeatable query that combines the selected monthly files, applies the saved preparation steps, and supports updated reporting after a successful refresh.
18. Mini Project: Create a Refreshable Business Dashboard
Project Objective: Build an Excel dashboard that uses Power Query to automate the preparation of recurring business data.
Project Requirements
- Import transaction data from a folder containing multiple files.
- Import a product master table from a separate Excel workbook.
- Clean column names, data types, and inconsistent text values.
- Use Append Queries to combine compatible monthly transaction datasets.
- Use Merge Queries when transaction records need related product information.
- Load the prepared data to an appropriate worksheet or Data Model.
- Create PivotTables and charts showing sales by region, product, and month.
- Configure appropriate refresh settings that are supported by the connections.
- Test the workbook after adding a new source file.
- Document any manual steps that remain necessary.
Project Deliverables
- A workbook containing named Power Query connections.
- A cleaned and consolidated dataset.
- A dashboard with relevant charts and summary figures.
- A documented refresh procedure.
- A validation checklist for record counts, totals, and errors.
19. Interview Questions and Answers
Q1. What is Power Query in Excel?
Answer: Power Query is a data connection and transformation tool that imports data from supported sources and helps users clean, combine, and prepare it for analysis.
Q2. What does refreshing a query mean?
Answer: Refreshing a query reruns the configured data retrieval and transformation process to update its results from the source.
Q3. What is the difference between Refresh and Refresh All?
Answer: Refresh updates a selected query or connection, while Refresh All requests updates for supported connections and queries in the workbook.
Q4. How does Power Query automate data preparation?
Answer: It stores transformation steps such as filtering, replacing values, changing data types, and combining files. Those steps can be reapplied during refresh.
Q5. Can Power Query automatically include new files from a folder?
Answer: Yes, a correctly configured folder query can include new compatible files when refreshed, provided they are not excluded by filters and follow the expected structure.
Q6. What is Refresh on Open?
Answer: It is a setting available for supported connections that requests a refresh when the workbook opens.
Q7. Why might a query fail after a source column is renamed?
Answer: A transformation step may refer to the original column name. The affected step must be reviewed and updated to match the new structure.
Q8. Does refreshing a query always refresh a PivotTable?
Answer: Not necessarily. Query refresh and PivotTable refresh can be separate operations, depending on the workbook configuration. Verify that dependent reports reflect the updated data.
Q9. How can you improve query refresh performance?
Answer: Remove unnecessary columns and rows early, simplify transformations, avoid redundant steps, and use an appropriate load destination.
Q10. Why is data validation important after refreshing?
Answer: Validation confirms that the query loaded the expected records and that important totals, dates, and fields are correct.
Q11. What can cause a query refresh to fail?
Answer: Common causes include missing files, changed source structures, invalid data types, unavailable network locations, and authentication or permission problems.
Q12. Does Excel support unattended scheduled refresh for every query?
Answer: No. Built-in refresh options vary by connection type and Excel version. Unattended automation may require an additional supported service or automation platform.
20. Quick Revision Checklist
- Understand queries, sources, transformations, and load destinations.
- Create a Power Query workflow before attempting to refresh it.
- Know how to refresh a single query and use Refresh All.
- Understand how Applied Steps automate recurring preparation.
- Use folder queries to combine compatible files.
- Review refresh properties and use only supported settings.
- Refresh dependent PivotTables and verify dashboards as needed.
- Troubleshoot source paths, authentication, changed columns, and data errors.
- Validate record counts, date ranges, and key totals after refreshing.
- Document the workflow and test it with updated source data.
21. Conclusion
Refreshing queries is an important Advanced Excel skill because it allows users to repeat data preparation without manually performing every cleaning and combining operation. Power Query can retrieve data from supported sources, apply saved transformation steps, and load the results for analysis.
By creating clear queries, keeping source structures consistent, configuring appropriate refresh settings, and validating results, you can develop reliable workflows for recurring reports and dashboards. Refreshing should always be combined with sensible error handling and data-quality checks.
To build more practical spreadsheet and reporting skills, explore the Advanced Excel Course at JustAcademy, visit the JustAcademy website, or register for a course demo.
22. Additional Learning Resources