Sub topic 1
Power Query in Excel: the editor and queries
Prerequisites
Assume you are comfortable with Excel tables and the Data ribbon. You should know that CSV files store separated text and that .xlsx files are workbooks. You also need Excel 2016 or Microsoft 365 with Power Query.
Power Query in Excel
Power Query is Excel's tool for importing and reshaping data. A query is a saved set of steps that gets data from a source and changes it. The Power Query Editor displays a preview, an Applied Steps list, and controls for filtering, splitting, and changing columns.
The query does not usually change the source files. It records transformations that Excel repeats when you refresh the query.
Connecting to a folder
Choose Data > Get Data > From File > From Folder. Select the folder that contains the exports. Power Query returns a file list instead of opening one file immediately.
Use Combine & Transform Data when the files share a layout and need cleaning before they are appended. Use Load only when you want the initial file list in Excel.
Understanding the file list
Each row represents one file. Important columns include:
| Column | Meaning |
|---|---|
| Content | The file's binary contents |
| Name | The file name |
| Extension | The suffix, such as `.csv` |
| Date modified | When the file last changed |
| Folder Path | The containing folder |
The Content column is used to read each file. The other columns help you select files and retain source information.
Choosing which files to combine
Filter before combining. Keep the required extension, a predictable name pattern, and the intended folder. Exclude temporary Excel files whose names start with ~$.
let
Source = Folder.Files("C:\Data\Sales"),
CsvOnly = Table.SelectRows(
Source,
each [Extension] = ".csv"
and not Text.StartsWith([Name], "~$")
)
in
CsvOnlyFolder.Files includes files in subfolders. Use Folder.Contents when you need only the selected folder, or filter Folder Path explicitly.
Combining with Combine & Transform Data
Power Query chooses a sample file and opens its contents in the editor. The transformations you apply to that sample become a reusable function. Excel then applies that function to every filtered file and appends the results into one combined query.
It also creates helper queries, commonly named Sample File, Transform File, and a folder parameter. Edit Transform Sample File when every file needs the same cleanup.
Exercise
Which query should you edit when a cleanup step must apply to every file?
Show answer
Edit the Transform Sample File query. Its steps define the function applied to each selected file.