Shaping and Combining Data

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Module 4

Shaping and Combining Data


Module Overview

• Power BI Desktop Queries


• Shaping Data
• Combining Data
Lesson 1: Power BI Desktop Queries

• The Query Editor


• Applied Steps
• The Advanced Editor
• Demonstration: Using Applied Steps
The Query Editor

• Enables you to load data and apply


transformations
• Comprises of four tabs:
• Home: import data, hide or delete columns, reduce
rows, merge and append queries
• Transform: create aggregated columns, transpose,
pivot, unpivot, split values
• Add Column: add columns, add indexes, apply
functions
• View: show or hide the Query Settings
Applied Steps

• The Query Editor records all transformations to a


query in the Applied Steps setting:
• All transformation steps are listed in order of creation;
Source is first, followed by Navigation if applicable
• Source contains data source connection information,
and Navigation includes select tables and views
• Steps can be reordered if no dependencies exist
• You can delete steps, but be aware of dependencies
• Steps can be undone, rolling back a previous step
• You can rename steps
The Advanced Editor

• With the Advanced Editor, you can see the query that
Power BI runs against the data source to import the data:
• Query is written in M Power Query Formula Language
• To view, click Edit Queries to open Query Editor, then
click Advanced Editor from Home, or View tab
• The query includes the connection, and connection
type; for example, Excel or SQL Database
• All transformations you apply to your data using Query
Editor are added to the query code
• The list of Applied Steps are reflected in the query, and
in the same order
• You can edit the query, but use syntax checker
Demonstration: Using Applied Steps

In this demonstration, you will see how to:


• Add transformations to a query, and see the
steps in Applied Steps
• Rename steps in the Applied Steps list
• See the steps reflected in Advanced Editor
• Delete steps, and change the source table in the
Navigation step
Lesson 2: Shaping Data

• What Is Shaping Data?


• Formatting Data
• Transforming Data
• Demonstration: Transforming Data with the Query
Editor
What Is Shaping Data?

• Shaping data is the process of transforming and


formatting data for best presentation in reports:
• The original data in the source remains unchanged
• Each shaping step is recorded in the Applied Steps

• When shaping data:


• Remove columns and rows that are not needed
• Rename columns using an obvious naming convention
• Ensure columns have the correct data types
• Use date and time functions to create new columns
• Add columns, and indexes useful for appending data
• Apply a sort order, or use an index to guarantee order
Formatting Data

• Query Editor provides many options for creating


columns, formatting text, and numbers:
• General Group:
• Add custom columns using formulas, or duplicate columns
• Add an index column, and move to the front of the table
• From Text
• String functions include lowercase, UPPERCASE, Capitalize Each
Word, Trim, Clean, Add Prefix, and Add Suffix
• Merge columns using optional character or space separator
• From Numbers
• Add, Multiply, Subtract, Divide columns, or calculate by value
• All formatting uses a query that you can view in the
Formula Bar, or in Advanced Editor
Transforming Data

• Table group:
• Use Group By to apply aggregations on your table
• Use First Rows As Headers, and use Headers As First Row
• Transpose to treat columns as rows, and rows as columns
• Reverse Rows to reverse the order of the data
• Any Column group:
• Change data types, or use Detect Data Types
• Replace Values, and Replace Errors
• Fill null values in a column
• Pivot Column and Unpivot Columns
• Move columns
• Split
• Split single column in multiple columns
Demonstration: Transforming Data with the
Query Editor

In this demonstration, you will see how to:


• Import data from Excel
• Apply transformations to the table
Lesson 3: Combining Data

• Adding Data from the Internet


• Shaping the New Data
• Merging Data
• Demonstration: Adding and Shaping Data from
the Internet
Adding Data from the Internet

• Import data from a website that provides data in


a tabular structure:
• Use publicly available datasets, and combine this with
your existing data for reporting insights
• Import using Get Data, Web, and enter the URL
• Power BI establishes a connection, and imports the
data
• Use the data just as you would from any other source
• Preview the table structures that Power BI has detected
• Load data, or edit in Query Editor; data can be
refreshed
• Shape and transform the data as required

• Be aware that the source data could be removed


Shaping the New Data

• After importing data from the Internet, use


shaping and transforming to format and correct
• All shaping is stored under Applied Steps, so will be
reapplied each time the query is run, and data can be
refreshed
• Use the data as you would from any other data source
• Remove columns that you won’t use in reporting
• Ensure the query and columns have names which
reflect the content, and are obvious to users and Q&A
• Make sure columns have the correct data type
• Apply a sort order if required
Merging Data

• Merge columns:
• Merge one table into another table, using a joining
column
• Choose from join types
• All columns are initially merged, but use the selector to
choose which columns you want to keep
• Can retain original column names

• Append rows:
• Adds rows from one or more tables to another table
• Column data does not have to match
• Mismatching can result in unclean data and/or nulls
• Add index to combined table
Demonstration: Adding and Shaping Data from
the Internet

In this demonstration, you will see how to:


• Import data from the Internet
• Shape the data that is imported
Lab: Shaping and Combining Data

• Exercise 1: Shape Power BI Data


• Exercise 2: Combine Power BI Data

Logon Information
Virtual machine: 10989B-MIA-SQL
User name: ADVENTUREWORKS\Student
Password: Pa$$w0rd

Estimated Time: 60 minutes


Lab Scenario

Adventure Works employees are becoming increasingly


frustrated by the time it takes to implement managed BI
services. The existing managed BI infrastructure, including
a data warehouse, enterprise data models, and reports and
dashboards, are valued sources of decision-making
information. However, users increasingly want to explore
relationships with other, currently unmanaged data; and it
takes too long for the IT department to include these
requirements in the corporate BI solution.
As a BI professional, you have been asked to explore ways
in which Adventure Works can empower business users to
augment their managed enterprise BI solution with self-
service BI.
Lab Review

• Discuss the types of different data in your


organization that could be combined using the
Query Editor. Do you have data stored across
locations that could be appended, or lookup data
that could be merged into other tables to make it
more useful for reporting?
Module Review and Takeaways

• Review Question(s)

You might also like