🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Data Science & Analytics › Dashboards: Design, Build, and Deploy with Power BI and Tableau › Lesson 2
TEC-DATA85-07 · Lesson 2 · 12 clock hours · lab

Connecting and Shaping Data in Power BI Desktop

Objective. Students import data from a CSV file, an Excel workbook, and a SQL Server or PostgreSQL database into Power BI Desktop and apply Power Query transformations to produce a clean, typed table.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

Connecting and Shaping Data in Power BI Desktop

Why Data Preparation Matters

Before any chart or dashboard is built, the underlying data must be accurate, consistently typed, and free of structural problems. Power BI Desktop provides two tightly connected tools for this work: the Get Data dialog, which establishes connections to sources, and the Power Query Editor, which transforms raw data into analysis-ready tables. Errors introduced here—a column typed as text instead of a number, a stray duplicate row, a mismatched date format—will silently corrupt every visual downstream. Taking time to clean and verify data in Power Query is therefore a foundational professional habit, not an optional step.

Connecting to Data Sources

Power BI Desktop can connect to hundreds of source types. For this lab you will use three:

Every connection produces a query in Power Query Editor. Think of each query as a recipe: it records every transformation step and replays them in order whenever the data is refreshed.

The Power Query Editor Interface

When you click Transform Data, Power Query Editor opens. Key areas:

Essential Transformations

Promote headers. When a CSV loads with generic column names (Column1, Column2 …), use Home → Use First Row as Headers. This adds a PromotedHeaders step that shifts row 1 into the column-name row.

Change data types. Every column must carry the correct type: Whole Number, Decimal Number, Date, Text, etc. Power Query auto-detects types on import, but auto-detection is not always correct—especially for columns that contain leading zeros (zip codes, permit IDs) that should remain Text. Click the type icon in the column header and select the correct type. Changing a type adds a Changed Type step.

Remove duplicates. Select one or more key columns, right-click, and choose Remove Duplicates. This is row-level deduplication based on the selected columns. Always confirm the row count before and after; the status bar at the bottom of the editor shows the current row count.

Merge queries. Merging is Power Query's equivalent of a SQL JOIN. Use Home → Merge Queries, select the two queries, pick the matching column(s), and choose the join kind (Left Outer is the most common for building fact tables). After merging, expand the nested table column to surface the columns you need.

Null Values and Type Mismatches

A null in Power Query represents an absent value. Type mismatches occur when a column typed as, say, Whole Number contains a null or a text string such as "N/A". Power Query will flag these with an error indicator on the column header. Fix strategies include:

The M Formula Language and the Advanced Editor

Every Applied Step is expressed in M, Power Query's functional formula language. You do not need to memorize M syntax, but you do need to be able to read and make small edits. The Advanced Editor (Home → Advanced Editor) shows the full M script for a query as a single function. A typical row-filter step looks like:

```

= Table.SelectRows(#"Changed Type", each [Budget] > 50000)

```

This keeps only rows where the Budget column exceeds 50,000. When you modify a step in the Advanced Editor, Power Query validates syntax on close; a red underline means a syntax error. Always verify the resulting row count in the status bar against an expected value before closing the editor.

File Path and Source Errors

A broken file path is one of the most common errors in shared .pbix files. If a CSV was connected from a personal desktop path (C:\Users\YourName\…) and the file is moved or the .pbix is opened on another machine, Power Query will show a DataSource.Error. Fix it by selecting the Source step in Applied Steps and editing the path in the formula bar or via Home → Data Source Settings.

Safety and Professional Practice

Data safety in analytics means protecting data integrity and, where applicable, personally identifiable information (PII). During lab:

Verifying Your Work

Before submitting, check:

1. Zero error indicators on column headers and in the Queries pane.

2. All columns carry the correct data type icon.

3. The merged fact table row count matches the instructor's answer key exactly.

4. Applied Steps are named clearly and contain no unused or duplicate steps.

Key terms9

Power Query EditorThe data transformation environment inside Power BI Desktop where connections are established and cleaning steps are recorded as a sequential M script.
Applied StepsThe ordered list of transformation actions recorded for a query in Power Query Editor; each step can be inspected, renamed, or deleted.
M formula languageThe functional scripting language used internally by Power Query to express every transformation step; visible in the formula bar and the Advanced Editor.
Merge QueriesA Power Query operation that combines two queries on a matching column, equivalent to a SQL JOIN, to produce a single wider table.
Data typeThe classification assigned to a column—such as Whole Number, Decimal Number, Date, or Text—that controls how Power BI stores and calculates with that column's values.
NullA special value in Power Query representing a missing or absent entry; must be handled explicitly to avoid type mismatch errors downstream.
DataSource.ErrorA Power Query error that occurs when the connection to a source cannot be established, most commonly due to a broken file path or incorrect server credentials.
Promote HeadersA Power Query transformation that elevates the first data row to become column names, correcting files that load with generic column labels.
Advanced EditorA dialog in Power Query Editor that displays and allows direct editing of the full M script for a query, enabling transformations not available through the graphical interface.
In class: Guided lab: connect to a provided CSV of city permit data and a PostgreSQL database of budget records; use Power Query Editor to remove duplicate rows, promote headers, change data types, and merge queries into one fact table. · Error-hunting exercise: instructor distributes a deliberately broken .pbix file with four Power Query errors (null type mismatch, broken file path, wrong delimiter, date format error); students identify and fix each error and document the fix in a lab log. · M-formula exploration: students modify one automatically generated M step by hand in the Advanced Editor to filter rows where a numeric column exceeds a threshold, then verify the result row count matches an expected value.
Materials: Power BI Desktop (free, current version), provided CSV and Excel sample datasets, access to class PostgreSQL instance (from Course 4), Microsoft Power Query documentation (docs.microsoft.com), lab log template
Check: Instructor reviews each student's .pbix file; pass requires correct data types on all columns, zero errors in Power Query pane, and a merged table matching the instructor's answer key row count (±0 rows). PL-300 mapping: Prepare the data domain.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

Prepare the data
1. When you open a CSV file in Power BI Desktop and all data appears in a single column, what is the most likely cause?
Prepare the data
2. A colleague opens your .pbix file on a different computer and sees a DataSource.Error on the CSV query. Which action will most directly fix the problem?
Prepare the data
3. You want to keep only rows where the column [PermitFee] is greater than 1000. Which M expression correctly filters the table named #"Removed Duplicates"?
Prepare the data
4. After promoting headers in Power Query, you notice the [ZipCode] column was automatically typed as Whole Number, which strips leading zeros from codes like 02134. What should you do?
Prepare the data
5. You merge two queries using a Left Outer join on a shared key column. After expanding the joined table, the row count of the result is higher than the left table's original row count. What is the most likely explanation?
Prepare the data
6. Where in Power BI Desktop can you edit the stored credentials for a PostgreSQL database without rebuilding the query?
Prepare the data
7. A column typed as Date contains several rows with the text value "TBD". When the data is refreshed, Power Query marks those rows with an error indicator. Which TWO actions could resolve the error while retaining as much data as possible? (Choose the best single answer from the options below.)
Prepare the data
8. Which Power Query action is equivalent to a SQL SELECT DISTINCT on a primary-key column?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.