10.1 Opening Power Query: Data from a Workbook or CSV
An import is the first point where a correct file can become an incorrect report. A date can be interpreted in the wrong order, an identifier can lose its leading zeros, or a worksheet summary can be mistaken for the transaction list. This lesson teaches you to bring data into Power Query deliberately and prove that the important values survived.
We will import a tiny CSV, refresh it after a controlled change, and connect a separate workbook containing the original Kesari Mart practice records. Every name, shop, amount and operational situation here is fictional teaching data. The earlier example filename blinkit_orders_nov.csv is only a familiar delivery-export context; it is not an actual company file. The detailed menu instructions use Windows desktop Excel with Power Query available. Other Excel environments have different connector choices.
1. Connect to a source instead of copying an unexplained result
Importing creates a repeatable connection
Suppose Shahrukh receives a daily grocery export. He could open it, copy rows into a report workbook and repair the columns by hand. The next day he would have to repeat those repairs and remember exactly what he changed. A query lets him connect to the source and keep the preparation instructions with the report. The next refresh can repeat those instructions against the current source.
The connection also makes a question unavoidable: which source? Two files with similar names can cover different days. A workbook can contain both a transaction sheet and a dashboard. A CSV can be an old download even if it sits in today's folder. Before clicking Import, identify the expected location, period and record type. A successful connection to the wrong source is still the wrong import.
- Write the source filename or table name in your practice notes.
- Record the period that the supplied data covers.
- State what one data row represents.
- Count the expected fields and records in a small sample.
- Identify one value that would expose a bad conversion.
- Choose Transform Data when you need to inspect the interpretation before loading.
The source and output remain separate
In a normal import workflow, Power Query reads the source and produces a transformed result. Choosing Trim inside the editor does not rewrite a customer's name in the CSV. Loading a result to Excel does not convert the original file into that worksheet. This separation is helpful because you can compare the original record with the prepared result.
It also explains a common surprise: changing the source does not necessarily change the loaded result immediately. The query must refresh. Conversely, editing a cell in the loaded output is not a reliable permanent correction because a refresh can replace it with the query's calculated result. Repair the source or the saved steps, depending on who owns the authoritative data and what the correction means.
A good import proves more than an attractive preview
A preview with sensible headings is a useful first check. It is not enough by itself. Some faults are visible only in specific records: a leading-zero ID, a date whose day is greater than twelve, a quoted comma, a non-English product name or a value near the end of the file. Choose test records that could reveal the failure you are worried about.
When you explain your import to another student, connect each check to its purpose. “I checked 00127 because numeric conversion would remove its zeros” is stronger than “I checked some rows.” “I counted five columns because a comma inside the product name must stay inside one field” shows that you understand the file's structure.
2. Choose the correct object inside an Excel workbook
A workbook can contain several kinds of object
An Excel workbook is a container. It may hold worksheets, named Excel Tables and named ranges, alongside formulas and formatting. The Navigator shown by a workbook import helps you select what to read. Do not choose the first entry merely because it appears at the top. Inspect its name, icon, headings and sample records.
A worksheet is a sheet-sized layout that may mix a title, notes, several small tables and a summary. An Excel Table is a defined rectangular data object with headings and a name. If the intended records are already in a well-formed named Table, selecting that Table often gives a clearer boundary than selecting the entire sheet. The Table can still be incomplete if new rows were typed outside its actual range.
Power Query can also suggest tables from a worksheet's arrangement. A suggested object is not a business guarantee that the inferred area includes every required record. If the layout changes, inspect the selection again. For a recurring export you control, a stable named Table and consistent headings make the relationship easier for another learner to maintain.
Current workbook and external workbook use different starting points
For a Table already in the current workbook, select a cell inside it and use Data → From Table/Range. For another workbook, start from Data → Get Data → From File → From Excel Workbook, choose the file and inspect Navigator. These routes both reach the query editor, but their source definitions describe different locations. A table in the current workbook is not the same as a file connection pointing at a saved copy elsewhere.
When practising the external-file route, save the source workbook before refreshing the report. An unsaved edit in another open window may not be the content your file connection reads. For the controlled lab, save and close the source before refreshing the destination. This removes ambiguity about which saved version should supply the expected values.
Watch for headers, totals and notes
The first data row should not accidentally become a heading. Equally, a heading row should not remain mixed into the records and later fail numeric conversion. A named Table normally provides its column names as part of its structure. A raw worksheet or CSV may need the first row promoted to headers. Inspect what is already present before applying that operation.
A grand total underneath a transaction list is not another transaction. If it enters the source range and you sum the values again, it can double a total. A title such as “November Orders” above the list is not a customer name. Define the boundaries and remove non-record layout elements deliberately, preserving enough explanation for another student to reproduce your choice.
3. Separate encoding, delimiter and locale
Encoding turns stored bytes into characters
A CSV is a text file with a record structure. It does not carry a workbook's sheets, cell formatting or calculation model. Text encoding describes how stored bytes represent characters. A file saved as UTF-8 should be read with that encoding. Choosing UTF-8 is appropriate when it matches the source; it is not a universal repair for every damaged file.
For example, a properly encoded Marathi product name or the rupee symbol should remain readable after import. If characters look corrupted, inspect the source encoding and import setting before changing delimiters or numeric types. Those settings solve different problems. Replacing unreadable characters by hand can hide the underlying mismatch and repeat the same damage on the next refresh.
The delimiter identifies field boundaries
A delimiter separates fields within a record. A comma is common, but semicolon- and tab-delimited exports also exist. The filename alone does not prove which separator the producing system used. Inspect the preview: if the complete line appears in one column, the delimiter may be wrong. If a product name unexpectedly becomes two columns, quotation handling or the source structure may be involved.
In the CSV below, the product Rice, Basmati contains a comma as part of its name. Double quotation marks surround that field so the internal comma is not treated as a separator. A correctly parsed record has five fields. The quotes are structure in the file; the resulting product value is Rice, Basmati without those enclosing quotation marks.
OrderID,OrderDate,Product,Quantity,UnitPrice
00127,03/11/2026,"Rice, Basmati",2,50
00128,04/11/2026,Milk,3,30
00129,05/11/2026,Bread,2,25
Do not split every line using a simple “break at every comma” mental model. Quoted fields can contain delimiters and, in valid CSV structures, other special content. Use the connector's parsing behaviour and confirm the resulting field count. For this small exercise there are three data records, five source fields and one header record.
Locale interprets dates and numeric conventions
Locale concerns conventions used to interpret values such as dates and numbers. The text 03/11/2026 could represent 3 November under day/month/year or March 11 under month/day/year. Automatic interpretation depends on the environment and detection settings; it is not always US-based. The source's intended convention must decide which interpretation is correct.
For our fixture, use day/month/year and interpret the first date as 3 November 2026. Select the date column and use Change Type → Using Locale with Date and an appropriate locale such as English (United Kingdom). If an earlier automatic step has already converted the text incorrectly, return to the original text and replace that conversion. Applying a new display format to the wrong date does not recover the intended meaning.
- Unreadable characters: investigate encoding.
- One long text column: investigate the delimiter and file structure.
- An extra column inside a product name: investigate quotation and separator handling.
- A plausible but wrong date: investigate locale and the type-conversion step.
- Missing identifier zeros: investigate numeric inference before the identifier was protected as text.
- Correct preview but old worksheet values: investigate the load and refresh stage.
These distinctions are documented in Microsoft's Text/CSV connector reference. Use the options to express what you know about the supplied file, then verify the result. An automatic guess is a starting point for inspection, not a substitute for a declared source format.
4. Protect meaning before automatic inference changes it
An identifier is not a quantity
Our first OrderID is 00127. Its five characters identify a record. Adding it to another identifier has no useful business meaning. Preserve the field as Text before numeric conversion removes the leading zeros. If it becomes the number 127, changing that result to Text produces “127”; it does not know that two zeros used to be present.
For a CSV import, choose the option that avoids automatic data-type detection when available, so the original fields enter as text. Then assign the intended types deliberately in the editor. If a Changed Type step has already converted OrderID, inspect an earlier step where the raw field still contains 00127, remove or replace the incorrect conversion, and set the identifier to Text there.
In an Excel source, distinguish the underlying value from its display. A numeric 127 formatted with a five-digit display can look like 00127 while remaining numeric. A true text identifier contains those characters. Decide which representation the source contract requires. Do not invent missing zeros by padding every identifier unless an approved fixed-width rule says that is the intended code.
Convert arithmetic fields explicitly
Quantity and UnitPrice are intended to participate in arithmetic. For the small CSV, Quantity is a positive whole number and UnitPrice is a nonnegative numeric value in rupees per unit. Set their types accordingly. A successful conversion is only one check: a negative quantity would violate this exercise's stated input domain even if it were a perfectly valid number.
A column called Amount may mean a line total, a tax-inclusive order total or a settlement amount. Its name alone does not identify the calculation. Here we deliberately supply UnitPrice and Quantity, so the derived LineValue has the explicit rule Quantity multiplied by UnitPrice. This creates a clear control:100,90 and 50, totalling 240.
Inspect inserted steps without fearing them
Power Query may add steps such as Source, Navigation, Promoted Headers and Changed Type depending on the connector and settings. Not every import has all those names or follows an identical list. Read the actual sequence. The Source step connects to input; Navigation selects an object when needed; header and type steps interpret its structure and values.
The formula bar shows the M expression for the selected step. You can enable it from View if hidden. You do not need to master the whole M language before importing a small table, but recognising the expression helps connect a visible command to a saved transformation. M expressions in the editor are different from worksheet formulas entered into Excel cells.
Follow the first CSV record
Read five original fields
The source contains 00127, a day/month/year date, one quoted product field, quantity 2 and unit price 50.
Preserve the identifier
Keep 00127 as Text before numeric inference. The leading zeros belong to the code.
Interpret date and numbers
The date is 3 November 2026. Quantity 2 and price 50 become numeric values, while Rice, Basmati remains one product field.
Check the output
The line value is 100. With the other two records, the initial output has three rows, seven units and total 240.
5. Lab: import a CSV and prove a controlled refresh
Create a small source file you can inspect
Use a plain-text editor to create GroceryOrders.csv containing exactly the four lines shown earlier, including the header. Save it as UTF-8 in a practice folder. On Windows, check that the filename really ends in.csv rather than.csv.txt. Do not open and resave it through automatic spreadsheet interpretation before the lab, because that could change the very identifiers you are trying to preserve.
Open a new report workbook. Keep a note containing the expected source controls: three records, five fields, seven units and line value 240. Also note the first identifier 00127 and the intended first date 3 November 2026. These control values are small enough to verify by hand, which makes this a useful first import rather than a large file whose mistakes are difficult to locate.
- Choose Data → Get Data → From File → From Text/CSV and select the practice file.
- Set File Origin to UTF-8 because that is how you saved this file. Set the delimiter to Comma.
- Disable automatic type detection where the import dialog offers that option. Check that the quoted product occupies one field.
- Select Transform Data. Name the query ImportedGroceryOrders.
- If the first record is still displayed as Column 1 through Column 5 values containing the intended headings, promote that header row once. Do not promote an actual order record.
- Keep OrderID and Product as Text. Set Quantity to Whole Number and UnitPrice to a suitable numeric type.
- Convert OrderDate from its original text using Date and the declared day/month/year locale.
- Add a Custom Column named LineValue using the expression below and assign a numeric type.
- Inspect all three records, then Close & Load to a new worksheet table.
- Confirm the output has three records and six fields: the original five plus calculated LineValue. Check seven units and total 240.
[Quantity] * [UnitPrice]
The source has five fields, while the final query has six because you deliberately added LineValue. This is a legitimate structural change. Do not report a six-column result as an import failure, and do not compare it with a five-column expectation without accounting for the added step. Count records separately from fields and exclude headings from the data-record count.
Add one new record without replacing the original three
In the plain-text source, append the following line after the existing records and save the file. Keep the original heading and all three original orders. The new record contributes two units and 80. Close the editor after saving so that the test refers to a clear on-disk source version. Return to the report and refresh ImportedGroceryOrders.
00130,06/11/2026,Eggs,2,40
After refresh completes, the loaded result should contain four records, six output fields, nine units and total 320. The first identifier remains 00127 and the new one is 00130. The date range now runs from 3 November through 6 November 2026. Refreshing the unchanged source again should retain these controls rather than append another copy of the four records.
Reveal the CSV lab answer key
The initial amounts are 2×50=100,3×30=90 and 2×25=50, so seven units total 240. The added Eggs line contributes 2×40=80. Cumulative output is four records, nine units and 320. The original source schema has five fields; the calculated output has six. Rice, Basmati is one product value. All four identifiers retain five characters, and the dates use the stated November interpretation.
Try two deliberate failures in a practice copy
First select an unsuitable delimiter, then inspect the source preview and restore Comma. Explain which field-boundary check reveals the mistake. Second, in a copy of the query, convert OrderID to Whole Number and inspect 127. Change that later numeric value to Text and observe that the missing zeros do not return. Repair the conversion at the earlier original-text stage.
Keep these as controlled experiments in your own practice workbook. Do not overwrite an unknown original export while trying to repair an interpretation. The point is to learn where information is lost and which step can recover it from the unchanged source. Rebuilding from the original text is more defensible than inventing values based on how the final sheet is expected to look.
6. Lab: import the original ten-record workbook fixture
Build the source workbook with a named Table
Create a separate workbook named KesariImportSource.xlsx with a sheet named RawImport. Enter the six headings and ten records below in A1:F11. These are the original records used by this lesson's Task Hub exercises. Amount is already a supplied line value in rupees; do not multiply it by Qty again. Every city uses the same teaching currency, including London and Toronto. Their locations do not imply a currency conversion.
| Order ID | Customer | City | Channel | Qty | Amount (₹) |
|---|---|---|---|---|---|
| ORD-501 | lucas rossi | KOLHAPUR | App | 2 | 680 |
| ORD-502 | Vikram Singh | mumbai | Website | 3 | 1440 |
| ORD-503 | Mateo Garcia | Kolhapur | Store | 2 | 680 |
| ORD-504 | olivia brown | Mumbai | Store | 4 | 1920 |
| ORD-505 | Sneha Patil | LONDON | Website | 8 | 3840 |
| ORD-506 | Aisha Khan | nashik | App | 6 | 2880 |
| ORD-507 | hana kim | Mumbai | Store | 3 | 1440 |
| ORD-508 | Yuki Tanaka | Toronto | Website | 5 | 1700 |
| ORD-509 | Diego Lopez | MUMBAI | Website | 2 | 680 |
| ORD-502 | Vikram Singh | toronto | Website | 9 | 2250 |
The first customer's original value has two ordinary spaces before lucas and one after rossi. The Olivia and Hana records follow the same surrounding-space pattern. If copying the displayed table removes those spaces, enter them deliberately for the cleaning exercise. Do not change the customer's letter case yet. We want to distinguish trimming surrounding spaces from changing capitalisation.
Select A1:F11, create an Excel Table with headers, and name it tblImportOrders. Put a note outside the Table explaining that the two ORD-502 records differ. Save and close the source workbook. The source should now have a defined ten-record Table plus a separate note, allowing you to see why Table selection is useful.
- Create a new report workbook named KesariImportReport.xlsx.
- Choose Data → Get Data → From File → From Excel Workbook and select KesariImportSource.xlsx.
- In Navigator, inspect tblImportOrders and the RawImport worksheet entries. Select the named Table for this lab.
- Check the six headings and the first and last records, then select Transform Data.
- Name the query ImportedKesari. Set the four descriptive fields to Text, Qty to Whole Number and Amount (₹) to an appropriate numeric type.
- Keep all ten records. This lab verifies an import; it does not authorise removing a repeated identifier.
- Load to a new worksheet table and check ten records,44 units and total 17,510.
- Check App value 3,560, Store value 4,040 and Website value 9,910. Their sum must equal 17,510.
- Open the query again from Queries & Connections, inspect its source and selected object, and confirm they identify the intended workbook and Table.
- Save the report with a short source-and-controls note so another student can repeat the import.
Do not confuse repeated identifiers with identical rows
ORD-502 occurs twice, but the two records are not identical. One contains Mumbai, quantity 3 and amount 1,440; the other contains Toronto, quantity 9 and amount 2,250. They could represent different lines, a correction, an export error or some other business condition. This fixture does not provide enough information to choose an authoritative row. Keep both while investigating.
Removing duplicates across all six fields would retain both because their fields differ. Removing duplicates using Order ID alone would collapse that key to one record, but that is a different rule and does not establish which values are correct. A hypothetical nine-row count can be calculated without approving that deletion. The Task Hub's count exercise should be read in that limited arithmetic sense.
To see the consequence, excluding the Toronto record would leave 35 units and 15,260. Excluding the Mumbai record would leave 41 units and 16,070. Both alternatives have nine records, yet their totals differ. Therefore “nine rows left” cannot prove that the right record was kept. A production correction needs a stated record identity and an authoritative resolution, not just a desired row count.
Test a saved external-source change
For a controlled change in the practice source, edit only ORD-501 Amount from 680 to 700, save and close KesariImportSource.xlsx, then refresh ImportedKesari in the report. The output should retain ten records and 44 units. Total amount becomes 17,530, App becomes 3,580, while Store and Website stay 4,040 and 9,910. Restore 680 in the saved source and refresh again to recover the baseline.
This test checks the connection to the intended saved file and selected Table. If the report stays at 17,510 after the first change, investigate the saved source version, source path, query completion and displayed destination. Do not assume refresh failed just because you are viewing a different query's table. Query names and sheet labels should make that distinction easy.
Reveal the workbook lab controls
The imported ten records contain 44 units and 17,510 in amount. Channel values are App 3,560, Store 4,040 and Website 9,910. ORD-502 occurs twice with conflicting values. A twenty-rupee increase in ORD-501 gives 17,530 overall and 3,580 for App, with row count and quantity unchanged. Restoring the original source value returns every baseline control. No deduplication is part of this import lab.
7. Complete the original practice checks with clear meaning
Use the unchanged baseline for these answers
Return the workbook source to its original 680 first-row amount and refresh. Use all ten records for the following checks. These preserve the lesson's twelve Task Hub outcomes while making their scope explicit. Some are worksheet formula checks of imported values; they are not claims that the Task Hub itself executes the Power Query editor.
- Count imported records: the nonempty Order ID entries number 10. Exclude the heading.
- Trim the first customer: the result is lucas rossi, with its existing lowercase letters retained.
- Standardise the first city for this exercise: the intended display is Kolhapur. Case conversion is separate from removing spaces.
- Add quantities: the full ten-record source totals 44 units.
- Count the first name's removable surrounding spaces: two leading plus one trailing gives 3.
- Count ORD-502 occurrences: there are 2. This is a repeated-key alert, not proof of two identical records.
- Count Kolhapur ignoring letter case: two records match, ORD-501 and ORD-503.
- Add App amounts:680 plus 2,880 gives 3,560.
- Average the imported line amounts:17,510 divided by 10 gives 1,751. This is a mean per imported line, not a proven average per distinct order.
- Calculate the hypothetical one-row-per-ID count: retaining one of the two ORD-502 entries gives 9. Do not apply that rule without resolving the conflicting records.
- Find the largest Store amount: among 680,1,920 and 1,440, the maximum is 1,920.
- Calculate first-row amount per unit:680 divided by 2 gives 340. The supplied amount is already a line value.
Explain the difference between equivalent-looking cleaning tools
The worksheet TRIM function and Power Query's text trimming are not interchangeable descriptions for every possible string. In this specific fixture, only surrounding ordinary spaces are being tested, so both can remove those edges. Internal repeated spaces or unusual Unicode whitespace require their own checks. Do not promise identical behaviour for all text merely because this first example matches.
Similarly, changing city capitalisation is acceptable for these controlled labels but is not a universal method for correcting people, brand names or codes. A label such as iPhone has intentional case. A case-sensitive identifier can carry meaning. Use a controlled mapping or agreed business convention when the source requires more than a cosmetic display change.
Record what remains unresolved
A successful import can preserve a source problem faithfully. Our workbook import should retain both conflicting ORD-502 records so that the issue stays visible. The acceptance note should therefore say “all ten supplied records imported, repeated key awaiting review,” rather than “data completely clean.” Separating transport, interpretation and business validity makes your report more honest and more useful.
Continue the formula exercises in the existing Excel Task Hub, then use the next lesson to explore cleaning steps in more depth. Keep a copy of the raw fixture and your baseline controls. When you change a transformation later, those records let you explain exactly which output changed and whether that change was intentional.
8. Diagnose an import in a sensible order
Start at the earliest disagreement
If the final total is wrong, avoid randomly changing several steps at once. First confirm the source and its saved content. Then inspect the selected object or parsed text structure, headings, types, filters and calculated fields in order. Find the earliest step whose result differs from the intended input. A downstream total usually reflects an earlier decision.
- File cannot be found: check the intended saved location and whether the source moved.
- Table cannot be found: inspect its actual name in the source workbook and the Navigation step.
- Rows are missing: check source Table membership, chosen object and filters.
- Rows are doubled: check whether a later combination included overlapping inputs.
- First record disappeared: check whether headers were promoted twice.
- Numbers fail conversion: inspect the raw text, separators, locale and invalid values.
- A zero-prefixed code changed: return to the original text before the numeric conversion.
- The preview changed but the sheet did not: complete the appropriate load or refresh and inspect the correct destination.
Keep environment differences visible
The lesson's source files are local practice files and its detailed clicks assume Windows desktop Excel. Microsoft 365 for Mac offers supported workbook and Text/CSV workflows, with its own interface. Excel for the web has supported query capabilities but different source and authentication constraints. Check the current Microsoft source matrix before promising identical behaviour to a class using several platforms.
Do not treat a Power Query Online connector example as a guarantee that every shown gateway or upload step applies to Excel desktop. The underlying idea of connecting and interpreting data transfers, while the host application controls available connections and menus. Teach the concept independently of a screenshot and state which environment the practical instructions require.
9. Check your understanding and interview explanation
A CSV displays six source columns instead of five. Where would you look first?
Inspect the delimiter and quoted product field. Rice, Basmati must remain one field in this fixture. Also distinguish the source's five columns from the final six-column output after intentionally adding LineValue. The stage at which you count matters.
Can changing numeric 127 to Text restore 00127?
No. That later conversion preserves 127 as text. Return to the original field before numeric inference and keep it as Text there. Only use padding if a documented identifier rule independently establishes the required width; do not invent missing characters.
Does Power Query always interpret ambiguous dates as US dates?
No. Interpretation depends on the environment and conversion settings. Declare the source convention and use the corresponding locale. The fixture's 03/11/2026 means 3 November 2026; a different source could legitimately use a different convention.
Explain Table selection versus worksheet selection.
A named Table gives a defined data object with headings and boundaries. A worksheet may also contain titles, notes and unrelated summaries. Inspect both in Navigator and choose the intended records. A Table still needs a membership check when new rows are added.
Why keep both ORD-502 records during the import lab?
Their city, quantity and amount differ. Import verification should preserve the supplied records and flag the conflict. Deleting one based only on the identifier chooses a business rule that the fixture has not justified. Nine rows can have two different totals depending on the excluded record.
Does the first CSV lab finish with five output fields?
No. It starts with five source fields and deliberately adds LineValue, giving six output fields. Initially there are three records, seven units and 240; after the new saved source line, four records contain nine units and 320. Count headings and records separately.
The source changed but the report did not. Name a careful check.
Confirm that the edit was saved in the exact file referenced by the query, then check refresh completion and the destination table being viewed. For a workbook source, also verify the selected named Table. A similarly named file or output can make a correct refresh appear ineffective.
Give a useful short interview answer about importing files.
I identify the required source and record grain, choose the correct workbook object or text parsing settings, preserve identifiers, and assign types with the source's date and number conventions. I load the result, compare independent controls, and test a saved source change through refresh.
Object
Select the intended table, not merely the intended file.
Characters
Use encoding that matches how the text file was saved.
Fields
Check separators and quoted values against the expected column count.
Meaning
Protect IDs and interpret dates before trusting calculations.
Refresh
Save the source, refresh the query and inspect its destination.
Evidence
Keep counts, totals, named records and unresolved conflicts visible.