MSBA-132 · Lesson 4 of 12 · 22 min

Getting and shaping data

▶ Video coming soon A video version of this lesson is on the way.

Kwabena's first report would combine three sources. The tutoring sessions lived in Dataverse. The list of course sections and enrolment counts came from the student information system, a SQL Server database on a campus server. And the Student Success office kept a small Excel workbook of tutor hourly rates that changed each term. Bringing those together cleanly is the job of Power Query, the data preparation engine built into Power BI Desktop, the Power BI service, Excel, dataflows and many other Microsoft products. Analysts often say that most of the work in a good report happens before the first visual is drawn, and this lesson shows why.

Connecting with Get data

In Power BI Desktop, Get data opens a list of several hundred connectors, grouped into files, databases, Microsoft Fabric, Power Platform, Azure, online services and other sources. Each connector knows how to talk to one kind of source and what credentials it needs. Kwabena used three:

  • The Dataverse connector, signing in with his Lumenvale work account. Because Dataverse applies security roles, he sees only the tables and rows his own role allows, which is a useful protection: a report author cannot accidentally load data he is not entitled to.
  • The SQL Server connector, giving the server name and database name of the student information system, and signing in with a read-only database account that the database team created for reporting.
  • The Excel workbook connector, pointing at the tutor rates workbook stored in a SharePoint document library rather than on his laptop, so that the service could refresh it later without depending on his computer being switched on.

After choosing a connector and signing in, the Navigator window lists the tables, views or sheets available. You tick the ones you need and then choose either Load, which brings the data straight into the model, or Transform data, which opens the Power Query Editor first. Experienced authors almost always choose Transform data, because raw data is rarely ready to use as it arrives.

Storage modes: Import, DirectQuery and Direct Lake

For each table, Power BI must decide whether to copy the data into the semantic model or to ask the source for it every time a visual needs it. That choice is the table's storage mode.

Three boxes: Import, a copy stored in the model with the fastest visuals but needing scheduled refresh; DirectQuery, which queries the source each time a visual loads and is always current but slower; Direct Lake, which reads Delta tables in OneLake directly and needs Fabric capacity.
Storage modes decide where a table's data lives when a report runs.

Import copies the data into the model, where it is compressed in memory. Visuals respond very quickly and every Power BI feature works, but the data is only as fresh as the last refresh, and the model must fit within size limits: 1 GB per model with Pro, larger with PPU or capacity. Import is the right default for most small and medium datasets, including all three of Kwabena's sources.

DirectQuery leaves the data in the source. Each time someone opens a page or clicks a slicer, Power BI sends a query to the source and draws the result. Data is always current and there is no size limit in the model, but visuals are only as fast as the source can answer, the source carries the query load, and some transformations and DAX functions are restricted. DirectQuery suits very large tables or situations where minutes-old data matters.

Direct Lake is a newer mode available on Microsoft Fabric capacity. It reads data stored as Delta tables in OneLake, the Fabric data lake, directly into memory without a separate import refresh, combining much of Import's speed with near-current data. It requires the data to be in a Fabric lakehouse or warehouse first, so it belongs with the Fabric material in later courses.

Two related terms complete the picture. A live connection connects a new report to a semantic model that is already published, without creating a new model at all; this is how one shared model serves many reports. A composite model mixes storage modes, for example importing small reference tables while keeping a huge transaction table in DirectQuery.

The Power Query Editor

The Power Query Editor shows a preview of each query's data and records every change you make as an applied step in the Query Settings pane. The steps are not applied to the source; they are a recipe that Power Query replays, in order, every time the data is loaded or refreshed. That is the key idea of Power Query: you clean the data once, by example, and the cleaning repeats automatically forever after.

A vertical list of seven applied steps: Source registrations.xlsx, Promoted headers, Changed type, Removed other columns, Trimmed text in Program, Filtered rows where Status is not Cancelled, Merged with Price List. A note says each step is a line of M code that the editor writes for you.
Applied steps are a recipe Power Query replays on every refresh.

Behind the scenes, each step is written in M, Power Query's formula language. You rarely need to type M, because the ribbon buttons write it for you, but it helps to recognize it. The Advanced Editor shows the whole query.

The M code Power Query wrote for the tutor rates query. Each named line is one applied step.
let
    Source = Excel.Workbook(Web.Contents("https://lumenvale.sharepoint.com/sites/studentsuccess/Shared Documents/tutor_rates.xlsx"), null, true),
    Rates = Source{[Item = "Rates", Kind = "Sheet"]}[Data],
    Promoted = Table.PromoteHeaders(Rates, [PromoteAllScalars = true]),
    Typed = Table.TransformColumnTypes(Promoted, {{"Tutor", type text}, {"Term", type text}, {"Hourly rate", Currency.Type}}),
    Trimmed = Table.TransformColumns(Typed, {{"Tutor", Text.Trim, type text}})
in
    Trimmed

Steps can be renamed, reordered, edited by clicking the gear icon beside them, or deleted. Selecting an earlier step shows the data as it looked at that point, which makes Power Query easy to debug: click down the list until the data first looks wrong, and the step that broke it is the one you just selected.

Profiling the data

Before transforming anything, look at what arrived. The View tab of the Power Query Editor turns on three profiling aids that appear above each column:

  • Column quality shows the share of values that are valid, errors or empty.
  • Column distribution shows how many distinct and unique values the column has, with a small histogram.
  • Column profile shows detailed statistics and a value distribution for the selected column.

By default profiling looks only at the first 1,000 rows; the status bar lets you switch to profiling the entire dataset, which is slower but catches problems hiding further down. Kwabena's profile of the enrolment table showed that the Campus column had seven distinct values for three campuses, because some rows used codes and others used names and a few had trailing spaces. Profiling found in thirty seconds what would otherwise have surfaced weeks later as a strange bar on a chart.

Common transformations

Most cleaning uses a small set of transformations, all available from the Home, Transform and Add Column tabs:

TransformationWhat it doesLumenvale example
Remove columns or Choose columnsKeeps only the columns you needDrop 40 unused columns from the student system
Change typeSets each column's data typeMake Start a date and time, Minutes a whole number
Replace valuesSwaps one value for anotherReplace campus codes with campus names
Trim and CleanRemoves extra spaces and non-printing charactersFix "Lakeshore " with a trailing space
Split columnBreaks one column into several by a delimiter or positionSplit "BIOL-1105-02" into subject, course and section
Filter rowsKeeps rows that meet a conditionExclude cancelled sessions
Remove duplicatesKeeps one row per unique valueOne row per course section
Group bySummarizes rowsTotal minutes by tutor and term
Add column from examplesBuilds a column from examples you typeCreate a Term label from a date
Conditional columnAdds a column with if-then logicLabel sessions as short, standard or long

Order matters for speed as well as correctness. Removing columns and filtering rows early means every later step processes less data. Setting data types early means later steps, such as filters on dates, behave as expected.

Combining queries: merge and append

Data from different sources often needs to be combined, and Power Query offers two operations that are easy to confuse.

Append stacks tables on top of one another, adding rows. It suits tables with the same columns, such as three campus files with identical layouts, or this term's sessions plus last term's archive. Merge joins tables side by side on a matching column, adding columns. It suits looking up extra information, such as adding each tutor's hourly rate from the rates workbook to each session.

A merge asks for a join kind. The default, left outer, keeps every row of the first table and brings in matching rows from the second, leaving empty values where nothing matches. Inner keeps only rows that match in both. Left anti keeps rows of the first table that have no match, which is a quick way to find problems. Kwabena ran a left anti merge between sessions and rates and found four tutors with no rate for the current term, which the Student Success office then added.

Worked problem

Merge or append?

For each situation, decide whether Kwabena needs a merge or an append: (a) combining the fall and winter tutoring exports, which have identical columns; (b) adding each course section's enrolment count to the session table; (c) finding sessions whose course section does not exist in the student system.

Show solution
  1. (a) Same columns, more rows wanted: append.
  2. (b) Extra column looked up by a matching key (section code): merge, left outer.
  3. (c) Rows in sessions with no match in sections: merge with the left anti join kind.

Answer: Append, merge (left outer) and merge (left anti).

Unpivoting

Spreadsheets designed for people often spread one kind of value across many columns, such as a column for each month. Power BI works best when each kind of value is in one column, so the Unpivot columns transformation turns those month columns into two columns, Month and Value, with one row per month. The Student Success office's budget sheet had a column for each of twelve months; after unpivoting it became a tidy three-column table that could be filtered and charted by month. The opposite operation, Pivot column, turns row values into columns and is used less often.

Query folding

When the source is a database, Power Query tries to translate applied steps into the source's own query language, so that the database does the filtering and grouping and sends back only the result. This is called query folding. A step such as Filter rows usually folds; some steps, such as certain custom columns, break folding, and every step after them runs in Power Query instead. Right-clicking a step and choosing View Native Query shows whether it folded. For Kwabena's small tables folding hardly mattered, but on a table of millions of rows it is the difference between a refresh of seconds and one of an hour. MSBA-260 covers folding in depth.

Loading the results

When the queries look right, Close and Apply loads them into the model. Queries that only feed other queries, such as a staging table used in a merge, can have Enable load turned off so that they do not appear as tables in the model. Kwabena turned off load for the raw rates query and kept only the merged, cleaned session table and the sections table. Each later refresh repeats every applied step against the current data.

One change in the service is worth knowing. The old route of uploading an Excel or CSV file directly to the Power BI service to create a semantic model has been retired during 2026; Microsoft's guidance is to build the model in Power BI Desktop or with the newer web experiences and keep source files in OneDrive or SharePoint so that they can refresh.

Dataflows and reusing preparation

Kwabena soon noticed that he and the finance office were both cleaning the same course section table from the student information system: trimming campus names, splitting section codes and removing withdrawn sections. Each did it in their own Power BI file, slightly differently. Power Query offers a way to do that work once. A dataflow is a set of Power Query queries that runs in the service, stores its cleaned output, and can be used as a source by any number of semantic models. Dataflows are created in a workspace with the same Power Query editor, online, and refreshed on their own schedule.

In Microsoft Fabric, the current generation is Dataflow Gen2, which can also write its output to destinations such as a Fabric lakehouse or warehouse. Earlier dataflows, now called Dataflow Gen1, still work in Pro and Premium workspaces. Either way, the idea is the same: shared preparation happens once, in one place, and every report that uses it gets the same clean table. Lumenvale moved the course section cleaning into a dataflow that both Kwabena's model and the finance model now use.

Worked problem

Planning a set of applied steps

The student system export has 52 columns, of which Kwabena needs 6. Campus appears as codes (DTN, LKS, RDG) and names. Section codes look like BIOL-1105-02. Withdrawn sections have Status = W. Plan the applied steps in a sensible order.

Show solution
  1. Connect to the table and choose Transform data.
  2. Choose columns: keep the 6 needed columns, dropping 46.
  3. Filter rows: remove sections with Status = W.
  4. Change types: section start date as date, enrolment as whole number.
  5. Replace values: map campus codes to campus names, then trim the column.
  6. Split column by delimiter on the hyphen: subject, course number and section number.
  7. Rename the new columns and Close and Apply.

Answer: Reduce columns and rows first, set types, then clean and split. Early reduction keeps later steps fast and, against a database, helps them fold.

A final habit: name your queries and steps. Power Query names steps automatically, such as Changed Type1 and Filtered Rows2, which tells the next person nothing. Renaming them to say why, such as Remove withdrawn sections, turns the Applied Steps pane into documentation.

Common mistakes

  • MistakeChoosing Load straight from the Navigator and cleaning the data later with DAX.

    InsteadChoose Transform data and clean in Power Query, where steps repeat on every refresh.

  • MistakeProfiling only the first 1,000 rows and assuming the column is clean.

    InsteadSwitch profiling to the entire dataset when checking a column you depend on.

  • MistakeUsing append when the goal is to look up extra columns.

    InsteadAppend adds rows from tables with the same columns; merge adds columns from a matching table.

  • MistakePointing a query at a file on your own laptop.

    InsteadStore source files in SharePoint or OneDrive so the service can refresh them without your computer.

Summary and key terms

  • Get data offers hundreds of connectors; the Navigator lets you load tables or open the Power Query Editor.
  • Import copies data into the model, DirectQuery queries the source live, Direct Lake reads OneLake on Fabric, and a live connection reuses a published model.
  • Applied steps are a recipe, written in M, that Power Query replays on every refresh.
  • Column quality, distribution and profile reveal problems before you transform.
  • Append stacks rows; merge joins columns with a join kind such as left outer, inner or left anti.
  • Unpivot turns columns of values into rows; query folding pushes work back to the source.
Power Query
The data preparation engine used to connect to and transform data.
Applied step
One recorded transformation in a query, replayed on each refresh.
M
The formula language behind Power Query steps.
Storage mode
Whether a table is imported, queried directly or read through Direct Lake.
Merge
Joining two queries side by side on matching columns.
Append
Stacking queries with the same columns to add rows.
Query folding
Translating Power Query steps into the source's own query language.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Which storage mode gives the fastest visuals but needs scheduled refresh?

    Show answer

    Import.

  2. Which join kind finds rows in the first table with no match in the second?

    Show answer

    Left anti.

  3. Why should a source workbook live in SharePoint rather than on a laptop?

    Show answer

    So the Power BI service can refresh it in the cloud without depending on the laptop being on.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz