Get started
with Power BI
Dr Doan Xuan Huy Minh
There are three primary
components to Power BI
Power BI Desktop
(desktop application)
Power BI service
(online platform)
Power BI Mobile
(cross-platform
mobile app)
Workflow
Create
Connect to data Transform and
visualizations and
with Power BI model data with
reports with Power
Desktop. Power BI Desktop.
BI Desktop.
Distribute and
manage reports in Publish report to
the Power BI Power BI service.
service.
Create a semantic model and
then use visuals to build a report
Learning objectives
• Resolve inconsistencies, unexpected or null values, and data quality
issues.
• Apply user-friendly value replacements.
• Profile data so you can learn more about a specific column before
using it.
• Evaluate and transform column data types.
• Apply data shape transformations to table structures.
• Combine queries.
• Apply user-friendly naming conventions to columns and queries.
• Edit M code in the Advanced Editor.
Scenerio
• The data resides in
several different
databases and files.
• These data repositories
are different from each
other, some are in
Microsoft SQL Server,
some are in Microsoft
Excel, but all the data is
related.
1. Get data from flat files
Files might exist in one of
the following locations
• Local: import data that
would not change
• Onedrive business
• Sharepoint / Teamsite
• Onedrive personal: must
Keep signed in
Select data to import
• Select the check box(es) of the
table(s) that you want to bring
in to Power BI.
• This selection activates the
Load and Transform Data
buttons
Change the source file
• Power Query provides
many ways for you to
accomplish this task,
so that you can make
this type of change
when needed.
• Data source settings
• Query settings
• Advanced Editor
Change the
source file
For example, try changing the
data source file path in the
data source settings.
Select Data source settings in
Power Query. In the Data
source settings window,
select your file and then
select Change Source.
Update the File path or use
the Browse option to locate
your file, select OK, and then
select Close.
2. Get data from relational data
sources
• Scenario
• The Sales team has
requested that you
connect to the
organization's on-
premises SQL Server
database and get the
sales data into Power
BI Desktop so you can
build sales reports.
Connect to data in a relational
database
• The two options in data
connectivity mode are:
Import (selected by
default, recommended)
and DirectQuery.
• After you've added your
server and database
names, you'll be
prompted to sign in with
a username and
password. You'll have
three sign-in options.
Select data to
import
Select the check box(es) of the
table(s) that you want to bring in
to Power BI Desktop, and then
select either
the Load or Transform
Data option.
• Load - Automatically load
your data into a Power BI
model in its current state.
• Transform Data - Open your
data in Microsoft Power
Query, where you can
perform actions such as
deleting unnecessary rows or
columns, grouping your data,
removing errors, and many
other data quality tasks.
Import data by
writing an SQL
query
To write your SQL query, on
the SQL Server
database window, enter your
server and database names,
and then select the arrow next
to Advanced options to
expand this section and view
your options.
In the SQL statement box,
write your query statement,
and then select OK.
In this example, you'll use
the Select SQL statement to
load the ID, NAME and
SALESAMOUNT
columns from the SALES
table.
Change data
source settings
(1)
After you create a data source
connection and load data into
Power BI Desktop, you can
return and change your
connection settings at any
time.
This action is often required
due to a security policy within
the organization, for example,
when the password needs to be
updated every 90 days. You can
change the data source, edit
permissions or clear
permissions.
Change data
source settings
(2)
You can also change your data
source settings from within
Power Query. Select the table,
and then select the Data
source settings option on
the Home ribbon.
Alternatively, you can go to
the Query Settings panel on
the right side of the screen
and select the settings icon
next to Source (or double
Select Source). In the window
that displays, update the
server and database details,
and then select OK.
Write an SQL statement
Example
• In the SQL Server database window, select Advanced options.
• Type the SQL query into the SQL statement box and then select OK.
• When the connection is made, the data is shown in the preview window.
• Select Edit to open the data in Power Query Editor.
3. Get data from a NoSQL
database
• Connect to a NoSQL
database (Azure
Cosmos DB)
• In this scenario, you'll use
the Get data feature in
Power BI Desktop.
• Select the More... option
to locate and connect to
the type of database that
you use.
• In this example, you'll
select the Azure category,
select Azure Cosmos
DB, and then
select Connect.
3. Get data from a NoSQL
database
• Import a JSON file
• If you're working with data stored
in JSON format, it's often
necessary to extract and
normalize the data first. This is
because JSON data is often stored
in a nested or unstructured
format, which makes it difficult to
analyze or report on directly.
• In this example, the data must be
extracted and normalized before
you can report on them, so you
need to transform the data before
loading it into Power BI Desktop.
Select the Edit button
to open the records in
Power Query.
Import a JSON
file (2)
In Power Query, select
the Expander button to the
right side of
the Column1 header, which
displays the context menu
with a list of fields.
Select the fields that you want
to load into Power BI Desktop,
clear the Use original column
name as prefix checkbox, and
then select OK.
Review the selected data to
ensure that you're satisfied
with it, then select Close &
Apply to load the data into
Power BI Desktop.
4. Get data from online services
• Get data → Online Services
category.
• In this example, you select
SharePoint Online List.
• After you've selected Connect,
you'll be asked for your
SharePoint URL.
• You can copy the URL from
your SharePoint site and paste
it into the connection window
in Power BI.
• Don't enter your full URL file
path;
• Only need your site URL
• Later, you can select the
specific list that you want to
load
Select a storage
mode
You can access storage modes
by switching to
the Model view, selecting a
data table, and in the resulting
Properties pane, selecting
which mode that you want to
use from the Storage
mode drop-down list, as
shown in the following visual.
Select a storage mode
• Import mode (default)
• Create a local Power BI
copy of your semantic
models from your data
source
• DirectQuery mode
• Using this model ensures
that you're always viewing
the most up-to-date data,
and that all security
requirements are satisfied
• Dual (Composite mode)
• Identify some data to be
directly imported and other
data that must be queried
5. Get data from Azure Analysis
Services
• Getting data from Azure Analysis Services
server is similar to getting data from SQL
Server, in that you can:
• Authenticate to the server.
• Pick the model you want to use.
• Select which tables you need.
6. Fix performance issues
• The performance in
Power Query depends
on the performance at
the data source level.
• Power Query takes
advantage of good
performance at the
data source through a
technique called
Query Folding.
Fix performance
issues
If the View Native
Query option isn't available (not
displayed in bold type), then
query folding isn't possible for
this step, and you'll have to work
backward in the Applied
Steps area until you reach the
step in which View Native
Query is available (displays in
bold type).
View Native Queries aren't
possible for the following
transformations:
Adding an index column
Merging and appending columns
of different tables with two
different sources
Changing the data type of a
column
Query diagnostics
Another tool that you can use to study query performance is query diagnostics. You
can determine what bottlenecks may exist while loading and transforming your data,
refreshing your data in Power Query, running SQL statements in Query Editor, and so
on.
• In Power Query Editor, go to Home → Tools.
• When you're ready to begin transforming your data or making other edits in
Power Query Editor, select Start Diagnostics in the Session Diagnostics section.
When you're finished, make sure that you select Stop Diagnostics.
1. Get Data in Power BI
Desktop
Preparation: Install SQL Server / SMSS
Exercise 1: Get started with Power
BI Desktop
• Download the zip folder: [Link]
• Extract the folder
i.e. D:\Allfiles\01-prepare-data
• Look for and open 01-Starter-Sales
[Link] file.
PowerBI: Get data from SQL Server
• Home → Data → SQL
Server
• In the SQL Server
Database window
• Server: localhost
• Database blank
• Data Connection:
Import
Test
Select
the DimEmployee table,
and notice the preview of
the table data.
Import data
To import the table data, select
the checkbox next to the
following tables:
✓ DimEmployee
✓ DimEmployeeSalesTerritory
✓ DimProduct
✓ DimReseller
✓ DimSalesTerritory
✓ FactResellerSales
Complete this task by selecting
Transform Data, which will
open Power Query Editor
Select the first query
DimEmployee.
The DimEmployee table in the
SQL Server database stores
one row for each employee.
A subset of the rows from this
table represents the
salespeople, which will be
relevant to the model you’ll
develop.
At the bottom left corner of the
status bar, some table statistics
are provided—the table has 33
columns, and 296 rows.
Notice that the last five
columns contain Table or
Value links.
Assess column quality
View → Data Preview
→ Column Quality
→ Column Distribution
Which column has
high percentage of
empty (null) data?
Select the DimReseller query
View → Data Preview
→ Column Profile
Select the BusinessType
column header
How many rows have
this (mispelled)
value?
Select the FactResellerSales
query.
• Review the column quality for
the TotalProductCost column,
What’s wrong with it?
Load CSV
• Home → New Query
→ New source →
Text/CSV
• Navigate to the
01-prepare-data >
ResellerSalesTargets
.csv file
• Preview data
• OK
Check data
• What does this table contain?
• Any empty value?
• What does a hyphen character (-) stand for?
• Review the icons in each column header →
what are they represented?
Practice
• Create a query to load
the [Link]
file.
• What is in the file?
Meaning?
Recap: What we have done
• Connect to SQL server
• Load data
• View data
• Identify missing / incorrect data
2. Load Transformed
Data in Power BI
Desktop
1. Practice: Salesperson query
• Home → Queries /
Transform Data
• Rename
• DimEmployee →
Salesperson
• Filter
• Salepersonflag →
TRUE (filter)
Note: If you receive a warning message asking to specify how to connect, select Edit
Credentials, connect using current credentials, and select OK to use an unencrypted
connection.
Practice with Manage Column
• To include columns, check the
following six columns:
• EmployeeKey
• EmployeeNationalIDAlternate
Key
• FirstName
• LastName
• Title
• EmailAddress
Practice with Merge Column
• Right-click either of
the select column
headers, and then in
the context menu,
select Merge
Columns.
Self-practice
• Rename the EmployeeNationalIDAlternateKey
→ EmployeeID
• Rename the EmailAddress column to UPN
• UPN - User Principal Name
• Verify that the query has 5 columns and 18 rows.
2. SalespersonRegion query
• Rename the query
DimEmployeeSalesT
erritory →
SalespersonRegion
• Remove the last 2
columns
• Verify that the query
has 2 columns and 39
rows.
3. Configure the Product query
• Rename the query • Choose Column →
DimProduct to remove all columns,
Product except the following:
• ProductKey
• EnglishProductName
• Filter • StandardCost
FinishedGoodsFlag = • Color
TRUE • DimProductSubcategory
Transformation: join tables
• Notice:
DimProductSubcategory
column represents a related
table (it contains Value links).
• Expand, then Select
EnglishProductSubcategoryN
ame and
DimProductCategory,
• Uncheck the Use Original
Column Name as Prefix
checkbox before selecting OK.
• What is the result?
Self-practice: join the
Dimproduct
• Expand DimProductCategory column, and
then introduce only the
EnglishProductCategoryName column
Rename the following four
columns:
• EnglishProductName → Product
• StandardCost → Standard Cost (include a space)
• EnglishProductSubcategoryName → Subcategory
• EnglishProductCategoryName → Category
Status bar: Verify that the query has 6 columns and 397 rows
3. Configure the Reseller query
• Rename DimReseller query to Reseller
• Remove all columns, except the following:
1. ResellerKey
2. BusinessType
3. ResellerName
4. DimGeography
• Expand the DimGeography column, to include
only the following three columns:
1. City
2. StateProvinceName
3. EnglishCountryRegionName
Replace misspelled values
• Right-click the
Business Type
column header, and
then select Replace
Values.
Rename the following four
columns:
• BusinessType → Business Type (include a space)
• ResellerName → Reseller
• StateProvinceName → State-Province
• EnglishCountryRegionName → Country-Region
Status bar: Verify that the query has 6 columns and 701 rows
4. Configure the Region query
• Rename DimSalesTerritory → Region.
• Filter: SalesTerritoryAlternateKey to remove the
value 0 (→ Corporate HQ).
• Remove all columns, except the following:
• SalesTerritoryKey
• SalesTerritoryRegion
• SalesTerritoryCountry
• SalesTerritoryGroup
Rename the following three
columns:
• SalesTerritoryRegion → Region
• SalesTerritoryCountry → Country
• SalesTerritoryGroup → Group
• Status: verify that the query has 4 columns and
10 rows.
4. Configure the Sales query
• Rename • Remove all columns,
FactResellerSales except the following:
query → Sales. • SalesOrderNumber
• OrderDate
• ProductKey
• ResellerKey
• EmployeeKey
• SalesTerritoryKey
• OrderQuantity
• UnitPrice
• TotalProductCost
• SalesAmount
• DimProduct
• Transform DimProduct → StandardCost
• Add Column → General group → Custom Column
• New column name: Cost
• Formula:
if [TotalProductCost] = null
then [OrderQuantity] * [StandardCost]
else [TotalProductCost]
Clean up
• Remove the following • Rename the following
two columns: three columns:
• TotalProductCost • OrderQuantity →
• StandardCost Quantity
• UnitPrice → Unit Price
(include a space)
• SalesAmount to Sales
Practice: Format data type
• Whole number
• Quantity
• Fixed Decimal Number
• Unit Price
• Sales
• Cost
5. Configure the Targets query
• Rename ResellerSalesTargets query → Targets
Unpivot table
• First multi-select the Year
and EmployeeID column
headers.
• Right-click either of the
select column headers, and
then in the context menu,
select Unpivot Other
Columns.
• Notice that the column
names now appear in the
Attribute column, and the
values appear in the Value
column.
• Apply a filter to the Value
column to remove hyphen (-)
values.
Rename (1)
• Rename the following two columns:
• Attribute → MonthNumber (there’s no space)
• Value → Target
Format data
• Right-click the
MonthNumber
column header, and
then select Replace
Values.
• Value To Find: M
• Leave the Replace
with empty.
• Change data type to
Whole Number
Practice: Column from Examples
• Add Column → Column From Examples
• Enter 1st row: 1/7/2017 and look at the predicted
rows below
• Look at the formula
• Is it OK?
Rename / Remove columns
• Rename Merged column → TargetMonth
• Remove the following columns:
• Year
• MonthNumber
Modify data types
• Modify the following column data types:
• Target as fixed decimal number
• TargetMonth as date
Assumption: Sale tell you that
target should be x1,000
• Transform → Number → x1,000
Status: verify that the query has 3 columns and 809 rows
6. Configure the ColorFormats
query
• Select the ColorFormats query and notice that
the first row contains the column names.
• Home → Transform group → Use First Row as
Headers.
Status: verify that the query has 3 columns and 10 rows
7. Update the Product query
• In this task, you’ll update the
Product query by merging the
ColorFormats query.
• Select the Product query.
• To merge the ColorFormats query:
• Home → Combine → Merge Queries
Transform / Merge table
• In the Merge window, in
the Product query grid,
select the Color column
header.
• In the dropdown list
beneath, select the
ColorFormats query.
• In the ColorFormats
query grid, select the
Color column header
• Join Kind – default Left
Outer
Privacy levels
• Privacy levels can be
configured for data source to
determine whether data can
be shared between sources.
• Setting each data source as
Organizational allows them
to share data, if necessary.
• Private data sources can
never be shared with other
data sources.
• It doesn’t mean that Private
data can’t be shared; it
means that the Power Query
engine can’t share data
between the sources.
Transform / Merge tables
• Expand
the ColorFormats column to
include the following two
columns:
• Background Color Format
• Font Color Format
• Status: verify that the query now has 8 columns and 397 rows.
8. Update the ColorFormats query
• In this task, you’ll update the ColorFormats to
disable its load.
• Select the ColorFormats query.
• In the Query Settings pane, select the All Properties
link.
• In the Query Properties window, uncheck the Enable
Load To Report checkbox.
Review final product
• Select Close & Apply to load
• 8 queries, correctly named as the data to the model, and
close Power Query Editor
follows: window.
1. Salesperson • You can now see the canvas in
Power BI Desktop.
2. SalespersonRegion • In the Data pane, notice the 7
tables loaded to the data model.
3. Product
4. Reseller
5. Region
6. Sales
7. Targets
8. ColorFormats (which
won’t load to the data
model)
Design a Data Model
in Power BI
Objectives
• Create model relationships
• Configure table and column properties
• Create hierarchies
1. Create model relationships
• Report view icon on the left.
• To see all table fields, right-click in
the Data pane and select Expand
All.
• To create a table visual, check the
Category field in the Product table
within the Data pane.
• To add another column, check the
Sales field in the Data pane.
• The table visual displays four product
categories, each with the same sales
value, including the total.
Problem?
Create Data Model
• Select the Model view icon from
the left navigation pane, and
select Manage Relationships.
• In the Manage
Relationships window, notice that
no relationships are yet defined. To
create a relationship, select New
relationship.
• Configure the relationship
from Product table to Sales table.
Notice the following elements
were automatically configured:
Configure the relationship
from Product table to Sales table
• ProductKey columns in
each table are selected
• Cardinality type is One To
Many (1:*)
• Cross Filter Direction type
is Single.
• Make This Relationship
Active is checked
Review Category sale
Practice: Create additional
relationships
• From the Reseller table, drag the ResellerKey
column → the ResellerKey column of the Sales
table.
• Use the new technique to create the following two
model relationships:
• Region | SalesTerritoryKey to Sales | SalesTerritoryKey
• Salesperson | EmployeeKey to Sales | EmployeeKey
3. Configure the Product table
• Task: you’ll configure the Product table with a
hierarchy and display folder.
• In Model view → Data pane, if necessary, expand the
Product table to reveal all fields.
• To create a hierarchy: in the Data pane, right-click
the Category column, and then select Create
Hierarchy.
• Update the name to Products (right-click or
double-click to rename).
3. Configure the Product table
• Second level: Add or
Search for
Subcategory → Add
to Hierarchy.
• Third level: in the
Hierarchy dropdown
list, select Product.
• Apply Level Changes.
Organize columns into a display
folder
• In the Data pane, first select the Background
Color Format.
• While pressing the Ctrl key, select the Font
Color Format.
• In the Properties pane, in the Display Folder
box, enter Formatting.
3. Configure the Region table
• Task: configure the
Region table with a
hierarchy and updated
categories.
• In the Region table,
create a hierarchy named
Regions, with the
following three levels:
• Group
• Country
• Region
3. Configure the Region table
• Select the Country.
• In the Properties pane,
expand the Advanced
section (at the bottom of
the pane),
• in the Data Category
dropdown list, select
Country/Region.
Change data category
• Select the Country
column (not the Country
hierarchy level).
• In the Properties pane,
expand the Advanced
section (at the bottom of
the pane), and then in the
Data Category dropdown
list, select Country/Region.
4. Configure the Reseller table
• Task: you’ll configure the Reseller table to add a
hierarchy and update data categories.
• In the Reseller table, create a hierarchy named
Resellers, with the following two levels:
• Business Type
• Reseller
Practice
• Create a second hierarchy named Geography,
with the following four levels:
• Country-Region
• State-Province
• City
• Reseller
• Set the Data Category for the following columns
(not within the hierarchy):
• Country-Region to Country/Region
• State-Province to State or Province
• City to City
5. Configure the Sales table
• Task: you’ll configure the Sales table with
updated descriptions, formatting, and
summarization.
• In the Sales table, select the Cost column.
• In the Properties pane, in the Description box, enter:
Based on standard cost.
Configure the Sales table (2)
1. Select the Quantity column.
2. In the Properties pane, from inside
the Formatting section, slide the Thousands
Separator property to Yes.
3. Select the Unit Price column.
4. In the Properties pane, from inside
the Formatting section, set the Decimal
Places property to 2.
5. In the Advanced group (you may need to scroll
down to locate it), in the Summarize
By dropdown list, select Average.
6. Bulk update properties
• Task: you’ll update multiple
columns using single bulk
updates. You’ll use this
approach to hide columns, and
1. Region | SalesTerritoryKey
format column values. 2. Reseller | ResellerKey
• From the Model 3. Sales | EmployeeKey
view > Data pane, select 4.
5.
Sales | ProductKey
Sales | ResellerKey
the Product | 6. Sales | SalesOrderNumber
ProductKey column. 7. Sales | SalesTerritoryKey
8. Salesperson | EmployeeID
• While pressing the Ctrl key, 9. Salesperson | EmployeeKey
select the following 13 10. Salesperson | UPN
columns (spanning multiple 11. SalespersonRegion | EmployeeKey
tables) 12. SalespersonRegion | SalesTerritoryKey
13. Targets | EmployeeID
• In the Properties pane, slide
the Is Hidden property to Yes.
1. Multi-select the following three columns:
• Product | Standard Cost
• Sales | Cost
• Sales | Sales
2. In the Properties pane, from inside
the Formatting section, set the Decimal
Places property to 0 (zero).
7. Explore the model interface
• Task: you’ll switch to Report view, review the
data model interface, and configure the auto
date/time setting.
Steps
• Switch to Report view.
• In the Data pane, notice the following:
• Columns, hierarchies and their levels are fields,
which can be used to configure report visuals
• Only fields relevant to report authoring are
visible
• The SalespersonRegion table isn’t visible—
because all of its fields are hidden
• Spatial fields in the Region and Reseller table
are adorned with a spatial icon
• Fields adorned with the sigma symbol (Ʃ) will
summarize, by default
• A tooltip appears when hovering the cursor over
the Sales | Cost field
• Expand the Sales | OrderDate field, and
then notice that it reveals a Date Hierarchy.
The Targets | TargetMonth field delivers a
similar hierarchy.
Steps
• To turn off the Auto date/time setting, Navigate to
File > Options and Settings > Options.
• Under the Current File section, navigate to Data
Load > Time Intelligence, and uncheck Auto
Date/Time.
• In the Data pane, notice that the date hierarchies are
no longer available.
8. Create quick measures
• Task: you’ll create two quick measures to
calculate profit and profit margin.
• A quick measure creates the calculation formula for
you.
Steps
• In the Data pane, right-click
the Sales table, and then
select New Quick Measure.
• In the Quick Measures window,
in the Calculation dropdown
list, from inside the
Mathematical Operations
group, select Subtraction.
• In the Data pane of the Quick
Measures window, expand
the Sales table.
• Drag the Sales field into the Base
Value box.
• Drag the Cost field into the Value to
Subtract box, then select Add.
• In the Data pane, inside the Sales table,
notice that new measure.
• To rename the measure, right-click it,
select Rename, then rename to Profit.
Practice
• In the Sales table, add a second quick measure,
based on the following requirements:
• Use the Division mathematical operation
• Set the Numerator to the Sales | Profit field
• Set the Denominator to Sales | Sales field
• Rename the measure as Profit Margin
• Ensure the Profit Margin measure is selected, and
then on the Measure Tools contextual ribbon, set
the format to Percentage, with two decimal
places.
Test result
• To test the two measures,
first select the Table visual.
• In the Data pane, check the
two measures.
• Select and drag the right
guide to widen the table
visual.
• Verify that the measures
produce reasonable results
that are correctly formatted.
8. Create a many-to-many
relationship
• Task: you’ll create a • In Power BI Desktop,
many-to-many in Report view, in the
relationship between Data pane, check the
the Salesperson table follow two fields to
and the Sales table. create a new table
visual.
• Salesperson |
Salesperson
• Sales | Sales
• Switch to Model view,
then drag the
SalespersonRegion table
to position it between the
Region and Salesperson
tables.
• Use the drag-and-drop
technique to create the
following two model
relationships:
• Salesperson | EmployeeKey
to SalespersonRegion |
EmployeeKey
• Region | SalesTerritoryKey
to SalespersonRegion |
SalesTerritoryKey
• Switch to Report view,
and then notice that the
visual hasn’t updated—
the sales result for
Michael Blythe hasn’t
changed.
• Switch back to Model
view, and then follow
the relationship filter
directions (arrowhead)
from the Salesperson
table.
• To edit the relationship between the Region and
SalespersonRegion tables, double-click the
relationship.
• In the Edit Relationship window, in the Cross Filter
Direction dropdown list, select Both.
• Check the Apply Security Filter in Both Directions
checkbox, then select OK.
INSTALL SQL
SERVER 2022
[Link]
us/sql-server/sql-server-
downloads
Dowload and run installer
Developer Edition → Basic
Start SQL Server
• Run SQL Server
Configuration Manager
• Check Started / Disable?
• Properties → Service →
Start mode: Manual →
Apply
• Start service
Continue:
Download SSMS
Download SQL Server
Management Studio
(SSMS) | Microsoft Learn
CONFIG SSMS
• Run SQL Server
Management Studio 20,
• Check: Trust server
certification
• Connect.
Restore
Database
• Open SSMS and connect to
your SQL Server instance.
• Right-click Databases in
Object Explorer →
Restore Database... to
launch the Restore
Database wizard.
Restore
Database
• Select Device and then
select the ellipses (...) to
choose a device.
• Select Add and then choose
the .bak file
• Browse for
AdventureWorksDW2020.
bak
• [in
..\Allfiles\DatabaseBackup]
• Select OK to confirm your
database backup selection
and close the Select backup
devices window.
Restore
Database
• Check the Files tab to
confirm the Restore as
location and file names
match your intended location
and file names in the Restore
Database wizard.
• Select OK to restore your
database.
Back to practice
Scenario
You have loaded raw sales data
from two sources into a Power BI
model. Some of the data came
from a .csv file that was created
manually in Microsoft Excel by
the Sales team.
The other data was loaded
through a connection to your
organization's Enterprise
Resource Planning (ERP) system.
Now, when you look at the data
in Power BI Desktop, you notice
that it's in disarray; some data
that you don't need and some
data that you do need are in the
wrong format.
You need to use Power Query
Editor to clean up and shape
this data before you can start
building reports.
Problem: data did not import as expected
Promote
headers
You can promote headers in
two ways: by selecting the Use
First Row as Headers option
on the Home tab or by
selecting the drop-down
button next to Column1 and
then selecting Use First Row
as Headers.
Rename
columns
You can rename column
headers in two ways. One
approach is to right-click the
header, select Rename, edit
the name, and then
press Enter.
Alternatively, you can double-
click the column header and
overwrite the name with the
correct name.
You can also work around this
issue by removing (skipping)
the first two rows and then
renaming the columns to the
correct name.
Remove
columns
A key step in the data shaping process is
to remove unnecessary columns. It is
much better to remove columns as early
as possible. One way to remove columns
would be to limit the column when you get
data from data source.
You can remove columns in two ways.
The first method is to select the columns
that you want to remove and then, on
the Home tab, select Remove Columns.
Alternatively, you can select the columns
that you want to keep and then, on
the Home tab, select Remove
Columns > Remove Other Columns.
Unpivot
columns (1)
Unpivoting is a useful feature of
Power BI. You can use this
feature with data from any data
source, but you would most
often use it when importing
data from Excel.
The following example shows a
sample Excel document with
sales data.
Though the data might initially
make sense, it would be difficult
to create a total of all sales
combined from 2018 and 2019.
Your goal would then be to use
this data in Power BI with three
columns: Month, Year,
and SalesAmount.
When you import the data into
Power Query, it will look like the
following image.
Unpivot
columns (2)
Highlight the 2018 and 2019
columns, select
the Transform tab in Power
Query, and then select Unpivot.
Next, rename the first column
to Month. This column was
mislabeled because that header
in Excel was labeling the 2018
and 2019 columns.
Then, rename
the Attribute column
to Year and the Value column
to SalesAmount.
Unpivoting streamlines the
process of creating DAX
measures on the data later. By
completing this process, you
have now created a simpler way
of slicing the data with
the Year and Month columns.
Pivot columns