You are on page 1of 530

Power BI Essentials

Introduction to Power BI

Complete Course
CONTENTS

Getting Started
Section 1: Welcome..................................................................4
Section 2: Getting Started..................................................... 10

Connecting to Data
Section 3: Connecting to Text Files...................................... 30
Section 4: Connecting to Excel data..................................... 45
Section 5: Connecting to a Folder of Data............................ 65
Section 6: Connecting to Web Data...................................... 87
Section 7: Connecting to SQL Server.................................. 104

Data Wrangling
Section 8: Splitting and Combining..................................... 123
Section 9: Extracting text..................................................... 135
Section 10: Transforming report data................................. 143
Section 11: Combining tables............................................. 159

Data Modelling
Section 12: Data Modelling Essentials............................... 175
Section 13: Creating Fact and Dim Tables......................... 195
Section 14: Date Tables....................................................... 213
Section 15: Relationships.................................................... 235
Section 16: Hierarchies and Groups................................... 254

-1-
CONTENTS

DAX Formulas
Section 17: Calculated Columns......................................... 277
Section 18: Calculated Tables............................................. 297
Section 19: Measures.......................................................... 312
Section 20: The CALCULATE Function............................... 336
Section 21: DAX Time Intelligence Functions.................... 350

Visualization
Section 22: Big Picture visuals............................................ 374
Section 23: Drill-Down and Drill-Through............................ 389
Section 24: Further Visualization Practice......................... 414
Section 25. Dynamic Titles & Conditional Formatting....... 430

Publishing and Sharing


Section 26: Publishing to the Power BI Service................. 443
Section 27: Power BI Dashboards...................................... 461
Section 28: Collaboration and Sharing............................... 475
Section 29: Power BI Mobile............................................... 501
Section 30: Refreshing Data................................................ 518

-2-
Getting Started

-3-
Section 1: Welcome

Welcome to this comprehensive introduction to Microsoft Power BI.


This course is designed to familiarize you with Power BI’s capabilities in the
most logical order.
The course consists of 30 sections, arranged into seven groups that reflect
the way in which Power BI works and the order in which operations are car-
ried out: Getting Started, Connecting to Data, Data Wrangling, Data Modelling,
DAX formulas, Visualization, and Publishing & Sharing.

Sections 1-2: Getting Started


1. Welcome
2. Getting Started
The first group of sections is, naturally enough, Getting Started. This is where
you’ll get up and running and download all of the resources you’ll need; and
where you’ll get an overview of the Power BI product, Power BI tenants and
Power BI licenses.

Sections 3-7: Connecting to data


3. Connecting to Text Files
4. Connecting to Excel Files
5. Connecting to a Folder of Data
6. Connecting to Web Data
7. Connecting to SQL Server
Then we dive straight into using Power BI and the first business intelligence
skill you need to master: connecting to data sources.
In these five sections, you’ll learn how to bring data into Power BI from Text
Files, CSVs and Excel Files; as well as how to connect to a Folder of Data,
either on your own file system or in a SharePoint library, and automatically

-4-
Section 1: Welcome

combine all the files inside the folder into a single table.
You’ll also learn how to Connect to data on websites and how to scrape data
from the web page itself.
And, naturally, you’ll get plenty of practice in connecting to Power BI’s most
frequent data partner: SQL Server. You’ll learn how to work in import, Di-
rectQuery and composite modes and how to retrieve data from both views
and database tables, as well as by executing SQL statements.

Sections 8-11: Data Wrangling


8. Splitting and Combining Columns
9. Extracting text
10. Transforming report data
11. Combining tables
Once you’re comfortable with getting data into Power BI, we’ll move on to the
next stage in the Power BI cycle: Data Wrangling.
It’s very rare that the data you connect to is already optimized for reporting; so
our four sections on data cleansing and transformation will fully familiarize
you with using Power Query, the utility built into Power BI whose user-friendly
interface allows you to carry out powerful and sophisticated transformation
with just a few mouse clicks, as well as how to edit the underlying M lan-
guage code generated by the interface.
In this group of sections, we’ll look at useful commands for morphing raw
data into the exact shape required for your reporting purposes:
Splitting columns that contain multiple data elements into separate columns;
and doing the reverse, combining columns to create new composite columns.
And extracting just the elements you require for reporting from the original
data columns using powerful built-in commands.
Cleansing data which has been produced by another system to get rid of such

-5-
Section 1: Welcome

features as embedded subtotals and pivoted columns.


And we’ll end this group of sections with a look at Power Query’s excellent
commands for stitching separate data queries into a single table, both verti-
cally and horizontally.

Sections 12-16: Data MODELLING


12. Data Modelling Fundamentals
13. Creating Fact and Dim Tables
14. Date Tables
15. Relationships
16. Hierarchies and Groups
After mastering the first two steps in your Power BI journey, connecting to
data and data cleansing, you’ll be ready to move on to the next stage: data
modelling.
In this group of sections, you’ll learn how to combine the various tables that
you need into a single entity called a data model.
You’ll start by learning the fundamentals of data modelling.
Then move onto looking at the two types of data table used in the data mod-
el: dimension tables and fact tables.
Next, you’ll see how to create relationships between the various tables how
this differs from creating relationships in relational databases.
And, we’ll spend some time discussing the various ways of creating one of
the standard dimension tables used in almost all data models: date tables.
And we’ll end this group of sections with a section on how create special
objects called hierarchies and groups which allow your users to explore your
data by drilling down into different levels of detail.

-6-
Section 1: Welcome

Sections 17-21: DAX Formulas


12. Calculated Columns
13. Calculated Tables
14. Measures
15. The CALCULATE Function
16. DAX Time Intelligence Functions

Having created a data model, our next group of sections focuses on using the
DAX language to add insights and enhancements.
We’ll look at the three types of calculation which you can create using the
DAX language:
Calculated columns
Calculated tables
And measures
And we’ll get to grips with the most important function in the DAX language:
the CALCULATE function.
And we’ll end the section by looking at DAX time intelligence functions which
enable you to compare calculations based on different time periods, to pro-
vide such insights as year-on-year growth and year to date sales.

Sections 22-25: Visualization


22. Big Picture visuals
23. Drill-Down and Drill-Through
24. Further Visualization Practice
25. Dynamic Titles & Conditional Formatting

-7-
Section 1: Welcome

Once we have built our data model, we’ll move on to the next phase in the
Power BI development cycle: visualization and report creation.
We’ll start with what I like to call the big-picture visuals, those which give your
audience with key metrics at a glance. As you’ll see in this section Power BI
has three big picture visuals: the card, the KPI visual and the gauge.
Then you’ll learn how the hierarchical structures within the data model can be
exposed to your users by enabling them to drill down into data which has a
parent-child and drill-through from a overview page to a page which focuses
on a particular item displayed in the overview.
And, of course, we’ll talk about many other visuals and visualization tech-
niques as we work through these sections.
We’ll even look at using DAX measures to enhance the user experience by
making titles change dynamically as users interact with them.

Sections 26-30: Publishing and Sharing


26. Publishing to the Power BI Service
27. Power BI Dashboards
28. Collaboration and Sharing
29. Power BI Mobile
30. Refreshing Data
OK, so now we have a report, in our last group of sections, we will look at how
we can make our content available to our intended audience.
First, we’ll look at publishing from Power BI Desktop into the Power BI service.
Then, you’ll learn how to create dashboards in the Power BI service and the
different ways of adding content to them.
You’ll learn how to create app workspaces and how to grant access to fellow
report developers, so that your team can collaborate on the creation of con-
tent; and how the different strategies for sharing that content throughout the

-8-
Section 1: Welcome

entire organisation.
And, in our section on Power BI mobile, you’ll learn how to create reports and
dashboards which are optimised for mobile viewing.
And we’ll end our collaboration and sharing section by discussing the prin-
cipal mechanism used in Power BI for refreshing data to keep it in sync with
changes made to the original data sources: namely, on premises data gate-
way.
So, as you can see this course covers a lot of ground; there’s a lot to learn and
a lot to remember.
That’s why each of the thirty sections in this course starts with an overview
and ends with a section summary which recaps the key topics covered and
reminds you where these techniques fit into the overall Power BI cycle.
So, basically, you always know where you are within the grand scheme of all
things Power BI.

-9-
Section 2: Getting Started

Section
Summary

Section 2: Getting Started

- 10 -
Section 2: Getting Started

Section
Summary

- 11 -
Section 2: Getting Started

• Microsoft Power BI consists of three parts:


• Power BI Desktop
• The Power BI service
• and Power BI mobile apps.

• The key activities carried


out in Power BI Desktop
are:
• Connecting with your
data
• Data cleansing and
transformation
• Creating data models
• Creating reports.

- 12 -
Section 2: Getting Started

Installing Power BI Desktop

• Power BI Desktop can be downloaded and installed as a


standard executable package.
• However, since the product is updated every month, the
latest version will need to be manually downloaded and
installed each month.

• Power BI Desktop can


also be installed as a
Windows 10 app from
the Microsoft store.
• The key benefit of
installing Power BI
Desktop from the
Microsoft store is that
the product will be
automatically updated
every month.

- 13 -
Section 2: Getting Started

Power BI Service

• The Power BI service is the cloud-based product where


collaboration and sharing takes place. You can also create
reports and dashboards within the Power BI service, once you
have created and shared content.

Dashboards

• The Power BI Service is also the only place where dashboards


can be created.
• In Power BI Desktop, you can only create reports.

- 14 -
Section 2: Getting Started

Dashboards versus Reports


• In the Power BI environment, dashboards are single screen
summaries of key information.
• Whereas reports are in-depth multi-page summaries
providing a full breakdown of all the key metrics relating to
one aspect of an organization's data.

Editing Reports in the Power BI Service


• Reports are normally created in Power BI Desktop and then
published to the Power BI service for sharing.

- 15 -
Section 2: Getting Started

Editing Reports in the Power BI Service


• It is also possible to edit reports in the Power BI service.
• However, only the visual aspects of reports can be edited in
the cloud; changes to the underlying data can only be made
in Power BI Desktop.

Power BI Mobile Apps


• Power BI mobile apps are used to consume Power BI content.
• Apps are available for every major mobile platform.

- 16 -
Section 2: Getting Started

Optimized Reports

• By default, Power BI reports are displayed in landscape


orientation and are perfectly acceptable as is.

• However, report authors can create an additional view which


is optimized for mobile devices and displays in portrait
orientation.

- 17 -
Section 2: Getting Started

Section
Summary

- 18 -
Section 2: Getting Started

• A tenant is the Microsoft Azure container which stores all


the data relating to an organization’s Microsoft Power BI
subscription.
• A Power BI tenant is created automatically when the first
user from a given organization signs up to the Power BI
service.

- 19 -
Section 2: Getting Started

Tenant Location

• Part of the sign-up process is to


specify the location of your
organization.
• The region chosen will
determine the Microsoft data
region in which your Power BI
tenant will be located.
• You cannot change the
selection after the tenant has
been created.

Checking Tenant Location


• To check the location of a Power BI tenant, in the Power BI
service, click Settings > Help & Support > About Power BI.

- 20 -
Section 2: Getting Started

Checking Tenant Location

• The dialog which is displayed contains confirmation of the


Microsoft data region in which your Power BI data is stored.

- 21 -
Section 2: Getting Started

Section
Summary

- 22 -
Section 2: Getting Started

• Power BI Desktop is completely free. However, individuals


using the Power BI service require one of two available
user licenses:
• Power BI Free (which is completely free of charge)
• Power BI Pro (which costs $10 per month).

Limitations of Power BI Free

• The difference between Power BI Free and Power BI Pro is


collaboration.
• Power BI Free cannot be used for sharing and collaboration
but is very useful for learning the product, creating reports
and experimenting.

- 23 -
Section 2: Getting Started

Power BI Pro Trial

• When using Power BI Free, if a user attempts to perform an


operation which requires a Pro license, they will be offered
the opportunity of having a 60-day trial of Power BI Pro.

• Within each Power BI tenant, approximately 50 such offers


are made. After this, when attempting to use a collaboration
or sharing feature, free users will simply be prompted to
upgrade to Power BI Pro.

• To verify whether you have a Power BI Pro license, in the


Power BI service, try clicking the “Share” button next to any of
your reports or dashboards.

- 24 -
Section 2: Getting Started

Free or Pro

• If you only have the free license, the “Upgrade to Power BI


Pro” message will be displayed.

• If you have a Pro license, the “Share report” dialog should


be displayed.
• However, bear in mind that you may still only have a
Power BI Free license with a 60-day trial.

- 25 -
Section 2: Getting Started

Pro or Pro Trial?

• To verify whether you are running a Power BI Pro trial, in the


Power BI service, click on the Settings button in the top right
of your screen.
• If you are running a free trial, the number of days remaining
will be displayed.

- 26 -
Section 2: Getting Started

Power BI Premium
• Unlike the Power BI Pro and Free licenses, Power BI Premium
is a tenant-level subscription available in various capacity
configurations.
• Power BI Premium provides organizations with dedicated
capacities, in contrast to the shared capacity model, where
Power BI resources are shared by multiple organizations.

Power BI Premium and Pro Users

• Even if an organization
purchases Power BI Premium,
content creators (people who
are creating reports,
dashboards and apps) will still
need to have a Power BI Pro
license.

- 27 -
Section 2: Getting Started

Power BI Premium and Free Users

• However, anyone who is


simply a content consumer
(looking at reports and
dashboards, but not actually
creating them), can use a free
license; and there are no
limits as to how many free
licenses can be used.

- 28 -
Connecting to Data

- 29 -
Section 3: Connecting to Text Files

Section 3: Connecting to Text Files

- 30 -
Section 3: Connecting to Text Files

- 31 -
Section 3: Connecting to Text Files

• The command Get Data > Text CSV is used to connect to


all types of text files.
• This same command is used regardless of the delimiter
within the file, be it a comma, tab, pipe, semi-colon, etc.

• When you connect to a text file, you are shown a


preview of the file which you have connected to.
• At the top of the Preview window are three drop-down
menus: File Origin, Delimiter and Data Type Detection.

- 32 -
Section 3: Connecting to Text Files

• When you connect to a text file, you are shown a


preview of the file which you have connected to.
• At the top of the Preview window are three drop-down
menus: File Origin, Delimiter and Data Type Detection.

• The file origin drop-down


displays the language
encoding which Power BI
has detected within the
file.
• Although you can choose
a different encoding to the
one detected by Power BI,
this will only work if the
encoding you choose is
actually present in the file.

- 33 -
Section 3: Connecting to Text Files

• The delimiter drop-down


displays the detected
delimiter character used to
demarcate columns of
data.
• It’s very rare that you will
need to specify the
delimiter, since Power BI
will normally detect it.

• Power BI normally bases its data type detection on the first


200 rows.
• The Data Type Detection drop-down allows you to change
this to either “Based on the entire dataset” or “Do not detect
data types”.

• Changing this option may be useful if key columns have


null values in the first 200 rows.

- 34 -
Section 3: Connecting to Text Files

- 35 -
Section 3: Connecting to Text Files

• Use Get Data > Web to connect to SharePoint files.


• Using the native connector does not connect to the
SharePoint file.
• Data stored in SharePoint libraries is automatically
refreshed. The Team

• When connecting to files stored in a SharePoint library, it


is best to use the connector Get Data > Web.
• To obtain the URL, simply copy the library URL and
then add the file name.

- 36 -
Section 3: Connecting to Text Files

• Avoid using native connectors when connecting to files


stored in SharePoint.
• For example, if downloading a CSV file, don’t use Get
Data > Text/CSV.
• If a native connector is used, Power BI will download the
file to your hard drive and then connect to the downloaded
file.
• This means that when the file changes, your imported data
will be out of synch with these changes.

- 37 -
Section 3: Connecting to Text Files

• Using Get Data > Web when connecting to files stored in


SharePoint will ensure that the data in your reports is
automatically refreshed.
• If the file stored in SharePoint is updated, these changes
will be reflected in your reports within an hour.
• By contrast, when you import data stored on premises,
changes will only be reflected if you set up a refresh
schedule using an on-premises data gateway.

- 38 -
Section 3: Connecting to Text Files

- 39 -
Section 3: Connecting to Text Files

• When using a data field for mapping, always specify the


data category.
• Select the field and then, in the Column Tools Tab, choose
the appropriate data category; for example “Latitude”.

• The Map visual creates a


map which features circular
hotspots.
• This is in contrast to the
Filled Map visual which
focuses on regions.

- 40 -
Section 3: Connecting to Text Files

• When configuring the map visual, the Size data field can
be used to link the size of the hotspots to any numeric
value.
• Just drag the appropriate field or measure into the Size
data field.

- 41 -
Section 3: Connecting to Text Files

• By default, the slicer visual has a vertical orientation.


• To change the orientation to horizontal, in the Format
pane, click General > Orientation > Horizontal.

- 42 -
Section 3: Connecting to Text Files

• On a bar chart, both the axis titles and the axes themselves
can be switched off.
• Data labels are often a good replacement for the X axis.

- 43 -
Section 3: Connecting to Text Files

• The slicer visual is dedicated to filtering other visuals on


the page.
• However, chart visuals (such as the bar chart) can also be
used for filtering.
• Using one visual to filter another is referred to as cross-
filtering.

- 44 -
Section 4: Connecting to Excel data

Section 4: Connecting to Excel data

- 45 -
Section 4: Connecting to Excel data

- 46 -
Section 4: Connecting to Excel data

• To connect to an Excel workbook, in the Home


Tab of the Ribbon, click Get Data > Excel.

• Or simply click the Excel button.

• When connecting to a workbook, Power BI


recognizes three Excel data objects:
• Worksheets
• Tables
• Named ranges

- 47 -
Section 4: Connecting to Excel data

• An Excel workbook consists of one or more


worksheets.

• When you connect to a workbook, Power BI


displays all of its worksheets in the navigation pane.

• Even if data is formatted as a table or named range,


Power BI still displays the underlying worksheet as
a separate object.

• Excel tables are optimized


for data analysis and always
consist of named columns.

• Tables are therefore the most


compatible format when
importing Excel data into
Power BI.

• It is useful to name your


Excel tables, rather than
leaving the default names:
“Table1”, “Table2”, etc.

- 48 -
Section 4: Connecting to Excel data

• Named ranges are used to


add clarity to Excel models,
and this is especially the
case when they are used in
place of formula references.

• Power BI recognizes named


ranges as separate data
objects but will still display
the worksheet on which the
named range is located.

- 49 -
Section 4: Connecting to Excel data

- 50 -
Section 4: Connecting to Excel data

• In Excel, sheets can be hidden by right-clicking the


sheet tab and choosing “Hide”.

• Although the data in hidden worksheets is not


visible, it can still be referenced from other
worksheets and workbooks. Hidden Sheets

• (Sheets can also be “Very hidden” in the Visual


Basic Editor by setting the Visible property of the
the sheet to “xlSheetVeryHidden”.)

• When you connect to an Excel workbook, only visible


sheets are displayed in the Navigator preview.
• However, you can connect to hidden and “very
hidden” worksheets by editing the M code of the
Power BI query.

- 51 -
Section 4: Connecting to Excel data

• In the Navigator, click in the check box next to any


of the available sheets.

• Click on Transform Data to enter the Power Query


Editor.

- 52 -
Section 4: Connecting to Excel data

• In the Applied Steps pane, delete all steps bar


“Source” and “Navigation”.

• Select the “Navigation” step and, in the Formula


bar, change the name of the sheet to which you
are navigating.

- 53 -
Section 4: Connecting to Excel data

- 54 -
Section 4: Connecting to Excel data

• If you connect to an Excel table, you normally get a


hundred percent accuracy in terms of column
recognition.
• When you connect to raw worksheet data, you will
sometimes find that Power BI recognizes blank
columns which used to contain data but no longer
do.
• This is an Excel issue which Power BI inherits, and
the columns can simply be removed.

- 55 -
Section 4: Connecting to Excel data

• The Choose Columns command, in the Home Tab of


the Power Query Editor, provides a convenient way of
quickly identifying and deleting unwanted columns.
• Simply deactivate the checkbox next to each of the
columns you wish to remove.

- 56 -
Section 4: Connecting to Excel data

• Power BI cannot import data from an Excel file


which is password protected.

• However, the error which Power BI displays


is misleading:
"We encountered an error while trying to
connect. Details: This file contains
corrupted data."

- 57 -
Section 4: Connecting to Excel data

• Excel’s Total Row feature is found in Table Tools >


Design and adds an extra “Total” row to a table.

• When you import an Excel table, you need to


remove the total row if one exists.
• If you know that the total row will always be
present, you can remove it with the Remove
Rows command.
• However, a safer approach is to filter out the
total row.

- 58 -
Section 4: Connecting to Excel data

- 59 -
Section 4: Connecting to Excel data

• You can populate a bar chart by clicking the


checkboxes next to the appropriate field.
• Clicking a text field places that field on the Axis of
the chart.
• Clicking a numeric field places the field in the
Values area of the visual.

- 60 -
Section 4: Connecting to Excel data

• Click the arrow next


to the field on the
Axis to specify the
aggregation.

• By default, Power BI sorts a bar chart in descending


order using the Values field.
• You can monitor and change the sort order using the
Sort options in the ellipsis menu.

- 61 -
Section 4: Connecting to Excel data

• The Treemap visual is


a useful alternative to
the pie and donut chart
for displaying the
breakdown of a field.
• It is useful where a
field breaks down into
more than just a few
elements.

• The two key areas of a


treemap are Group and
Values.
• The Group is the field
whose composition
you wish to display.
• The Values are the
metric being measured
for each element.

- 62 -
Section 4: Connecting to Excel data

• A treemap displays two key values: category labels


and data labels.
• The (textual) category label is determined by the
field placed in the Group area.
• The (numeric) data label is generated by the field
placed in the Values area.

- 63 -
Section 4: Connecting to Excel data

• By default, many visuals interact with other visuals


by cross-highlighting, rather than cross-filtering.
• To switch the behavior between cross-filtering and
cross-highlighting, in the Format Tab of the Ribbon
activate “Edit Interactions”.
• The interaction between visuals can be set to Filter,
Highlight or None.

- 64 -
Section 5: Connecting to a Folder of Data

Section 5: Connecting to a Folder of Data

- 65 -
Section 5: Connecting to a Folder of Data

- 66 -
Section 5: Connecting to a Folder of Data

• The command Get Data > Folder is used to stitch


together data in different files.

• In order for this feature to work correctly:


• All of the files must have exactly the same column
headings (though not necessarily in the same order)
• And all of the files must be of the same file type.

• The files being combined can be placed inside sub-


folders.

- 67 -
Section 5: Connecting to a Folder of Data

• When the Get Data > Folder command is used, the


initial preview window displays metadata rather
than data; a list of all the files found in the specified
folder.

• To access the data inside the files, click Combine


and Transform Data.

- 68 -
Section 5: Connecting to a Folder of Data

• The Combine Files window allows you to specify a


sample file.

• The sample file determines the columns which will


be included in the output file and the data connector
which will be used, for example Text/CSV.

• If no sample file is specified, by default, the first


file in the folder is used as the sample file.

- 69 -
Section 5: Connecting to a Folder of Data

• The output query produced by the Get Data >


Folder operation relies on a number of helper
queries.

• These queries are required by the output query and


therefore cannot be deleted.

• The helper file called “Transform Sample File” is


used to determine the connection and
transformation which will be carried out on each
file in the folder.

• Any additional transformations carried out on this


query will also be applied to all files.

- 70 -
Section 5: Connecting to a Folder of Data

• When a blank sample file is used (one that contains


only headers), Power Query does not recognize the
first row as headers.

• This means that the header row is treated as data


and repeats within the output query.

- 71 -
Section 5: Connecting to a Folder of Data

• To resolve this problem, simply highlight the helper


file called “Transform Sample File” and click “Use
First Row as Headers”.

- 72 -
Section 5: Connecting to a Folder of Data

- 73 -
Section 5: Connecting to a Folder of Data

The Team

• The Get Data > SharePoint Folder command


actually connects to a SharePoint site rather than a
SharePoint folder.

- 74 -
Section 5: Connecting to a Folder of Data

• In order to target a specific folder in the site, after


using the Get Data > SharePoint folder command,
you must add a filter to the resulting query.

• When you use the Get Data > SharePoint folder


command, you are asked to provide the URL of a
SharePoint site (not a SharePoint folder).

- 75 -
Section 5: Connecting to a Folder of Data

• You then need to supply the “Microsoft account”


credentials required for accessing the specified site.

• When the Get Data > Folder command is used, the


preview window displays a list of all the files found
in the SharePoint site, regardless of file type and
sub-folders.

- 76 -
Section 5: Connecting to a Folder of Data

• When the Get Data > Folder command is used, the


preview window displays a list of all the files found
in the SharePoint site, regardless of file type and
sub-folders.

• So, instead of attempting to combine files, click


Transform data.

- 77 -
Section 5: Connecting to a Folder of Data

• The resulting query then shows metadata about the


files in the SharePoint site.

• To target a particular folder, we simply apply a filter


to the Folder Path column of the metadata table.

- 78 -
Section 5: Connecting to a Folder of Data

• To manually combine the files listed in the metadata


table, click the Combine Files button on the right of
the “Content” column.

• This displays the Combine File dialog and from


here everything functions in the same way as when
using Get Data > Folder.

- 79 -
Section 5: Connecting to a Folder of Data

- 80 -
Section 5: Connecting to a Folder of Data

• Themes are used in Power BI to globally control


report formatting.

• Power BI has a number of built-in themes.

• To use a built-in theme, simply choose an item from


the “Themes” dropdown in the View Tab of the
Ribbon.

- 81 -
Section 5: Connecting to a Folder of Data

• Themes can include a background colour, which


will be applied to all pages in the report.

- 82 -
Section 5: Connecting to a Folder of Data

• The card visual displays a single key metric.

• It displays a data label and a category label.

• To populate a card visual, click on the check box


next to the required field.

• The name of the field will be used as the category


label.

- 83 -
Section 5: Connecting to a Folder of Data

• To change the category label, in the Fields section


of the Visualizations pane, simply double-click
the existing label and enter a new one.

• By default, data labels use the SUM function for


aggregation.

• To choose a different function, click on the arrow


next to the field name.

- 84 -
Section 5: Connecting to a Folder of Data

• When formatting the Data label of a card visual,


setting display units to “None” forces Power BI to
display the raw figure.

• To
T preserve existing
i i formatting,
f i visuals
i l can be
duplicated by highlighting the original and typing
Control-C followed by Control-V.

- 85 -
Section 5: Connecting to a Folder of Data

• The Home Tab of the Ribbon also contains Copy


and Paste buttons.

- 86 -
Section 6: Connecting to Web Data

Section 6: Connecting to Web Data

- 87 -
Section 6: Connecting to Web Data

- 88 -
Section 6: Connecting to Web Data

• Connecting to a web URL does not imply any specific


format.
• The file being accessed via the web may be in any format:
CSV, XML, JSON etc.

The Team

• However, accessing web data using its native connector


(instead of using Get Data > Web) will cause Power Query
to download the file and then import the downloaded file.

- 89 -
Section 6: Connecting to Web Data

• This means that an on-premises data gateway will be


required to refresh the data source.

The Team

Data Gateway

On-prem Data

• By contrast, when data is imported using Get Data > Web,


no data gateway is required to access and refresh the data
(provided that all data sources in the dataset are web-
based).
• Scheduled refreshes are created in dataset settings in the
Power BI service.

- 90 -
Section 6: Connecting to Web Data

• You can add up to 8


scheduled times in a
Power BI Pro
workspace.
• And up to 48 in a
premium capacity
workspace.
The Team

- 91 -
Section 6: Connecting to Web Data

- 92 -
Section 6: Connecting to Web Data

• As well as connecting to a web URL, Power BI also allows


you to “scrape” data directly from a web page and import
any tabular data the page contains.
• This operation uses the standard web connector: Get Data
> Web.
The Team

• The Navigator window displays a preview of the tables


retrieved from the web page and lets you specify the
required table.

- 93 -
Section 6: Connecting to Web Data

• The Navigator also lets you switch between the standard


“Table View” and a useful “Web View” which provides a
preview of the web page.

• The same data refresh rules apply to web page data as to


any other web-based data source.
• No data gateway is required to access and refresh the
data (provided that all data sources in the dataset are
web-based).

Web Data

- 94 -
Section 6: Connecting to Web Data

- 95 -
Section 6: Connecting to Web Data

• Relationships are used to link the tables within the data


model using common columns.
• A column in one table acts as a primary key and the
matching column in the related table acts as a foreign key.
• The default relationship in Power BI is one to many.

• Th
The ttwo tables
t bl mustt have
h a common column.
l
• The common columns must contain the same type of data.
• One table must have unique values in the common column.

- 96 -
Section 6: Connecting to Web Data

• If, in addition to satisfying the usual criteria, the common


column has the same name in both tables, Power BI will
automatically create the relationship.
• To ensure that the two tables had a column in common, we
created a conditional column in one of our tables.
• The Power Query command Add Column > Conditional
Column allows you to create a column by defining logical
clauses which can only be true or false.

• To ensure that the two tables had a column in common, we


created a conditional column in one of our tables.
• The Power Query command Add Column > Conditional
Column allows you to create a column by defining logical
clauses which can only be true or false.

- 97 -
Section 6: Connecting to Web Data

• In Power Query, new columns are added in the context of a


single query.
• When you click “Close and Apply”, Power BI generates the
data model.
• You can now use the DAX language to add elements to the
data model, including calculated columns.
• To create a DAX calculated column, highlight the appropriate
table and, in the Table Tools Tab of the Ribbon, click New
Column.

- 98 -
Section 6: Connecting to Web Data

• Unlike Power Query columns, DAX calculated columns can


refer to any element present in the data model, including
columns in other tables.

• The RELATED function is used when creating a column in the


table on the many side of a relationship to refer to a column
in the table on the one side.
• Hence, RELATED always retrieves a single value.

- 99 -
Section 6: Connecting to Web Data

- 100 -
Section 6: Connecting to Web Data

• To add a page background,


in the format section of the
Visualization pane, click
Page Background > Add
Image.
• Background images are
100% transparent by default.
• Reduce the transparency to
0% to make the image fully
visible.

• To populate the table visual, simply click on the check


boxes next to the fields you want to display in the table.

- 101 -
Section 6: Connecting to Web Data

• Settings in the Values section of the Format Tab apply only


to the body of the table, while those in Column Headers
apply to column headings.

• By default, text columns are sorted alphabetically.


• This natural sort order can be overridden by mapping the sort
to an associated numeric column.

- 102 -
Section 6: Connecting to Web Data

• To specify the sort order, highlight the text column in the


Fields pane and, in the Column Tools Tab, choose the numeric
column from the Sort by Column dropdown.

- 103 -
Section 7: Connecting to SQL Server

Section 7: Connecting to SQL Server

- 104 -
Section 7: Connecting to SQL Server

- 105 -
Section 7: Connecting to SQL Server

The Team
Th T

• To connect to a SQL Server database, click Get Data > SQL


Server.
• Enter the name of the server and, optionally, the database.

• Choosing Import mode will normally provide the best


performance in the Power BI data model.
• However, in import mode, all of the data is imported from
the server into the Power BI data model, which may cause
the file to exceed the limit of 1 GB.

- 106 -
Section 7: Connecting to SQL Server

• Using your current Windows credentials to access the


database is useful for testing and training environments.

The Team

• In a production environment, you would normally click on


the Database Tab and enter a username and password.

- 107 -
Section 7: Connecting to SQL Server

• Power BI will recognize three types of SQL Server object:


databases, views and stored procedures.

The Team

• When importing data from SQL Server, in general, the most


efficient approach is to avoid connecting directly to the
tables in your relational database.
• Instead, create a series of views, each corresponding to
one of the tables which will be present in your data model.
• In Power BI, you then connect to these views rather than to
the original database tables.
• Taking this approach makes it easier to update your Power
BI data models if modifications are made to the database
tables or to the database structure.

- 108 -
Section 7: Connecting to SQL Server

• When connecting to SQL Server Views, Power BI still


automatically detects and creates relationships between
the imported tables.

• Query folding is the process whereby


some, or all, of the transformations you
define in the Query Editor are converted
into SQL statements and pushed back to
the database server.
• This can provide a significant
performance boost each time the data
source is refreshed.

• To monitor query folding, right-click on


one of the “Applied steps” in the Query
pane and choose “View Native Query”
from the menu.

- 109 -
Section 7: Connecting to SQL Server

- 110 -
Section 7: Connecting to SQL Server

• Import is Power BI’s default mode when connecting to data


and is designed to provide optimal performance.
• DirectQuery is usually used in preference to import mode
for three main reasons:
• When frequent changes in data need to be fed quickly
through to report consumers. The Team
• When data is too large to be imported without
exceeding Power BI’s 1 GB limit.
• When data is not permitted to leave the organization’s
premises.
• When you connect to SQL server using DirectQuery
mode, data is not imported into the data model of your
SQL Server report. Instead, the actual database source
is always queried, not an imported copy.

- 111 -
Section 7: Connecting to SQL Server

• Power BI does not automatically generate relationships


when connecting to SQL Server views in DirectQuery mode.

The Team

• In the Edit Relationship


dialog, “Assume
referential integrity”
helps to improve
performance in
DirectQuery mode by
optimizing the SQL
queries generated by
Power BI.

- 112 -
Section 7: Connecting to SQL Server

• In DirectQuery mode, transformational steps which cannot


be query folded (i.e. converted to native SQL statements)
are not permitted.
• Such steps must be deleted, or the whole report converted
to Import mode.

- 113 -
Section 7: Connecting to SQL Server

- 114 -
Section 7: Connecting to SQL Server

Executing SQL Statements


• We have seen that, when connecting to SQL Server, it is best
to create views and then connect to your views from Power BI,
in preference to the underlying tables.
• However, if this is not possible, the same statements that you
would use to create views in the SQL Server database can be
executed from within Power BI.
• To execute a SQL statement, click Get Data > SQL Server.
• This time, however, you must enter the name of both the
server and the database.
• Click “Advanced options” and enter or paste in your SQL in the
“SQL statement…” box.

- 115 -
Section 7: Connecting to SQL Server

• Each SQL statement that you execute in this way will


produce a single table.
• Simply repeat the process to create all the tables you need
in your data model.

No Query Folding
• Whenever you create a query by executing an SQL statement,
no query folding at all will occur.
• Whatever transformational steps you perform will always be
done using the M language and not converted into SQL.

- 116 -
Section 7: Connecting to SQL Server

• To carry out further transformations using SQL, click on the cog


icon next to the Source step then modify the SQL statement.

- 117 -
Section 7: Connecting to SQL Server

- 118 -
Section 7: Connecting to SQL Server

•• Composite
Composite mode
mode is
is aa variant
variant of
of DirectQuery
DirectQuery mode.
mode.
•• Composite
Composite mode is a variant of DirectQuery mode.
• Composite mode
mode is
is aa variant
variant of
of DirectQuery
DirectQuery mode.
mode.
•• Composite
You can mode is aDirectQuery
variant of DirectQuery mode.
• You can switch
Composite mode
switch from
is aDirectQuery
from to
to Composite
variant of DirectQuery mode,
mode, but
mode.
Composite but
not from
not from Import to
Importfrom Composite.
to Composite.
• You can switch DirectQuery to Composite mode, but
• You can switch from DirectQuery to Composite mode, but
not from Import to Composite.
not from Import to Composite.

•• Importing
Importing aa table
table or
or creating
creating aa DAX
DAX table
table will
will automatically
automatically
switch
switch a report
a report from
from DirectQuery
DirectQuery mode
mode to Mixed mode,
• Importing a table or creating a DAX tabletowill
Mixed mode,
automatically
• creating
Importing
creating a composite
a table or model.
creating a DAX table will automatically
switch a areport
composite model.
from DirectQuery mode to Mixed mode,
switch a report from DirectQuery
creating a composite model. mode to Mixed mode,
creating a composite model.

- 119 -
Section 7: Connecting to SQL Server

• To improve performance when using composite models,


Power BI offers three different storage modes: Import, Direct
Query and Dual.

• In Import mode, the table data is imported into the data


model and only replaced when the dataset is refreshed.
• This mode is normally used for tables which contain data that
does not change very often.

- 120 -
Section 7: Connecting to SQL Server

• In DirectQuery mode, all queries are sent to the database


server; and no data is imported into the data model.
• This mode is normally used for tables which either change
very often or are too large to import.

• In Dual mode a copy of the table data is imported into the


data model.
• Queries involving data from the dual mode table as well as
other related tables will be sent to the server.
• However, if a query only requires data from the dual mode
table, the imported data will be used, potentially improving
performance and enhancing the user experience.

- 121 -
Data Wrangling

- 122 -
Section 8: Splitting and Combining

Section 8: Splitting & Combining Columns

- 123 -
Section 8: Splitting and Combining

- 124 -
Section 8: Splitting and Combining

Identifying Text Issues


• When looking to clean up a text column, it is always useful
to know what you are looking for; and one way of doing
this is to copy the column into Microsoft Word and review
the invisible characters.
• Right-click the text column and Choose “Copy”.
The Team

• Once the data is pasted into Microsoft Word, activate the


Show Hidden Characters feature to identify the invisible
characters.
• A dot represents a space and the arrow symbol represents
a Tab character.

- 125 -
TrimSection 8: Splitting and Combining
and Clean
• The Trim command removes leading and trailing spaces from a
text column.
• The Clean command removes white space characters like tabs
and returns.
Trim and Clean
• To use these commands, either:
• The Trim command removes leading and trailing spaces from a
text column.
• Right-click the text column and choose Transform > Format >
Trim/Clean
• The Clean command
• In the removes
Ribbon, click white
Transform space
> Format characters like tabs
> Trim/Clean.
and returns.
• To use these commands, either:
• Right-click the text column and choose Transform > Format >
Trim/Clean
• In the Ribbon, click Transform > Format > Trim/Clean.

Split Column by Delimiter


• The Split Column by Delimiter command creates new columns
by splitting text entries wherever the specified delimiter
occurs.

Split Column by Delimiter


• The Split Column by Delimiter command creates new columns
by splitting text entries wherever the specified delimiter
occurs.

occurs.
by splitting text entries wherever the specified delimiter
- 126 -
• The Split Column by Delimiter command creates new columns
Section 8: Splitting and Combining

Split Column by Delimiter


• The Split Column by Delimiter command creates new columns
by splitting text entries wherever the specified delimiter
occurs.

• When using the Split Column by Delimiter command,


activating the option Left-most delimiter ensures that only
two columns will be created.

- 127 -
Section 8: Splitting and Combining

- 128 -
Section 8: Splitting and Combining

Split by Character Transition


• Power Query contains four useful commands for splitting
columns according to a transition from one kind of
character to another, i.e., at the point where a key attribute
of the characters changes:
• By Lowercase to uppercase
• By Uppercase to lowercase
The Team
• By Digit to non-digit
• By Non-digit to digit
• For example, if a variable number of digits is followed by
text, we can use the command Split Column > Digit to Non-
Digit to separate the characters following the leading digits
into a new column.

- 129 -
Section 8: Splitting and Combining

- 130 -
Section 8: Splitting and Combining

Merge Columns
• The merge columns command combines the selected
columns into a single column using the specified
“Separator”.

• The merge columns command combines the selected


columns into a single column using the specified
“Separator”.
• When combining columns using Transform > Merge
Columns, the order in which you select the columns
determines the order in which the columns will be merged.

• The Power Query Merge Columns command can be found


on both the Transform and Add Column Tabs of the Ribbon.
• Using Transform > Merge Columns replaces the merge
columns, whereas Add Columns > Merge Columns
preserves the existing columns.

- 131 -
Section 8: Splitting and Combining

• Using Right-click > Merge Columns is equivalent to


Transform > Merge Columns.

Merge Columns & Query Folding


• When transforming queries which connect to database
servers, such as SQL Server and Oracle, Merge Columns is
one of those commands which cannot be query folded (i.e.,
it cannot be converted into a native SQL command to be
executed by the server).

- 132 -
Section 8: Splitting and Combining

Add Column > Custom Column


• Unlike Merge Columns, using the more basic command Add
Column > Custom Column to create a concatenated column,
generates a step which will be query-folded.

• The Add Column > Custom Column command displays a


dialog into which you can enter M language code.
• To combine columns, simply enter the names of the columns
using the “&” character for concatenation.

- 133 -
Section 8: Splitting and Combining

• The Custom Column dialog is fairly user-friendly. Double-


clicking a column in the “Available columns” list inserts the
M code reference to that column.

Data Type
• Using the Merge Columns command always generates a text
column. However, when using Add Column > Custom column,
you must manually specify the data type of the new column.

- 134 -
Section 9: Extracting text

Section 9: Extracting text

- 135 -
Section 9: Extracting text

x x x x x

- 136 -
Section 9: Extracting text

• The commands found in the Transform > Extract and Add


Column > Extract sub-menus are designed to extract
substrings from a single piece of text.
• The commands in the Transform Tab will modify the
selected column, the Add Column equivalent will retain the
original column and extract text into a new column.
The Team

First Characters
• Extract > First Characters returns the specified number of
characters from the start of a string and is equivalent to
Microsoft Excel's LEFT function.

- 137 -
Section 9: Extracting text

Last Characters
• The command Extract > Last Characters returns the specified
number of characters from the end of a string and is
equivalent to Excel's RIGHT function.

Range
• The command Extract > Range returns the specified number
of characters from the middle of a string and is equivalent to
Excel's MID function.
• When specifying the starting index, remember that, in the M
language, the first character position has an index of zero, not
one.

- 138 -
Section 9: Extracting text

- 139 -
Section 9: Extracting text

Text Between Delimiters


• The command Extract > Text Between Delimiters returns
the text between the two specified delimiters.
• The Text Between Delimiters dialog allows you to specify
different start and end delimiters.

• Advanced options allow you to specify whether to scan the


text from the start or end and which occurrence of the two
delimiters to target.

- 140 -
Section 9: Extracting text

- 141 -
Section 9: Extracting text

Text Before Delimiter


• The command Extract > Text Before Delimiter returns the
text before the specified delimiter.
• As we can see in this example, when using the Text Before,
After and Between delimiters commands, the delimiter can
contain multiple characters.

Replace Values
• The Replace Values command, which works in a similar way
to Find and Replace, can be used to iron out minor
discrepancies in the text being used as the delimiter.

- 142 -
Section 10: Transforming report data

Section 10. Transforming Report Data

- 143 -
Section 10: Transforming report data

Section
Summary

- 144 -
Section 10: Transforming report data

• One common attribute of data which is essentially a report


is rows of metadata preceding the actual data; for example,
the name, date and author of the report.
• Remove Rows > Remove Top Rows can be used to eliminate
these non-data rows.

• If data contains analysis rows embedded within the data,


such as sub-totals, Remove Rows > Remove Alternate Rows
can be used to remove these embedded rows.
• Specify the first row to remove, the number of rows to
remove and the number of rows to keep.

- 145 -
Section 10: Transforming report data

• When rows need to be removed, filtering is often an


option.
• Filtering is useful when the row entries are known in
advance.

- 146 -
Section 10: Transforming report data

Section
Summary

- 147 -
Section 10: Transforming report data

• Report data sometimes contains embedded headings.


• This means that some columns contain blanks instead of
data labels, preventing accurate data analysis.

• The Fill Down


command will copy
each sub-heading down
into the blank rows
below; but it will never
overwrite an entry,
since the command
only fills empty rows.

- 148 -
Section 10: Transforming report data

• However, the Fill Down command will only replace null


values, and Power BI does not treat blank entries as null.

• If rows are empty, prior to using Fill Down, we can use


Replace Values to insert nulls instead of blanks; entering
nothing in “Value to find”, and lowercase “null” in “Replace
with”.

- 149 -
Section 10: Transforming report data

• Once the rows below the embedded sub-headings contain


null values, Fill Down will produce the correct result.

- 150 -
Section 10: Transforming report data

Section
Summary

- 151 -
Section 10: Transforming report data

Pivoted Data

• One of the attributes which reporting data sometimes


contains is pivoting, where the elements within a category
have been separated out into columns like a pivot table.
• Pivoted data is difficult to analyze, since it has already been
separated into preset categories.

Unpivot Columns

• The Unpivot Columns command transposes the pivoted


columns into two new columns called “Attribute” and “Value”.
• The “Attribute” column contains the original column headings,
while the “Value” column contains the entries which were
underneath each of those headings.

- 152 -
Section 10: Transforming report data

Table.UnpivotOtherColumns

• The M syntax generated when the Unpivot Columns


command is used is Table.UnpivotOtherColumns, a function
which references the columns not being unpivoted.
• If you wish to generated the Table.UnpivotColumns
command, which explicitly references the columns to be
unpivoted, use the command Unpivot Only Selected
Columns.

- 153 -
Section 10: Transforming report data

Section
Summary

- 154 -
Section 10: Transforming report data

• When importing a background image, you can resize the


image to fit the Power BI canvas precisely by choosing Fit
from the Image Fit dropdown in the Format > Background
settings.

The Team

• Unlike calculated columns, which produce a result for each


row in a table, DAX measures display a result only when
added to one of the fields in a visual.

- 155 -
Section 10: Transforming report data

• The syntax for creating a measure is:


Name of Measure = Formula.
• Pressing Shift-Enter to split your formulas onto separate lines
makes them easier to read.
• Pressing Shift-Plus or Shift-Minus increases or decreases the
font size in the formula bar.

• The DAX REPT function generates the specified number of


instances of a text string.
• The syntax of the REPT function is:

REPT(<text>, <num_times>)

where <text> is the text to be repeated, either a literal string


or a text function
and <num_times> is the number of times you wish to repeat
the string.

- 156 -
Section 10: Transforming report data

• The DAX UNICHAR function returns the Unicode character


referenced by specified number.
• The syntax of the function is:
UNICHAR(number)
• The single argument (number) is the Unicode number that
represents the character.

• UNICHAR(9733) returns a filled star character.


• UNICHAR(9734) returns an unfilled star.
• BTW, to look up or search for Unicode characters, visit the
website unicode-table.com.

- 157 -
Section 10: Transforming report data

• The text font and background colours used in the table visual
can be changed on an individual column basis.
• In the Field Formatting section of the Format pane, choose a
column from the dropdown, then set the Font and
Background colours as required.

- 158 -
Section 11: Combining tables

Section 11: Combining Tables

- 159 -
Section 11: Combining tables

- 160 -
Section 11: Combining tables

• Append Queries performs the vertical stitching together of


data, combining rows of data from separate queries into a
single query.

• If the column structure of the input queries is not identical,


a typical first step is to remove the differences between the
columns, so that you have the same column headers and
the same data types in all queries.

- 161 -
Section 11: Combining tables

• The order of the columns in each query is unimportant, as


long as all columns are present.

• The Append Queries command will modify one of the


existing queries in creating the new one; whereas the more
useful Append Queries as New will create a completely
new query, leaving the original queries intact.

- 162 -
Section 11: Combining tables

• After using the Merge Queries As New command, it is


important to prevent the original queries from being loaded
into the data model.
• Right-click on each of the queries references in the Append
Queries as New dialog and choose the toggle command
“Enable Load” to deactivate loading.

- 163 -
Section 11: Combining tables

- 164 -
Section 11: Combining tables

• Merge Queries performs the horizontal stitching together


of data, combining columns of data from separate queries
into a single query.

• When using the Merge Queries command, the two queries


to be merged must have a common column containing the
same data values. The values in the common column are
used to marry up the rows of data in the two input queries.

- 165 -
Section 11: Combining tables

• The Merge Queries command will modify one of the


existing queries in creating the new one; whereas Merge
Queries as New will create a completely new query, leaving
the original queries intact.

- 166 -
Section 11: Combining tables

• When using the Merge Queries command, as well as


indicating the common column, you must specify a join
kind, very similar to join types used in relational databases.

• The Left table is simply the first table specified in the


Merge dialog, and the Right table is second table in the
dialog, the one selected from the dropdown.

- 167 -
Section 11: Combining tables

• Left Outer (the default) gives precedence to the first table:


all rows from the first table will be included in the output,
as well as matching rows from the second table.

• Right Outer is simply the mirror image of left-outer. All


rows from the second table will be included in the output,
as well as matching rows from the first table.

• With the Full Outer join kind, all rows from both tables will
be included in the output, with null values occurring
wherever there is no matching data in either table.

- 168 -
Section 11: Combining tables

• When the Inner join kind is specified, only rows where the
entry in the common column is present in both tables will
be included in the output.

• Left-Anti provides subtractive logic. Only those rows in the


first table which have no match in the second table will be
included in the output table.

• Right-Anti is the mirror image of left-Anti. Only those rows


in the second table which have no match in the first table
will be included in the output table.

- 169 -
Section 11: Combining tables

• The Merge Queries command does not import columns


from the subordinate table into the main table. Instead it
places the subordinate table in a binary column which you
must expand in order to select the columns to be imported.

- 170 -
Section 11: Combining tables

- 171 -
Section 11: Combining tables

• The Merge Queries Left-Anti option is useful for any kind of


data removal scenario.
• For example:
• Removing unsubscribed clients from a subscribers list
• Removing returned sales items from a sales table

• When using Merge Queries Left-Anti, the first table is the


main table and the second table is used to modify it by
removing all matching rows.

- 172 -
Section 11: Combining tables

• When using Merge Queries Left-Anti, there is no need to


expand the binary table column provided by Power Query
for pulling columns from the second table into the first
table. So, this extra column can simply be deleted.

- 173 -
Data Modelling

- 174 -
Section 12: Data Modelling Essentials

Section 12. Data Modelling Fundamentals

- 175 -
Section 12: Data Modelling Essentials

- 176 -
Section 12: Data Modelling Essentials

• Tables are data structures consisting of columns and rows.


• Tables are the most important element within the data
model, because they are the mechanism that allows data
to be imported into Power BI.

• Each data object retrieved and transformed in Power Query


is referred to as a query.
• When data is loaded into the data model, all queries are
converted into data tables.

- 177 -
Section 12: Data Modelling Essentials

• Fact tables contain data relating to a key business process.


• Dimension tables contain information which can be used to
categorize and describe the transactional information held
in fact tables.

• Calculated tables are dynamic tables generated in memory


through the use of DAX formulas.
• Calculated tables are stored permanently in the data
model, they can have relationship links to other tables and
their columns can be used in report visuals.

- 178 -
Section 12: Data Modelling Essentials

• Date tables, containing all the date-related columns to be


used within a data model, are probably the most
commonly-used calculated tables.
• The core DAX function used in generating a date table is
the CALENDAR function.

- 179 -
Section 12: Data Modelling Essentials

- 180 -
Section 12: Data Modelling Essentials

• Tables are composed of columns, with each column


defined to contain a specific type of data.
• The key data types are text, whole number (integer),
decimal number, fixed decimal number (currency),
date/time, date, time and boolean (true/false).

• Calculated columns can be created using either DAX or M,


though columns created using the M language are normally
referred to as computed columns.
• M language computed columns are created in the context
of a single query and can only reference columns within the
same query.
• DAX calculated columns are created in the context of the
entire data model and the column formulas can therefore
reference any objects within the data model, including
measures.

- 181 -
Section 12: Data Modelling Essentials

• The cardinality of a column is the number of distinct values


within the column.
• Columns with a high cardinality have correspondingly high
memory requirements.

- 182 -
Section 12: Data Modelling Essentials

- 183 -
Section 12: Data Modelling Essentials

• In Power BI, if a data model contains more than one table,


then relationships must be created between the tables.

• Unlike relational databases, in Power BI, the key function of


relationships is to enable the filtering applied to the
columns in dimension tables to propagate to the fact
table(s).

- 184 -
Section 12: Data Modelling Essentials

• Although Power BI supports all types of relationship, the


norm is to create many-to-one relationships between fact
and dimension tables, with the fact table on the many side
of the relationship and the dimension table on the one
side.

• In order to create a relationship between two tables:


• The two tables must have a common column.
• The common columns must contain the same type of
data.
• One table must have unique values in the common
column.

- 185 -
Section 12: Data Modelling Essentials

- 186 -
Section 12: Data Modelling Essentials

• Measures are the principal calculation used in Power BI to


aggregate and analyze the static data within tables.
• Measures produce dynamic results based on the visuals in
which they are displayed.

• Calculated columns are computed for each row of a table


and the results are saved in the data model.
• Measures are computed in memory, in the context of the
visuals on a page and produce constantly changing results
as the user interacts with the page.

- 187 -
Section 12: Data Modelling Essentials

- 188 -
Section 12: Data Modelling Essentials

• A hierarchy is a combination of two or more columns in the


same table which have a parent-child relationship to each
other.

• Hierarchies can be created either as formal objects which


are stored within the data model and available for re-use,
or they can be built directly within a visual as a one-time
structure.

- 189 -
Section 12: Data Modelling Essentials

• Whenever a hierarchy is placed on the axis of a visual,


Power BI’s interactive drill-down feature is automatically
enabled.

- 190 -
Section 12: Data Modelling Essentials

- 191 -
Section 12: Data Modelling Essentials

• With the exception of DirectQuery mode, Power BI is


designed to load data into the data model.

• The size of a Power BI PBIX file is largely determined by the


number of rows of data imported into the data model.

- 192 -
Section 12: Data Modelling Essentials

• It’s possible to see the contents of a Power BI file simply by


changing the file extension from .PBIX to .ZIP and then
looking inside the ZIP file.

• With a Power BI Pro license, the maximum file size allowed


for a PBIX file is 1 GB and this increases to a maximum of
10 GB for the top of the range Power BI Premium license.

- 193 -
Section 12: Data Modelling Essentials

• In the Power BI service, each account has a storage


allowance of 10 GB. This is a per user allocation, and each
PBIX file the user uploads eats into this allocation.
• In a premium capacity workspace, there is no per-user
storage, instead, there is a limit of 100 TB per Premium
capacity.

- 194 -
Section 13: Creating Fact and Dim Tables

Section 13. Creating Fact and Dim Tables

- 195 -
Section 13: Creating Fact and Dim Tables

- 196 -
Section 13: Creating Fact and Dim Tables

• When creating a database in SQL Server, the use of


schemas allows you to separate the different objects within
the database into logical groups.

• When connecting
to SQL Server from
Power BI, schemas
can also be used to
store views
optimized for use in
Power BI reporting.

- 197 -
Section 13: Creating Fact and Dim Tables

- 198 -
Section 13: Creating Fact and Dim Tables

• A database view is a virtual table generated by executing


an SQL statement.
• Each view is a subset of the original database and has the
same structure as a database table, consisting of rows and
columns.

• When importing data into Power from SQL Server, the most
efficient approach is to avoid connecting directly to the
tables in your relational database.
• Instead, create a series of views, each corresponding to
one of the tables which will be present in your data model.
• In Power BI, you then connect to these views rather than to
the original database tables.
• Connecting to views, rather than connecting to the
database tables protects your Power BI reports by creating
a buffer between your data models and any changes to the
database.

- 199 -
Section 13: Creating Fact and Dim Tables

• Placing the views that you have created for Power BI in a


special schema makes them easy to manage and facilitates
the granting of permissions to Power BI.

- 200 -
Section 13: Creating Fact and Dim Tables

- 201 -
Section 13: Creating Fact and Dim Tables

• Rather than simply using an existing user account to access


SQL Server data from Power BI, it is safer to create a login
and user explicitly for use in Power BI.

• Typical steps in creating a login for Power BI to access views


in a SQL Server schema are:
• Create a database role.
• Grant SELECT permission on the Power BI schema to
the database role.
• Create a login with a password.
• Create a user for the login.
• Add the user to the database role

- 202 -
Section 13: Creating Fact and Dim Tables

- 203 -
Section 13: Creating Fact and Dim Tables

• To connect to views prepared for Power BI, using a login


with minimum permissions, click on the Database category
and enter the username and password.
• The only objects to which you have access on the database
should be the views within the schema to which the login
gives you access.

• When connecting to SQL Server Views, Power BI still


automatically detects and creates relationships between
the imported tables.

- 204 -
Section 13: Creating Fact and Dim Tables

• The tables created by connecting to the views will each


have the schema name as a prefix.
• To quickly rename all tables, switch to Model view and, in
the Properties pane, remove the schema prefix from the
“Name” field.

- 205 -
Section 13: Creating Fact and Dim Tables

- 206 -
Section 13: Creating Fact and Dim Tables

• When connecting to SQL Server, the ideal workflow is to


create a series of views, on the database server; each of
which will become a table in the Power BI data model.
• However, if are no views available, and you have to connect
to the database, the Include Relationship Columns option
can be used to achieve similar results to the use of views.

• To access this feature, in the Get Data > SQL Server dialog,
expand the “Advanced Options” section and ensure that
the “Include Relationship Columns” checkbox is active.

- 207 -
Section 13: Creating Fact and Dim Tables

• When Include relationship columns is checked, Power BI


creates extra columns containing binary data which link to
each of the tables directly related to the current table.

• To access the columns in the table referenced by a


relationship column, click the Expand button and select the
columns to be imported into the current table.

- 208 -
Section 13: Creating Fact and Dim Tables

• Relationship columns provide access not just to the columns


in a related table but also to tables directly related to that
table, which can be accessed as nested relationship
columns.

- 209 -
Section 13: Creating Fact and Dim Tables

- 210 -
Section 13: Creating Fact and Dim Tables

• The Relationship Columns feature can only be used when


connecting to relational databases. However, the same
functionality can be achieved when connecting to any data
source by using the Merge Queries command.

• Using Merge Queries as New will create a completely new


query, leaving the original queries intact.

- 211 -
Section 13: Creating Fact and Dim Tables

• The Merge Queries command does not import columns


from the subordinate table into the main table. Instead it
creates the equivalent of a relationship column. Simply
expand this column then select the columns to be
imported.

- 212 -
Section 14: Date Tables

Section 14. Date Tables

- 213 -
Section 14: Date Tables

- 214 -
Section 14: Date Tables

• By default, Power BI creates


automatic date hierarchies for
every date field in the data
model.
• These hierarchies can be used
on the axes of visuals.

• The same feature also provides hierarchical dot-syntax


when referring to date columns; for example, Date.Year.

- 215 -
Section 14: Date Tables

• However, to support this feature, Power BI creates hidden


date tables, which add to the size of the data model, so, on
the whole, it’s best to deactivate this feature.

• To block this feature, click on Options and Settings >


Options; and, in the Global > Data Load category,
deactivate Auto Date/Time.

- 216 -
Section 14: Date Tables

- 217 -
Section 14: Date Tables

• The two methods of duplicating a query in Power Query are Right-


click > Duplicate and Right-click > Reference.

• Duplicating a query creates a snapshot copy of the original and


changes to the copy will not affect the original.
• Referencing a query creates a
linked copy of the original with no
mechanism for modifying the steps
in the original query. Changes to
the original will update the copy.

• The Reference command is a useful


method of creating queries to
generate the earliest and latest
date in the key date column of a
fact table. Simply reference the fact
table query then remove all
columns bar the key date column.

- 218 -
Section 14: Date Tables

• To avoid confusion and errors,


staging queries, used to support
and feed into main queries,
should not be loaded into the data
model.
• Queries to extract the earliest and
latest date in the key date column
of a fact table are examples of
staging queries.
• To prevent staging queries from
being loaded into the data model,
right-click the query and use the
toggle command “Enable Load” to
disable loading.

- 219 -
Section 14: Date Tables

• To generate the earliest and latest Date staging queries:

• Create a reference
to the main fact
table query.

• Right-click the key


Date column and
choose “Remove
Other Columns”,
leaving only the
date column in the
new query.

- 220 -
Section 14: Date Tables

• Right-click the Date


column and choose
“Date Filters > Is
Earliest/Is Latest” from
the filter dropdown.

• Use Add Column >


Custom Column to
create a column
containing the first day
of the year of the date
column, using the
#date function.

• Remove the original


date column, leaving
only the new one.

- 221 -
Section 14: Date Tables

• Change the data type of


the new date column to
whole number.

• Click Transform > Statistics


> Minimum/Maximum to
ensure that the query
returns a whole number.

- 222 -
Section 14: Date Tables

• To generate the custom column containing the first or last


day of the year, use the M language #date function which
takes three arguments: year, month and day.
• For the year argument of #date, use the M function
Date.Year, with the original date column from the fact table
as the single date argument.
• For earliest date, add “, 1, 1” to complete the #date
formula.
• For the latest date, add “12, 31” to complete the #date
formula.

- 223 -
Section 14: Date Tables

• Having extracted the


earliest and latest dates
from the main date
column of the fact table
and converted the results
to whole numbers, to
create the actual table,
click New Source > Blank
Query.

• Click Home > Advanced Editor and edit the definition of the
Source variable in the M code to read:
S ource L ist. N um bers E arliestDate, L atestDate E arliestDate 1

• The List.Numbers function generates a list of numbers and


takes two obligatory arguments: the start number and the
number of values to generate. (If the optional third argument,
increment, is omitted, the default increment is one.)

- 224 -
Section 14: Date Tables

• To convert the list of numbers generated by the


List.Numbers function into a single column date table:
• Convert the list into a table, by right-clicking the list heading
and choosing “To Table”.
• Convert the data type of the single column of the resulting
table to date.

• Having generated a single column date table and renamed


the column to “Date”, we can use Add Column > Custom
Column to create additional columns.
• Date.Year([Date]) for a “Year” column (whole number data
type).
• Date.QuarterOfYear([Date]) for the “Quarter” column (whole
number data type).
• Date.MonthName([Date]) for the “Month” column (text data
type).
• Date.Month([Date]) for the “Month Sort” column (whole
number data type).
• Date.Day([Date]) for the “Day” column (whole number data
type).

- 225 -
Section 14: Date Tables

- 226 -
Section 14: Date Tables

• To generate the earliest and latest year queries:

• Create a reference to the


main fact table query.

- 227 -
Section 14: Date Tables

• Right-click the key Date


column and choose
“Remove Other
Columns”, leaving only
the date column in the
new query.

• Convert the column from


a date to year using
Right-click > Transform >
Year > Year.

• Extract the earliest year


by clicking Transform >
Statistics >
Minimum/Maximum.

- 228 -
Section 14: Date Tables

• To filter the date table so that it maps to the earliest year and
latest year queries, choose Number Filters > Between from
the filter dropdown of the Year column of the imported date
table and enter any temporary numeric values in the “greater
than or equal to” and “less than or equal to” fields.

• Next, click on Home > Advanced Editor and, in the M code,


replace the two temporary numeric values with references to
the earliest year and latest year queries.

- 229 -
Section 14: Date Tables

DAX

- 230 -
Section 14: Date Tables

• The DAX CALENDAR function generates a single column


table containing an uninterrupted sequence of dates.
• It takes two arguments: start date and end date.

CA L E N DA R start date , end date

• Instead of supplying static dates for the CALENDAR


function, the DATE function can be used to compose start
and end dates consisting of the first day of the earliest year,
and the last day of the latest year, in the key date column.

• The DAX DATE function takes three arguments: year, month


and day.

DATE(<year>, <month>, <day>)


• For the year argument, the YEAR, MIN and MAX functions
can be used to extract the earliest and latest years from the
main date column in the fact table.

- 231 -
Section 14: Date Tables

• Having generated a single column date table we can use


Home > New Column to create additional columns.
• YEAR('Date Table'[Date]) for a “Year” column (whole number
data type).

• QUARTER('Date Table'[Date]) for the “Quarter” column (whole


number data type).

• FORMAT('Date Table'[Date], “MMMM”) for the “Month” column


(text data type).

• MONTH('Date Table'[Date]) for the “Month Sort” column (whole


number data type).

• DAY('Date Table'[Date]) for the “Day” column (whole number data


type).

• To ensure that the textual Month column is sorted using


the values in the numeric Month Sort column, highlight the
Month column and click Column Tools > Sort by Column >
Month Sort.

- 232 -
Section 14: Date Tables

- 233 -
Section 14: Date Tables

• The Mark as Date table command allows you to specify the


table you want your data model to use as its date table.
• It also prevents Power BI from automatically identifying
date columns and creating date hierarchies.
• To use the command, highlight the date table and click
Table Tools > Mark as Date Table.

• In the Mark as Date


Table dialog, select the
Date column from the
dropdown. If you have
created your own date
table, this will normally
be the only date
column displayed in the
list.

- 234 -
Section 15: Relationships

Section 15. Relationships

- 235 -
Section 15: Relationships

- 236 -
Section 15: Relationships

• The automatic detection of relationships is determined by


the Relationship settings in Options and Settings > Options >
Data Load.

• The option “Import relationships from data sources on


first load” will cause Power BI to detect relationships
which exist in databases and recreate them into the data
model.
• These relationships can later be modified but can be a
useful starting point.

- 237 -
Section 15: Relationships

• “Update or delete relationships when refreshing data” will


cause Power BI to detect relationships which exist in
databases and recreate them into the data model
whenever data is refreshed, overriding any manually
created relationships in the data model.
• This option is deactivated by default and this is normally
the best setting.

• Whereas the first two options apply to database sources,


the setting “Autodetect new relationships after data is
loaded” will cause Power BI to detect relationships
between any tables imported into the data model,
regardless of the type of data.
• This option is activated by default and can be a useful
time-saver.

- 238 -
Section 15: Relationships

• Even if autodetection is deactivated in the options and


settings, autodetection can still be performed by clicking
Home > Manage Relationships and then clicking the
Autodetect button, in the Manage Relationships dialog.

- 239 -
Section 15: Relationships

- 240 -
Section 15: Relationships

• When relationships have been


automatically created, it is a good idea
to monitor each relationship. This can
be done in model view by placing the
cursor over the line between two
related tables.
• The column used to create the
relationship will be highlighted in
each of the two tables.
• The direction of the arrow, in the
middle of the line joining the
tables, indicates the direction in
which it is possible for filtering to
propagate.
• The table on the one side of the
relationship has a figure 1 next to
the line.
• And the table on the many side
has an asterisk next to the line.

- 241 -
Section 15: Relationships

• To obtain full details of each relationship, Right-click on the


line joining two tables and choose “Properties” to display
the Edit Relationship dialog.

• To manually create a relationship, in Model view, drag the


matching column from the first table onto the matching
column in the second table. (The direction in which you
drag is unimportant.)

- 242 -
Section 15: Relationships

• After creating a relationship in this way, it is a good idea to


position the cursor over the line between the two tables to
verify that the relationship has been correctly created.

• The safest method of creating relationships is to use the


Create Relationship dialog.
• Click Home > Manage Relationships; then, in the Manage
Relationships dialog, click the New button.

- 243 -
Section 15: Relationships

• In the Create Relationship dialog, choose the table which you


want on the many side of the relationship (usually the fact
table) from the first dropdown.

The Team

• Choose the table which you want on the one side of the
relationship (usually a dim table) from the second dropdown.

- 244 -
Section 15: Relationships

• Click on the column in each table which will be used to create


the relationship.

• Set the “Cardinality” to “Many to one” and the “Cross filter


direction” to “Single” then click OK to create the relationship.

- 245 -
Section 15: Relationships

- 246 -
Section 15: Relationships

• In this section, we needed to create a relationship between


our Date Table and the Branch Targets fact table.
• However, Branch Targets did not contain a Date column; only a
Year column.
• We therefore had to engineer a Date column in the Branch
Targets table for use in the relationship.

• To engineer a date column in the Branch Targets table, in the


Power Query Editor, we used Add Columns > Custom
Columns to create a Date column by concatenating the first
of January (an arbitrary date) with the Year column.

- 247 -
Section 15: Relationships

• Since only string values can be concatenated in the M language,


we used the function Number.ToText to format the Year as a
string:

"1/1/" & Number.ToText([Year])

• When the command Add Column > Custom Column is used, the
data type of the resulting column is left undefined. It is therefore
important to remember to set the data type of the new column.

- 248 -
Section 15: Relationships

- 249 -
Section 15: Relationships

• When creating a relational database, it is possible to use


more than one column in each table as the primary or
foreign key, when no single column uniquely identifies each
row.
• This is normally referred to as a composite key.

• Composite keys are not allowed in Power BI. However,


there is a very simple workaround: all you need to do is to
create an extra column which concatenates the columns
which, when combined, uniquely identify each row in the
table.
• In our demo example, we needed to combine “PO
Number” and “Product ID” in the Sales table and “Purchase
ID” and “Product ID” in Purchase Orders.

- 250 -
Section 15: Relationships

• Composite keys are not allowed in Power BI. However,


there is a very simple workaround: all you need to do is to
create an extra column which concatenates the columns
which, when combined, uniquely identify each row in the
table.
• In our demo example, we needed to combine “PO
Number” and “Product ID” in the Sales table and “Purchase
ID” and “Product ID” in Purchase Orders.

• When creating a new column which concatenates two


existing columns, using Add Columns > Merge columns will
preserve the original columns, unlike Right-click > Merge
Columns, or Transform > Merge Columns, which remove
the original columns.

- 251 -
Section 15: Relationships

• When concatenating columns, using a separator, such as a


pipe character, between the two columns reduces the risk
of unforeseen results in the concatenated value.

• Unlike Add Columns > Custom Column, the Merge Column


command always produces a text column.

- 252 -
Section 15: Relationships

• Merge Columns is one of the Power Query commands


which cannot be query folded (i.e. converted to native SQL
and pushed back to the database server). So, if you wish to
take full advantage of query folding, you will need to use
Add Columns > Custom Column to create the concatenated
column.

- 253 -
Section 16: Hierarchies and Groups

Section 16. Hierarchies and Groups

- 254 -
Section 16: Hierarchies and Groups

- 255 -
Section 16: Hierarchies and Groups

• A hierarchy is a reference to a collection of table columns


which have a hierarchical relationship to one another.
• Hierarchies enable the use of the drilldown feature
available with many Power BI visuals.

• Although, by default, Power BI creates automatic date


hierarchies for every date field in the data model, it is best
to disable this feature and create your own date table.

- 256 -
Section 16: Hierarchies and Groups

• To create a hierarchy:
• In the Fields pane right-click on the parent field at the
top of the hierarchy and choose New Hierarchy.
• This creates a hierarchy object containing the parent
field.

• To populate the hierarchy, drag each of the required fields


onto the hierarchy object, in the appropriate order.

- 257 -
Section 16: Hierarchies and Groups

• The default name of a hierarchy


is the name of the top-level
field followed by the word
“Hierarchy”.
• To change the name, either
double-click the existing name
or right-click and choose
“Rename”.

• Hierarchies can be used on the axes of Power BI visuals, in


the same way as individual table columns.

- 258 -
Section 16: Hierarchies and Groups

• Adding a hierarchy to the axis of a visual automatically


activates Power BI’s drill-down feature.

- 259 -
Section 16: Hierarchies and Groups

- 260 -
Section 16: Hierarchies and Groups

• The shortcut method of creating a hierarchy is to drag the


field which is to occupy the first child onto the root parent
field, the field at the top of the hierarchy. Thus, in a standard
date hierarchy, we would drag “Quarter” onto “Year”.
• This action creates a hierarchy containing the top two levels.

• To complete the hierarchy


hierarchy, drag each of the required fields
onto the hierarchy object, in the appropriate order.

- 261 -
Section 16: Hierarchies and Groups

• Because the shortcut action is so easy to perform, users


who are new to Power BI often create hierarchies
unintentionally.
• To delete an unwanted hierarchy, right-click the hierarchy
object and choose “Delete”.

- 262 -
Section 16: Hierarchies and Groups

- 263 -
Section 16: Hierarchies and Groups

- 264 -
Section 16: Hierarchies and Groups

• To create a group, right-click on a column in the Fields pane


and choose New Group to display the Groups dialog.

The Team

• To create a group within the Group dialog, use Control-click


to select the appropriate values, click the “Group” button,
then enter a name for the group.

- 265 -
Section 16: Hierarchies and Groups

• To create a group within the Group dialog, use Control-click


to select the appropriate values, click the “Group” button,
then enter a name for the group.

• The option “Include Other Group”


Group”, if used,
used will cre
create an
extra group containing all those elements which you
yourself have not placed in a group.

- 266 -
Section 16: Hierarchies and Groups

• A group can be used on the axis of a visual, in the same way as a


column.

• For example, here we are using the “Product Range Category”


group on the axis of a bar chart.

• To add a group to a hierarchy, it is not possible to drag the group


onto the name of the hierarchy, as can be done with columns.
Instead, you need to right-click on the group and choose Add to
Hierarchy, which adds it to the bottom level; and then drag it to its
final position.

- 267 -
Section 16: Hierarchies and Groups

• Once added to a hierarchy, the group will behave in exactly


the same way as a parent column to the column from which
its values were derived and, when placed in a visual, you
can drill down from the group to the underlying child
column.

- 268 -
Section 16: Hierarchies and Groups

- 269 -
Section 16: Hierarchies and Groups

• The behavior of Power BI’s group feature is controlled by


the “Group Type”.
• When a group is created from a text column, the “Group
type” defaults to “List”; if the column is numeric, it defaults
to “Bin”.

• When creating a bin you can choose between two options


for “Bin Type”: “Size of Bins” or “Number of Bins”.
• If you choose “Size of Bins”, then you must specify the
“Bin size”, a fixed numeric value.
• If you choose “Number of Bins”, then you need to
specify the “Bin count”.

- 270 -
Section 16: Hierarchies and Groups

• Power BI also displays two automatic fields: “Min value”


and “Max value” which can be useful when deciding on the
bin size.

- 271 -
Section 16: Hierarchies and Groups

• To create a histogram showing frequency distribution; i.e.,


how often each different value in a set of data occurs, place
the group containing the bins on the axis of a clustered
column chart and the field on which the group is based in
the Values field.

- 272 -
Section 16: Hierarchies and Groups

- 273 -
Section 16: Hierarchies and Groups

• Creating “formal” hierarchy objects and using them on the


axes of visuals produces quick and consistent results.
• However, when creating a hierarchy, all of the hierarchy
fields must be in the same table.
• This is the chief benefit provided by the use of informal
hierarchies: the fields used to generate the hierarchical
behavior can be in an
any table within the data model.

• The main pros of using informal hierarchies are:


• They do not require the existence of a hierarchy in order
to add the drill-down functionality to a visual.
• They can use columns from any table in the data model.
• The main cons are:
• The hierarchical behaviour created on the visual cannot
be copied to another visual.
• The use of informal hierarchies encourages
inconsistency in report creation, since different report-
creators may use different versions of what is supposed
to be the same hierarchy.

- 274 -
Section 16: Hierarchies and Groups

• To create an informal hierarchy, simply drag the fields into


the desired axis of the visual in the logical hierarchical
order.

- 275 -
DAX Formulas

- 276 -
Section 17: Calculated Columns

Section 17. Calculated Columns

- 277 -
Section 17: Calculated Columns

DAX

- 278 -
Section 17: Calculated Columns

• DAX stands for Data Analysis Expressions.


• It is used in three Microsoft Products:
• Power BI Desktop
• Analysis Services
• And Power Pivot, in Excel.
The Team
• DAX can be used to add three types of calculation to the
Power BI data model:
• Calculated columns
• Calculated tables
• And measures.

• A calculated column is one which is dynamically created by


entering a DAX formula.
• However, calculated columns behave in much the same
way as the inherent data columns within a table.
• You write a DAX formula to define how the column will be
created; that formula is applied to every row within the
table; and an entry is generated within the calculated
column.
• But this dynamic data is then stored in the data model
along with the static data.

- 279 -
Section 17: Calculated Columns

• When creating calculated columns and measures, a


formula is created which will generate a single, scalar,
value.
• By contrast, when creating a calculated table, you need to
write an expression which will generate a table, rather than
a single value.
• The CALENDAR function is an example of a DAX function
which can be used to generate a table as a opposed to a
scalar value.

• Measures, by contrast, do not generate a result which is


stored permanently in the data model.
• Instead, measures produce results dynamically when they
are attached to the values areas of visuals.
• Measures are also very versatile: the same measure can
produce many different results within the same report,
simply by being placed in different visuals.
• Because of this, measures should be regarded as the
default calculation type in Power BI reporting and should
be used in preference to calculated columns whenever
possible.

- 280 -
Section 17: Calculated Columns

DAX

- 281 -
Section 17: Calculated Columns

• Columns created using the M language are normally


referred to as computed columns.
• M language computed columns are created in the
context of a single query and can only reference
columns within the same query.
• When connecting to database servers, the creation of M
language columns can be query folded; i.e. converted to
SQL and pushed back to the server.
• Columns created using DAX are normally referred to as
calculated columns.
• DAX calculated columns are created in the context of
the entire data model and the column formulas can
therefore reference any objects within the data model,
including measures.
• The creation of calculated columns will only be query
folded when connecting to database servers in
DirectQuery mode.

- 282 -
Section 17: Calculated Columns

• To create a new column:


• Switch to data mode, so you can easily review existing
table columns.
• In the fields pane, select the table to which you want to
add the new column.
• Click New Column in either the Home or Table Tools Tab.

• The pattern for creating a new column is:


Column_Name = Formula.
• When writing the formula, using auto-completion helps to
avoid errors:
• Start typing an object name, then wait for the actual
name to appear in the auto-complete list.
• When the name appears and is highlighted, press Tab to
insert it into the formula.

- 283 -
Section 17: Calculated Columns

• As in many other environments, in DAX, the ampersand is


used for concatenation.

• In the M language, columns can be concatenated by right-


clicking the columns and using the “Merge Columns”
command.
• In the Merge Columns dialog, a separator can be inserted
between the columns.

- 284 -
Section 17: Calculated Columns

• The Merge Columns command cannot be query folded; so,


when connecting to SQL Server, use the Add Column >
Custom Column command instead.
• To combine columns, double-click to insert the columns to
be merged and use the “&” character for concatenation.

- 285 -
Section 17: Calculated Columns

* 1

- 286 -
Section 17: Calculated Columns

• The RELATED function is used to retrieve a related value


into a table on the many side of a relationship from a table
on the one side of the relationship.
• The function returns a result for each row within a table
and is, therefore, normally used when creating calculated
columns.
• However, as we will see later when we discuss measures, it
can also be used in measures with iterator functions such
as SUMX.

• As the name suggests, RELATED is not simply a lookup


function and will only work if a many-to-one relationship
exists with the other table.

- 287 -
Section 17: Calculated Columns

• In our example, we used the RELATED function in the


scenario where we needed to created a “formal” hierarchy
consisting of columns in different dimension tables:

Branches[Country]
Branches[Branch]
Staff[Account Handler]
Clients[Customer Name]
• However, to create a hierarchy, all of the required columns
must be in the same table.
• So, the logical solution is to recreate all of the columns
required for the hierarchy in the Sales table, the fact table
which has many-to-one relationships with the Branches,
Staff and Clients tables.
• We therefore created four new
columns in the Sales table,
using the formulas:

Country =
RELATED(Branches[Country])

Branch =
RELATED(Branches[Branch])

Account Handler =
RELATED(Staff[Account Handler])

Customer Name =
RELATED(Clients[Customer Name])

- 288 -
Section 17: Calculated Columns

• Having created, or rather recreated, all of the columns


required for the hierarchy in the Sales table, we are able
to create our hierarchy object; because we now have all
of the columns in the same table.

- 289 -
Section 17: Calculated Columns

* 1

- 290 -
Section 17: Calculated Columns

• The RELATEDTABLE function is used to retrieve the related


values into a table on the one side of a relationship from a
table on the many side of the relationship.
• Unlike the RELATED function, which returns a single result
for each row within a table, the RELATEDTABLE function is
designed to retrieve multiple matching rows for each row
in a table.
• This means that the result produced by the RELATEDTABLE
function needs to be aggregated in order to produce a
single, scalar value for each row in a table.
• Just as RELATED requires a many-to-one, the
RELATEDTABLE function requires a one-to-many
relationship with the table from which values are being
retrieved.

- 291 -
Section 17: Calculated Columns

• In our example, we wanted to add a calculated column into


the Products table to show the quantity of each product
sold.
• The simple formula Units Sold = SUM(Sales[Quantity])
simply inserts the total units sold on each row of the new
column.

• However, by using the RELATEDTABLE function, we can


ensure that the values being aggregated to produce the
total for each row of the products table are only the
matching ones.
• And, since RELATEDTABLE is not a column reference, we use
SUMX rather than SUM.

- 292 -
Section 17: Calculated Columns

- 293 -
Section 17: Calculated Columns

• Measures are the most efficient DAX calculation and should


be used in preference to calculated columns whenever
possible.
• However, measures can only be placed in the values field of
visuals, not on the axis. So if you are creating a calculation
whose result needs to be displayed on a chart axis, you will
need to create a calculated column, not a measure.

• In this section, we took the scenario where we want to


assign each product with a popularity rating: Fast Moving,
Popular, Average or Slow Moving.
• However, because we want to display these options on the
axis of a chart, we need to create a calculated column
rather than a measure.

- 294 -
Section 17: Calculated Columns

• Since we want to base the popularity on units sold, we begin


by declaring a variable to hold the result of dividing units
sold, for each product, by average units sold, across all
products.

• We then use a nested IF statement to test the value


retrieved by our variable and return the appropriate
popularity rating.

- 295 -
Section 17: Calculated Columns

• Now that we have a calculated column, rather than a


measure, we can add it to the axis of a visual with no
problem.

- 296 -
Section 18: Calculated Tables

Section 18. Calculated Tables

- 297 -
Section 18: Calculated Tables

- 298 -
Section 18: Calculated Tables

• The CALENDAR and CALENDARAUTO functions are both


used to generate a single column table containing a series
of dates.
• The key difference between CALENDAR and
CALENDARAUTO is that with CALENDAR, a start and end
date must be specified; while, with the CALENDARAUTO,
the start and end dates are deduced automatically by
examining the data model.
• This usually means that it is safer to use CALENDAR rather
than CALENDARAUTO.
• As we saw in “Section 14: Date Tables”, The DAX CALENDAR
function generates a single column table containing an
uninterrupted sequence of dates and takes two arguments:
<start_date> and <end_date>.
• The DATE function can be used to compose a <start_date>
and <end_date> consisting of the first day of the earliest
year, and the last day of the latest year, in the key date
column.

- 299 -
Section 18: Calculated Tables

• The CALENDARAUTO function takes a single argument:


fiscal_year_end_month.
• This optional parameter allows you to specify the month in
which the fiscal calendar ends by entering a number
between 1 and 12.
• If no value is supplied, the default is 12, meaning that the
year runs from January to December.

• In large data models, the results of CALENDARAUTO can be


fairly unpredictable, because the function examines the
entire data model in deciding on the earliest and latest
dates.
• Thus, for example, if the data model contains a Date of
Birth field and the oldest person in the dataset was born in
1955, our Date column in the data table would start on 1st
January 1955.

- 300 -
Section 18: Calculated Tables

- 301 -
Section 18: Calculated Tables

- 302 -
Section 18: Calculated Tables

• To define a variable, use the keyword VAR followed by an


equal sign, followed by the expression to be assigned to the
variable.
• To end variable definition and begin the formula proper,
use the keyword RETURN. Thus the basic syntax is:
Formula =
VAR Variable1 = Expression1
VAR Variable2 = Expression2
RETURN

• The ADDCOLUMNS function adds columns to the specified


table.
• The function takes three obligatory arguments:
• The table to be modified
• The name of the column to be added to the table
• And the expression to be used to generate the
additional column.
• Arguments two and three can be repeated as many times
as necessary to add further columns to the specified table.

- 303 -
Section 18: Calculated Tables

• Since the CALENDAR function returns a table, it can be


used as the first argument of the ADDCOLUMNS function.
• For greater readability, we can place the CALENDAR
function inside a variable and then use the variable name
as the first argument of ADDCOLUMNS.
• For the remaining arguments of ADDCOLUMNS, we use
the name of each additional column and the expression
needed to generate it.

- 304 -
Section 18: Calculated Tables

- 305 -
Section 18: Calculated Tables

• Table formulas are often used not to generate tables within


the data model but, rather, to generate virtual tables inside
a measure formula whose columns are aggregated within
the formula itself.
• The ability to temporarily create these virtual tables as
actual tables within the data model is a useful debugging
and testing tool.

• The SUMMARIZE function creates a summarized version of


a table by grouping the table according to the specified
columns.
• It then allows you to add additional aggregation columns to
the summarized table.

- 306 -
Section 18: Calculated Tables

• Within our data model, we can use the SUMMARIZE function


to create a table which summarizes the sales table and
shows the total number of units ordered on each invoice.

• In our example, we only need to use the four obligatory


arguments of the SUMMARIZE function. (The second, third
and fourth arguments can be repeated as many times as
necessary.)
• The table to be summarize: “Sales”.
• The column to be used for grouping: “Invoice Number”.
• The name of the column to be added to the summarized
table: “Units Sold”.
• The expression to be used to generate the additional
column: “SUM(Sales[Quantity]”).

- 307 -
Section 18: Calculated Tables

- 308 -
Section 18: Calculated Tables

• The FILTER function creates a subset of a table containing


only those rows which satisfy certain criteria and is most
commonly used as one of the arguments to other functions
within a measure formula.
• It takes two arguments: the table to be filtered and the
filter expression.

• The second argument of the FILTER function, the filter


expression, must be a Boolean statement; one which can
only evaluate to TRUE or FALSE.
• The most common Boolean expressions have the generic
format:

Column Operator Value


• For example:
Sales[Quantity] > 0
• or
Branches[Branch] = “London“.

- 309 -
Section 18: Calculated Tables

• Within our data model, we can use the FILTER function to


find all those sales which took place on the weekend.
• However, since we have no column which indicates the day
on which each sale took place, we need to use the
WEEKDAY function as part of our filter expression.

• The WEEKDAY function returns a number between 1 and 7


identifying the day of the week.
• It takes two arguments: the date and the return type (1 for
week commencing on Sunday and 2 or 3 for week
commencing on Monday).

- 310 -
Section 18: Calculated Tables

• To calculate weekend sales, we can therefore use the


FILTER function, with the Sales table as the first argument.
• For the second argument, we use the WEEKDAY function,
with the “Invoice Date” column as the first argument and
“2” as the second argument, indicating that the week starts
on Monday.
• Thus, if the number returned by WEEKDAY is greater than
5, we have a weekend sale.

- 311 -
Section 19: Measures

Section 19. Measures

- 312 -
Section 19: Measures

- 313 -
Section 19: Measures

• Unlike calculated columns, measures do not generate a


result which is stored permanently in the data model.
Instead, measures produce results dynamically when they
are attached to the values areas of visuals.
• They are also very versatile; in that the same measure can
produce many different results within the same report,
simply by being placed in different visuals.

• When calculating key metrics in Power BI, it makes sense to


start by basic measures which perform simple
aggregations.
• These basic measures can then be referenced repeatedly in
other, more complex measures.

- 314 -
Section 19: Measures

• To refer to a table in a DAX formula, simply enter the name


of the table. However, if the table name contains a space,
then the name must be enclosed in single quotes.
For example:
'Branch Targets'
• To refer to a column, enter the name of the table,
immediately followed by the column name enclosed in
square brackets.
For example:
Sales[Discount]
• To refer to a measure, enter the name of the measure
enclosed in square brackets. To avoid confusion with
column references, avoid preceding the name with a table
reference.
For example:
[Revenue] NOT Sales[Revenue]

• Since the Power BI data model is built


on a framework of tables and
relationships, measures must be stored
in one of the tables in the data model.
• However a measure never become a
structural part of any particular table
and can be moved freely between
tables.
• Creating one or more separate tables
purely for storing measures makes it
easy to manage them as they become
more numerous.

- 315 -
Section 19: Measures

• To create a table for storing measures in Power BI Desktop,


click Home > External Data > Enter Data, enter a table
name and click Load.
• The word “Measures” is a reserved word, so a convenient
table name is “_Measures”.

• Once you have added at least one measure to the table,


you can then delete the default column it contains.
• Additionally, once you have deleted the data column, if you
hide then show the Fields pane, the table icon changes to a
calculator, distinguishing it from the data tables.

- 316 -
Section 19: Measures

• Power BI measures are used to populate the Values fields


of visuals.
• Some measures are very simple, consisting of a single
aggregation using a function such as SUM or AVERAGE.

• It is also possible to add a table column directly to the


Values field of a visual, without creating a measure, and
obtain the same result. This is called an implicit measure.
• However, although you can specify the DAX function used in
the implicit measure, you have no way of editing the
underlying DAX formula or referencing the measure
elsewhere.

- 317 -
Section 19: Measures

• When populating the Values fields of visuals, the best


practice is to create a measure to obtain the result and add
the measure to the visual, no matter how simple the
formula.
• This makes it easy to monitor and modify all calculations
and these simple measures can be referenced repeatedly
by more complex measures.

- 318 -
Section 19: Measures

- 319 -
Section 19: Measures

• The DAX language contains a series of functions which are


clones of standard statistical functions, such as SUM and
AVERAGE, but which end in an X; for example, SUMX and
AVERAGEX.

• The standard version of these versions, without the “X”,


can only take a literal column reference as the single
argument; and can, therefore, only be used to aggregate a
single column.

- 320 -
Section 19: Measures

• By contrast, the version of the functions which end in “X”


take two arguments: a table and an expression. They then
iterate through every row of the table, evaluating the
expression, and then aggregate all the results.

• Thus to calculate Units Sold, we can simply use the SUM


function; since units sold is just the sum of the Quantity
column.
• However, to calculate the total Revenue, we need SUMX,
since we must multiply Quantity by Units Sold then
subtract one minus Discount.

- 321 -
Section 19: Measures

• The SUMX function iterates through the rows of the Sales


table and computes the expression Sales[Quantity] *
Sales[Unit Price] * (1 – Sales[Discount]).
• The result of each computation is stored in the rows of a
virtual column, in memory, and the result of the formula is
the SUM of all the rows in this virtual column. .

• In our next example, we need to calculate the average time


taken by clients to pay invoices.
• To do this, we need to take the average difference between
Invoice Date and Payment Date; we therefore need
AVERAGEX rather than just AVERAGE.

- 322 -
Section 19: Measures

• The DATEDIFF function can be used to compute the


difference between the Invoice Date and Payment Date
columns.
• The function takes three arguments: start date, end date
and interval (the time units to be used; in our case DAY).

• The AVERAGEX function iterates through the rows of the


Sales table, using the DATEDIFF expression to compute the
difference between invoice and payment date.
• The result of each computation is stored in the rows of a
virtual column, and the result of the formula is the
AVERAGE of all the rows in this virtual column.

- 323 -
Section 19: Measures

- 324 -
Section 19: Measures

• In this section, we created DAX measures to calculate


three key metrics:
• The percentage of target revenue achieved
• The gross profit margin
• And the comparison between our gross margin and the
industry average.

• Our first metric will calculate the percentage of target


revenue achieved and will be displayed in a card visual on
the first page of our report.

- 325 -
Section 19: Measures

• In keeping with the philosophy of creating building-block


measures, we first create a measure which calculates the
total revenue target.
• Since we are aggregating a single column, we use the SUM
function, rather than SUMX.

• Now that we have both a [Revenue] and a [Revenue Target]


measure, we simply subtract [Revenue Target] from
[Revenue] and divide the result by [Revenue Target] to
obtain the percentage variance between actual and target
revenue.
• Using the DIVIDE function, instead of the division operator
allows us to replace any potential errors with a zero.

- 326 -
Section 19: Measures

• Next, we need to work out our Gross Profit and Gross


Margin % figures.
• They will also both be displayed in card visuals on the first
page of our report.

• To calculate our Gross Profit, we must first work out the


total cost of each item sold.
• We can then subtract Total Cost from Revenue to obtain
the Gross Profit.

- 327 -
Section 19: Measures

• The Total Cost follows a similar pattern to the Revenue


calculation, using the SUMX function to aggregate an
expression evaluated on every row of the Sales table.

• However, this time, we need to use the RELATED function,


because we are multiplying the quantity sold by the
appropriate unit price in the Purchases table.

- 328 -
Section 19: Measures

• To improve the readability of our Gross Profit formula, we


place the Total Cost calculation inside a variable called
TotalCost. Then we simply subtract our TotalCost variable
from Revenue.

• Now that we have both Revenue and Gross Profit, we can


simply divide Gross Profit by Revenue to obtain the Gross
Margin percent, again using the DIVIDE function to replace
any potential errors with a zero.

- 329 -
Section 19: Measures

• Next, we need to work out the percentage variance


between our gross margin and the industry average.
• This will be displayed in the final card visual on the first
page of our report.

• To simulate the appropriate industry margin intel for our


industry (which, in reality, we would need to pay for), we
used a table on the website pages.stern.nyu.edu.

- 330 -
Section 19: Measures

• To improve the readability of our industry margin variance


formula, we place the industry average margin calculation
inside a variable called IndustryAverage.
• We then subtract IndustryAverage from [Gross Profit Margin]
and divide the result by IndustryAverage to obtain the
percentage variance between our margin and the industry
average.

- 331 -
Section 19: Measures

- 332 -
Section 19: Measures

• We have already discussed the use of calculated tables in


Power BI.
• Calculated table formulas are often used to generate
virtual tables inside a measure formula whose columns are
aggregated within the formula itself.
• These virtual tables can be as complex as required.
• In this section, we took an example which we created in
“Section 18: Calculated Tables”, using SUMMARIZE
function.

• The formula which produced the calculated table can


simply be copied and used as the argument within another
function inside a measure.

- 333 -
Section 19: Measures

• The SUMMARIZE function creates a summarized version of


a table by grouping the table according to the specified
columns.
• It then allows you to add additional aggregation columns to
the summarized table.

• The measure we want to create is the average order value


per invoice. However, we can’t use the AVERAGE function,
because the column is in a virtual table produced using the
SUMMARIZE function, so we need AVERAGEX.

- 334 -
Section 19: Measures

• If we use the AVERAGE function, we must use a static data


column as the single argument; but, if we use AVERAGEX,
we can use our SUMMARIZE formula as the table argument
and the Revenue column of the SUMMARIZE table, as the
expression argument.

1
2
3
4

• For the outer AVERAGEX function:


1.
1 SUMMARIZE becomes the first argument of the AVERAGEX
function.
2.
2 The [Invoice Revenue] column created within the
SUMMARIZE statement becomes the expression argument.
• For the inner SUMMARIZE function, we only need to use
the four obligatory arguments:
1.
1 The table to be summarize: “Sales”.
2.
2 The column to be used for grouping: “Invoice Number”.
3.
3 The name of the column to be added to the summarized
table: “Invoice Revenue”.
4.
4 The expression to be used to generate the additional
column: our existing [Revenue] measure.

- 335 -
Section 20: The CALCULATE Function

20. The CALCULATE Function

- 336 -
Section 20: The CALCULATE Function

- 337 -
Section 20: The CALCULATE Function

• When you create a calculated column, the DAX formula


used to create the column will be evaluated for each row of
the table in which the column is being created.

• By contrast, filter context normally applies to measures


which have been placed within visuals on the report page.
• The filter context is the combined set of filters, imposed by
the user interface, which impact the result produced by a
DAX calculation.

- 338 -
Section 20: The CALCULATE Function

• The CALCULATE function allows you to change the context in


which a DAX calculation takes place.
• It takes two or more arguments: the expression to be
evaluated (often a reference to an existing measure), and one
or more filter expressions.

• Although the filter expression argument(s) of the CALCULATE


function can take many different formats, the result is always
that the rows of the table on which the calculation is being
performed are being filtered.
• And the filter expressions take precedence over the filtering in
place on the report page:
• If there is an existing filter context matching one specified by
CALCULATE, it is overridden.

• If there is no existing matching filter context, then a new filter context


is added to the page.

- 339 -
Section 20: The CALCULATE Function

- 340 -
Section 20: The CALCULATE Function

• The simplest format that a CALCULATE filter expression


argument can take is a Boolean statement; one which can
only evaluate to TRUE or FALSE.
• The most common Boolean expressions have the generic
format:

Column-Operator-Value
• For example:
Sales[Quantity] > 0
• or
Branches[Branch] = “London“.

- 341 -
Section 20: The CALCULATE Function

• In our first example, we use the CALCULATE function to help


calculate the % of London sales performed by each branch.
• Using CALCULATE, we are able to create a version of our
Revenue calculation which only returns the London revenue,
using the filter expression: Branches[Branch] = “London".

• If we place the London Revenue measure in a table visual,


it returns the revenue figure for the London branch,
ignoring the branch filter on every row of the table and
overriding the filter context on the Branch column.

- 342 -
Section 20: The CALCULATE Function

• To obtain the % of London revenue achieved by each


branch, we simply need to modify our measure and divide
the London revenue by the original [Revenue] measure.

• When performing division in DAX, the DIVIDE function


provides an optional alternate result argument which will
replace potential errors resulting from division by zero.
• If the alternate result argument is not specified, errors will
be replaced by BLANK().

- 343 -
Section 20: The CALCULATE Function

- 344 -
Section 20: The CALCULATE Function

• Boolean expressions used as the filter argument of the


CALCULATE function must have the basic format: Column-
Value-Operator; for example Sales[Quantity] > 0.
• Boolean statements which detract from this basic format,
for example, a statement comparing one table column with
another, will generate an error.

• More complex Boolean statements must be wrapped inside


the FILTER function.

- 345 -
Section 20: The CALCULATE Function

• The FILTER function evaluates the Boolean expression


against every row of a specified table.

• The FILTER function takes two arguments: the table to be


filtered and the filter expression.
• However, because the table is specified, the filter
expression can be more complex than the basic Column-
Value-Operator.

- 346 -
Section 20: The CALCULATE Function

- 347 -
Section 20: The CALCULATE Function

• The ALL function clears filters on a table, column or


columns, enabling you to perform calculations on all the
rows in a table.
• It takes as arguments a reference to a table, a single
column or a list of columns.

• In our report, we need to use the ALL function as the filter


expression inside a CALCULATE statement, so that we can
return the revenue for all countries, ignoring filters on the
Country and Branch columns.

- 348 -
Section 20: The CALCULATE Function

• We can then use our Revenue All Countries measure in the


Maximum data field of a gauge visual, with the Revenue in
the (Actual) Value field.

• The Revenue measure can be filtered by Country or Branch;


but the Revenue All Countries measure ignores these filters
and returns the overall revenue.

- 349 -
Section 21: DAX Time Intelligence Functions

Section 21. DAX Time Intelligence Functions

- 350 -
Section 21: DAX Time Intelligence Functions

- 351 -
Section 21: DAX Time Intelligence Functions

• The examples in this section all focus on modifying the


[Revenue] measure which we created back in “Section 19:
Measures”.

- 352 -
Section 21: DAX Time Intelligence Functions

• The total year to date function, TOTALYTD, evaluates an


expression in the context of the period of the year which
has already passed.
• For example, on a chart with months on the axis, you might
display the total year to date instead of, or alongside, the
monthly total.

• The TOTALYTD function takes two obligatory, and two


optional, parameters:
• < Expression> An expression returning a scalar value
(usually a measure)
• < Dates> A date column (usually the date
column of your date table)
• < Filter> An optional additional filter to apply to
the current context
• < Year_End_Date> An optional string specifying the
year end (default is 31st December).
• The two related functions TOTALQTD and TOTALMTD
work in a similar way.

- 353 -
Section 21: DAX Time Intelligence Functions

• To calculate the Revenue year-to-date using the TOTALYTD


function, we would use the following DAX formula.

• However, the TOTALYTD function is not really scalable; and


this is why using a combination of CALCULATE AND
DATESYTD is usually preferred.

• The dates year to date function, DATESYTD, Returns a table


containing a column of the dates for the period of the year
which has already passed.
• It is used in conjunction with the CALCULATE function:
CALCULATE evaluates an expression and DATESYTD
specifies the period for which the expression is to be
evaluated.

- 354 -
Section 21: DAX Time Intelligence Functions

• The DATESYTD function takes one obligatory, and one


optional, parameter:
• < Dates> A date column (usually the date column of your
date table)
• < Year_End_Date> An optional string specifying the year end
(default is 31st December).
• The two related functions DATESQTD and DATESMTD work in
a similar way.

• To calculate the Revenue year-to-date using the CALCULATE


and DATESYTD functions, we would use the following DAX
formula.

A dditional filte rs

• The result is the same. However, the CALCULATE and


DATESYTD version of the formula is endlessly scalable;
since you can add any number of additional filter
statements to the basic formula.

- 355 -
Section 21: DAX Time Intelligence Functions

- 356 -
Section 21: DAX Time Intelligence Functions

• The SAMEPERIODLASTYEAR function is used to generate a


filtered table containing a column of dates one year earlier
than the specified date column. It has the syntax shown
below.
• The function takes one obligatory parameter:
• < Dates> A date column (usually the date column of
your date table)

• Since the SAMEPERIODLASTYEAR function returns a table,


rather than a scalar value, it is normally used in conjunction
with the CALCULATE function.
• For example to work out the revenue for the previous year,
we would use the following formula.

• We can then refer back to this [Revenue LY] measure in


some of our other measures.

- 357 -
Section 21: DAX Time Intelligence Functions

• Thus to work out the revenue year-on-year change, as an


absolute figure, we could use the following formula.
• Thus to work out the revenue year-on-year change, as an
absolute figure, we could use the following formula.

• And to remove the misleading figure displayed for the first


year of the period, we could change the formula to an IF
• And to remove the misleading figure displayed for the first
statement, returning a blank if the [Revenue LY] measure is
year of the period, we could change the formula to an IF
itself blank.
statement, returning a blank if the [Revenue LY] measure is
itself blank.

- 358 -
Section 21: DAX Time Intelligence Functions

• In contrast to the PARALLELPERIOD function,


SAMEPERIODLASTYEAR does not control the period length.
Rather, it preserves the original period length and simply
moves it back one year in time.
• Thus, if we use SAMEPERIODLASTYEAR in conjunction with
CALCULATE, we will get the following results.

Current Period Resulting Period

2020 SAMEPERIODLASTYEAR 2019

July 2020 SAMEPERIODLASTYEAR July 2019

7th July 2020 SAMEPERIODLASTYEAR 7th July 2019

• With the resulting period always the same duration as the current period.

- 359 -
Section 21: DAX Time Intelligence Functions

- 360 -
Section 21: DAX Time Intelligence Functions

• Unlike TOTALYTD and DATESYTD, the SAMEPERIODLASTYEAR


function has no equivalents for previous quarter or month.
• However, we can calculate these periods using the Swiss
army knife of time intelligence functions: DATEADD.

• DATEADD allows you to perform a calculation in a date


context which is offset by any number of year, quarters,
months or days, either in the past (negative offset) or the
future (positive offset).

• The DATEADD function takes three obligatory parameters:


• < Dates> A date column (usually
the date column of your date table)
• <Number_of_Intervals> The number of units to
add to or subtract from the dates
• < Interval> The time unit to be used:
Year, Quarter, Month or Day.

- 361 -
Section 21: DAX Time Intelligence Functions

• To calculate the previous year revenue using DATEADD, we


would use the following formula.

• This gives the same result as using SAMEPERIODLASTYEAR


but is much more flexible.

• Thus, for example, the DATEADD formula can easily be


changed to any period relative to the current period; for
example showing last quarter revenue, rather than last year.

- 362 -
Section 21: DAX Time Intelligence Functions

- 363 -
Section 21: DAX Time Intelligence Functions

• The PARALLELPERIOD function returns a table that contains a


single column of dates representing a period parallel to the dates
in the specified dates column, with the dates shifted a given
number of intervals either forward or back in time.

• It takes the same three obligatory parameters as the DATEADD


function:

• < Dates> A date column (usually the date column of your date
table)

• <Number_of_Intervals> The number of units to add to or subtract


from the dates

• < Interval> The time unit to be used: Year, Quarter, Month or Day.

• The PARALLELPERIOD controls the period length; it ignores the


original period length and always returns a period of the length
specified by the <interval> argument of the function.

• Thus, if we specify -1 as the <number_of_intervals> and YEAR as


<interval>, we will get the following results.
Resulting
Current Period
Period
2020 PARALLELPERIOD 2019

July 2020 PARALLELPERIOD 2019

7th July 2020 PARALLELPERIOD 2019

• With the resulting period always one year in duration, as


specified by the <number_of_intervals>.

- 364 -
Section 21: DAX Time Intelligence Functions

• The result returned


by PARALLELPERIOD
is not usually of
much use on its
own, since it will
usually be the same
for all entries within
a given period.

• However, it is a useful
component in ratio
calculations.
• For example, we could
use calculate the
percentage proportion
of last year’s total
represented by each
month’s total in the
current year by dividing
[Total Revenue] by the
result returned using
PARALLELPERIOD in
conjunction with the
CALCULATE function.

- 365 -
Section 21: DAX Time Intelligence Functions

- 366 -
Section 21: DAX Time Intelligence Functions

• A running total is normally calculated from the very first date in


the dataset and, unlike a year to date total, and its variants, it
does not reset at the end of any periods.

• We can work out the running total revenue by using the


CALCULATE function in conjunction with two filters: firstly, the ALL
function which allows us to retrieve all rows in our dates table,
irrespective of the filter context.

• And, secondly, a Boolean test to see whether each date in the


resulting table is less than the latest date in the current filter
context.

• The formula to return


the running total for
revenue, for all dates
within our data model,
uses the CALCULATE
function, with [Total
Revenue] as the
<expression>
argument.

• For the <filter>


argument of
CALCULATE, the FILTER
function is then used to
limit the rows of the
date table to those
where the date is
earlier than the latest
date in the current
period.

- 367 -
Section 21: DAX Time Intelligence Functions

• The result returned by the Running Total formula


continues to increase throughout the entire period
covered by the dataset, whereas a year-to-date formula
will reset at the start of each year.

- 368 -
Section 21: DAX Time Intelligence Functions

- 369 -
Section 21: DAX Time Intelligence Functions

• DATESINPERIOD returns a table containing a single column of


dates, beginning with the <Start_Date> and continuing for
the specified <Number_of_Intervals>, either working back or
forward in time.
• The function takes four parameters :
• < Dates> A date column (usually the date column of your date
table)
• < Start_Date> A date column (usually the date column of your
date table)
• <Number_of_Intervals> The number of units to add to or
subtract from the dates
• < Interval> The time unit to be used: Year, Quarter, Month or
Day.

• By mapping the <Start_Date> parameter to the current


date displayed in a visual, the DATESINPERIOD function can
be used to display moving calculations, such as moving
annual totals or moving averages.
• A Moving Annual Total (MAT) finds a total value over the
last 12 months.
• It is useful for ironing out seasonal variations when
analyzing monthly revenue.

- 370 -
Section 21: DAX Time Intelligence Functions

• The formula to return the moving annual total revenue,


uses the CALCULATE function, with [Total Revenue] as the
<expression> argument.
• For the <filter> argument of CALCULATE, the
DATESINPERIOD function is used to create a date range
which starts at the end of each current period and works
back one year from that date.

e xp re ssion

filte r

- 371 -
Section 21: DAX Time Intelligence Functions

• To calculate a 3-month moving average, the


DATESINPERIOD function is used to create a date range
which starts at the end of each current period and works
back 3 months from that starting point.
• We then use the DIVIDE function to divide this figure by 3
to obtain the monthly average.

e xp re ssion

filte r

- 372 -
Visualization

- 373 -
Section 22: Big Picture visuals

Section 22. Big Picture Visuals

- 374 -
Section 22: Big Picture visuals

- 375 -
Section 22: Big Picture visuals

• The card visual displays a single headline figure (provided


by a measure).
• It has two elements: a data label and a category label.

Data label

Category label

• To populate a card visual, highlight the card tile and, in the


Fields pane, click on the checkbox next to the required field.

- 376 -
Section 22: Big Picture visuals

• To change the category label, in the Fields section of the


Visualizations pane, simply double-click the existing label
and enter a new one.

• The format of a measure is controlled by highlighting the


measure and choosing a format in the Measure Tools Tab.

- 377 -
Section 22: Big Picture visuals

• The Data Label options


of the card visual allow
you to override two
aspects of this
underlying format:
Display Units (such as
Millions, Thousands,
etc.) and decimal places.

• To enter the precise width and height of a visual, in the


Format section of the Visualizations Pane, click on General
and enter X Position, Y Position, Width and Height.

- 378 -
Section 22: Big Picture visuals

• To evenly space a series of visuals, select them by dragging


a selection rectangle which encloses them all, then in the
Format Tab, click Align > Distribute Horizontally.

- 379 -
Section 22: Big Picture visuals

- 380 -
Section 22: Big Picture visuals

• The KPI visual is used to indicate


progress towards the achievement
of a goal in a given time period.
• It has three data fields: Indicator,
Trend axis and Target goals.

• Indicator - is the actual figure which will be compared to


the target which must be met.
• Trend axis - is the time frame in which the target is
supposed to be achieved.
• Target goals - is the target figure with which the actual
performance will be compared.

• In our example, we used the KPI visual to display the six-year


trend of actual versus target, which is only possible if we
display six years’ worth of data.
• We therefore set the interaction between the Year slicer and
the KPI visual to “None”, by highlighting the slicer and clicking
Format > Edit Interactions.

- 381 -
Section 22: Big Picture visuals

• The key metric displayed on the KPI


visual is the indicator (or actual)
figure.
• Like the data label on the card
visual, it allows you to change the
“Display Units” used (Thousands,
Millions, etc.) and “Value decimal
places”.
• “Auto” (the default) is useful when
the figure constantly changes due to
filter selection.
• Since our KPI visual indicator will
always show six years’ worth of
data, setting display units to
“Millions” makes more sense.

- 382 -
Section 22: Big Picture visuals

- 383 -
Section 22: Big Picture visuals

• A gauge visual shows a single actual value compared to a KPI


or target value.
• The needle on the gauge represents the goal or target value.
• The filled area represents the progress toward the target
value.

• The gauge visual has four data fields:


• Value - This is the actual figure achieved, represented by
the filled area of the gauge.
• Minimum - The starting point. Since this defaults to
zero, it can normally be ignored.
• Maximum - The endpoint of the 180° arc. This defaults
to twice the Value setting.
• Target - The target being contrasted with the (actual)
Value, represented by a line on the gauge.

Value Target

Minimum Maximum

- 384 -
Section 22: Big Picture visuals

• As well as allowing the consumers of your report to filter data


via slicers and other visuals, Power BI allows you to enforce
filters which remain in place throughout, irrespective of user
actions.
• These filters can be applied at three levels: all pages, page or
visual.
• In order to display the revenue for each country, we need to
apply a visual-level filter to each of the four gauges fixing the
Country to "England", "Northern Ireland", "Scotland" or
"Wales", respectively.

• To apply a visual-level filter to a visual, drag the filter field (in


this case Country) into the “Filters on this Visual” area of the
Filters pane.

- 385 -
Section 22: Big Picture visuals

• Next, apply a basic filter by clicking in the checkbox next to


the appropriate value.

• To get the Maximum value to ignore the Country filter


applied to the gauge visual, in “Section 20: The CALCULATE
Function”, we created a separate measure called [Revenue All
Countries] and used it to calculate the gauge Maximum.
• The [Revenue All Countries] measure uses the CALCULATE
and ALL functions to ensure that the result returned by the
measure cannot be filtered by either [Branches]Countries or
Branches[Branch].

- 386 -
Section 22: Big Picture visuals

• Thus, when the Country filter is applied to each gauge, the


Value and Target value amounts are filtered; but the
Maximum ignores the Country filter and returns the Revenue
for all countries.

Filtered

Filter ignored

• And, in the same way, when a gauge is being filtered for a


particular branch, the Value and Target value amounts are
filtered; but the Maximum field ignores the Branch filter and
returns the Revenue for all branches.

• By default, every visual that you add to a page will influence


the filtering in every other visual on the page. This process is
referred to as cross filtering.
• In our scenario, we need to create four distinct groups of
visuals, each consisting of a gauge and the related bar chart.
• Thus, for example, we want the bars in the Wales bar chart to
influence only the Wales gauge and to have no effect
whatsoever on the other gauges and bar charts.

- 387 -
Section 22: Big Picture visuals

• To create these visual interactive groupings, we highlight each


of the bar charts and click on the “None” option of the three
unrelated bar charts and the three unrelated gauges.

- 388 -
Section 23: Drill-Down and Drill-Through

Section 23. Drill-Down and Drill-Through

- 389 -
Section 23: Drill-Down and Drill-Through

- 390 -
Section 23: Drill-Down and Drill-Through

• Adding a hierarchy (whether formal or informal) to the axis


of a visual automatically activates Power BI’s drill-down
feature.

• To determine
determ
etermine whether drill-down
eter drill down applies
app
plies
es only
on to the visual
o
containing the hierarchy, or whether other visuals on the
page will be cross-filtered, click the Data/Drill Tab; and
choose “Apply drill down filters to” either “Entire page” or
“Selected visual”.

- 391 -
Section 23: Drill-Down and Drill-Through

• To activate the drill-down feature, click on the second of


the four arrow icons above (or below) the visual,
depending on its position.
• When the feature is activated, the second arrow icon is
surrounded by a circle.

• Once drill-down mode is activated, click on any value to drill


down to the next level in the hierarchy: for example, clicking
the year 2015 displays the four quarters in 2015, etc.
• Click the first arrow in the series to drill back up through
the levels.

- 392 -
Section 23: Drill-Down and Drill-Through

• At any point in the drill-down experience, instead of


clicking on a value in the chart itself, you can click on the
“Go to Next Level…” button (the third of the four drill-down
buttons) to drill down into all values simultaneously; for
example, drill from the Quarters level down to Months,
displaying all months, instead of only the months in one
quarter.

• The final icon in the series


“Expand all down one level in
the hierarchy”, simply reveals
the entire contents of the next
level within a hierarchy, rather
than selectively drilling down.

- 393 -
Section 23: Drill-Down and Drill-Through

- 394 -
Section 23: Drill-Down and Drill-Through

• To populate a table visual, highlight the tile and, in the


Fields pane, click on the checkbox next to each of the
required fields, in the appropriate order.

• By default, the name of each field will determine the


column headers.
• To change a column header, simply double-click the existing
name and enter a new one.

- 395 -
Section 23: Drill-Down and Drill-Through

• By default, tables automatically display an extra “Total”


row. If this is not required, in the Format Tab of the
Visualizations pane, expand the “Total” section and
deactivate “Totals”.

• The formatting options which apply to the body of a table


visual are found in the “Values” section of the Format Tab.
• To set an alternating colour scheme, choose contrasting
options for “Font Color”, “Background Color”, “Alternate
Font Color” and “Alternate Background Color”.

- 396 -
Section 23: Drill-Down and Drill-Through

- 397 -
Section 23: Drill-Down and Drill-Through

• The top N filter is normally applied to an individual visual


and restricts the number of items displayed in the visual to
• The top N filter
the specified is normally
value applied
of N, using to an individual
the specified criteria.visual
and restricts the number of items displayed in the visual to
the specified value of N, using the specified criteria.

• To apply the filter:


• To• apply
Highlight the visual in
the filter:
question.
•• Highlight the pane,
In the Filters visual in
question.
expand the field to be
• In the Filters pane,
filtered.
• expand
Change thethe field toType”
“Filter be
filtered.
to “Top N”.
•• Change the Value
Specify the “FilterofType”
N.
to “Top N”.
• Drag the field to be used
• Specify theinto
as criteria Value
theof“ByN.
• Drag
Value” the field to be used
box.
• as criteria
Click “Apply into the “By
Filter”.
Value” box.
• Click “Apply Filter”.

- 398 -
Section 23: Drill-Down and Drill-Through

- 399 -
Section 23: Drill-Down and Drill-Through

• Treemaps provide a
useful alternative to pie
charts and donut charts
when the number of
items to be displayed is
fairly numerous.
• A treemap consists of a
series of rectangles
whose size is mapped to a
given value, such as
Revenue.

• A treemap has three data fields:


• Group - Represents the axis of the
chart, the field whose elements
will be broken down into
rectangles.
• Details - Provides a legend
functionality. If used, each
rectangle would be sub-divided
into smaller rectangles indicating
the breakdown of each element in
the Group field.
• Values - Represents the metric
being plotted, and which is used to
determine the relative sizes of the
rectangles.

- 400 -
Section 23: Drill-Down and Drill-Through

• By default, Power BI assigns different colours to the


segments within a treemap.
• However, a useful alternative, in the advanced colour
options, is to map the colour tint of each segment to the
value of a measure.

• To base treemap colours on the value of a measure, in the


Format Tab of the Visualizations pane, click Data Colors >
Advanced Controls.
• Choose Format by > Color scale and specify the “Based on
field” measure.

- 401 -
Section 23: Drill-Down and Drill-Through

- 402 -
Section 23: Drill-Down and Drill-Through

• As we have seen, Power BI’s drill-down feature is triggered


by adding a hierarchy to the axis of a visual.
• Power BI’s drill-through feature applies the same
hierarchical drilling capability at the page level rather than
on a single visual.
• Any element displayed on the first page can become the
child element which is featured on the drill-through page.

• Drill-through pages typically


contain visualizations and
information relevant to one
particular field.
• Having prepared the page,
to make it into a drill-
through page, simply drag
the chosen field into the
“Drill through” area at the
bottom of the Values Tab of
the Visualization pane.

- 403 -
Section 23: Drill-Down and Drill-Through

• If the option
“Cross-report” is
activated, then
the user has the
potential to drill-
through to the
current page from
other reports
based on the
same dataset.

• The option “Keep


all filters” will
honour any
filtering which was
in place on the
page from which
the user has
drilled through.

- 404 -
Section 23: Drill-Down and Drill-Through

• Whenever a field is added to the “Drill through” area of the


Visualizations > Fields pane, Power BI automatically adds a
fully functioning Back button in the top left of the page.

• To avoid confusing your audience, it is useful to hide your


drill-through pages. This way, the only way for a user to get
to the page is by drilling through.
• To hide a page, right-click on the page tab and choose
“Hide Page”.
• In Power BI Desktop, the page will remain visible, for your
convenience; but will display a closed eye symbol indicating
its hidden state.

- 405 -
Section 23: Drill-Down and Drill-Through

• Once a drill-through field has been defined, when the user


hovers over this field on any other page, a tooltip will
automatically be displayed inviting them to drill through.

• Simply right-click on any of the elements in the visual and


choose “Drill through” from the menu.

- 406 -
Section 23: Drill-Down and Drill-Through

• Right-clicking to drill-through does not always occur to your


audience. However, Power BI offers a more explicit
alternative to right-click, which is to create a drill-through
button.

• If you start with the “Blank” button option, you will need to
activate “Button Text” and enter the text which you want to
appear on the button.

- 407 -
Section 23: Drill-Down and Drill-Through

• To add the drill-through functionality to the button, activate


“Action”, set the “Type” to “Drill through” and then choose
the appropriate page from the “Destination” dropdown.

- 408 -
Section 23: Drill-Down and Drill-Through

- 409 -
Section 23: Drill-Down and Drill-Through

• A tooltip page is a hidden miniature page which appears


when the user hovers over the specified field, replacing
Power BI’s default textual tooltip.

The Team

• To create a tooltip page, add a new page to your report;


and, on it, create the content which you want displayed in
the tooltip.
• Then, move all the content to the top left of the page.

- 410 -
Section 23: Drill-Down and Drill-Through

• To configure the page as a tooltip


page:
• Deselect all the visuals on the
page by clicking in space.
• In the Format tab of the
Visualizations pane, expand the
“Page Information” section.
• Activate the “Tooltip” option.

• Next, to reduce the size of the page, expand the “Page Size”
section and either set the size to “Tooltip” (320 pixels wide by
240 pixels high) or choose “Custom” to enter the dimensions
required by your content.

- 411 -
Section 23: Drill-Down and Drill-Through

• To complete the tooltip


page configuration, we
must specify the field
for which the page will
become a tooltip.
• In the Values tab of the
Visualization pane,
drag the required field
into the “Tooltip” area.

• To ensure that the correct tooltip is


displayed, select any visual, or
visuals which display the tooltip
field; and, in the Format tab of the
Visualizations pane, expand the
“Tooltip” section.
• Ensure that “Tooltip” is switched on.
• Set the “Type” to report page.
• And choose the required page from
the “Page” dropdown.

- 412 -
Section 23: Drill-Down and Drill-Through

• When you hover over the tooltip field, the tooltip page
should now be displayed, replacing Power BI’s default.

- 413 -
Section 24: Further Visualization Practice

Section 24. Further Visualization Practice

- 414 -
Section 24: Further Visualization Practice

- 415 -
Section 24: Further Visualization Practice

• In our trend line example, on the “Products” page or our


report, we created a line chart and added 'Date
Table'[Date] to the axis and [Revenue] to the Values field.

• To enable the user to filter this rather busy chart, we added


a Date slicer to the page, which, by default, provides two
methods for the user to filter dates:
• By dragging the two ends of a slider.
• By using the calendar to input start and end dates.
1 2

- 416 -
Section 24: Further Visualization Practice

- 417 -
Section 24: Further Visualization Practice

• To determine whether drill-down applies only to the visual


containing the hierarchy, or whether other visuals on the
page will be cross-filtered, click the Data/Drill Tab; and
choose “Apply drill down filters to” either “Entire page” or
“Selected visual”.
• The default behaviour is that drill down filters will apply to
the entire page.

• In our example, we add the Products hierarchy to the


"Group" field of a treemap visual (the axis), with Revenue
in the Values field.

- 418 -
Section 24: Further Visualization Practice

• Because of the default cross-filtering, when we drill down


the Products hierarchy, from Range Categories to Product
Range, the tables displaying Product Range and Product
information are automatically cross filtered.

• Cross-filtering is Power BI's default behaviour; but when


appropriate, this can be changed to cross-highlighting by
activating Format > Edit Interactions and clicking the cross-
highlight button.

- 419 -
Section 24: Further Visualization Practice

• Thus, for example, it is more useful to have cross-filtering


response in the treemap when the user selects either a
product range or a product in one of the tables, since they
can then see the proportion of the parent represented by
the selected item.

- 420 -
Section 24: Further Visualization Practice

- 421 -
Section 24: Further Visualization Practice

• The bar chart visual is a good choice for displaying top N


metrics. In our report, we use bar charts to show top 5
products by revenue and by units sold.

• Switching off the X axis and replacing it with data labels


makes it easier for the user to accurately compare the
values displayed.

- 422 -
Section 24: Further Visualization Practice

• To apply the top N filter:


• Highlight the visual in question.
• In the Filters pane, expand the field
to be filtered.
• Change the “Filter Type” to “Top N”.
• Specify the Value of N.
• Drag the field to be used as criteria
into the “By Value” box.
• Click “Apply Filter”.

- 423 -
Section 24: Further Visualization Practice

- 424 -
Section 24: Further Visualization Practice

• Although it is possible to install a


custom visual which enables you
to add a hierarchy to a slicer,
there is no need; since Power
BI's built-in slicer now supports
hierarchies.
• On the “Products” page of our
report, we need a slicer which
displays a hierarchy consisting of
Country, Branch, and Account
Handler.

• The slicer visual supports both formal hierarchy objects


which form a permanent part of the data model and
“informal” hierarchies created by dragging a series of fields
onto the axis of a visual to create a one-time hierarchical
structure.
Informal Hierarchy
Formal Hierarchy

- 425 -
Section 24: Further Visualization Practice

• If elements of a formal hierarchy are not required on a


particular occasion, it is possible to simply remove the
unwanted element.
• Thus, in our example, we do not need the “Customer
Name” field, so we simply delete it.

• As well as using the arrows to expand and collapse


individual items in the hierarchy, it is possible to right-click
and choose Expand or Collapse Entire Level.
• This is a useful feature for resetting the visual to the most
appropriate state from the user’s persepective, in
preparation for publishing.

- 426 -
Section 24: Further Visualization Practice

- 427 -
Section 24: Further Visualization Practice

• Having the same slicers available on multiple pages is a


common design feature and one which is convenient for
the user.
• Power BI leaves it to you, the report designer, to choose
whether slicers are synchronized or not as the user moves
from page to page.
Not synchronized
2017 2018 2019 2020 2017 2018 2019 2020 2017 2018 2019 2020

Page 1 Page 2 Page 3 Page 1 Page 2 Page 3 Page 1 Page 2 Page 3

Synchronized
2017 2018 2019 2020 2017 2018 2019 2020 2017 2018 2019 2020

Page 1 Page 2 Page 3 Page 1 Page 2 Page 3 Page 1 Page 2 Page 3

• To show the Sync Slicers pane, in the Ribbon, click View >
Sync Slicers.
• The Sync Slicers pane will remain completely blank until a
slicer is selected.

- 428 -
Section 24: Further Visualization Practice

• When a slicer is selected, the Sync


Slicers pane displays three columns:
• The first column, “Page Name”,
lists every page in the current
report.
• The second column, “Sync”,
determines on which pages the
slicer will be synchronized.
• The third column, “Visibility”,
determines on which pages the
slicer will be visible.

• In addition to the Sync Slicers pane, whenever you copy a


slicer from one page and paste it onto another, Power BI
displays a dialog which offers you the two synchronization
options: “Sync” and “Don’t Sync”.

- 429 -
Section 25. Dynamic Titles & Conditional Formatting

Section 25. Dynamic Titles & Conditional Formatting

- 430 -
Section 25. Dynamic Titles & Conditional Formatting

- 431 -
Section 25. Dynamic Titles & Conditional Formatting

• The SELECTEDVALUE function returns the value currently selected


in a column which has been filtered down to a single item.

• The function takes two arguments.

ColumnName A literal reference to an existing column; i.e., not


an expression.
AlternateResult An optional value to be returned when a single
value is not found in the specified column. When
not provided, the default value is BLANK().

• If the specified column has not been filtered down to a single


value, the optional second argument of the SELECTEDVALUE
function (AlternateResult) is returned.

• In our example, we used a nested SELECTEDVALUE


statement as the optional AlternateResult argument of an
outer SELECTEDVALUE in the gauge title measure.
• In our example, we used a
nested SELECTEDVALUE
statement as the optional
AlternateResult argument of
an outer SELECTEDVALUE in
the gauge title measure.

• Thus, if a branch is selected in


the bar chart, the gauge title
displays the branch.
• If no branch is selected, the
the nested SELECTEDVALUE
statement returns the name
of the country.

- 432 -
Section 25. Dynamic Titles & Conditional Formatting

• To use a measure as the title of a visual, in the Format tab


of the Visualizations pane, expand the “Title” section and
click the “fx” button.
• Choose Format by > “Field Value”; then choose your
measure from the “Based on field” dropdown.

- 433 -
Section 25. Dynamic Titles & Conditional Formatting

- 434 -
Section 25. Dynamic Titles & Conditional Formatting

• To convey meaningful messages to the user, it is often


necessary to concatenate text with the value returned by
SELECTEDVALUE.
• DAX uses the ampersand (“&”) for concatenation.

• The card visual is the standard choice for displaying


dynamic message.
• However, since text displayed in a card is always centre-
aligned, the multi-row card, which aligns text to the left, is
often a better option.

- 435 -
Section 25. Dynamic Titles & Conditional Formatting

- 436 -
Section 25. Dynamic Titles & Conditional Formatting

• In Power BI, conditional formatting


can be applied to several different
aspects of a visual, but the key
attribute to which it is applied is
colour.

• For example, in a gauge, you might


apply conditional formatting to the
colour of a data label or a category
label.

• To apply conditional formatting, click


on the “fx” button next to the
“Color” dropdown, in the
appropriate formatting section.

• The conditional formatting “Color” dialog offers three formatting


options:
• “Color Scale” - Which creates a continuous color scale from a
minimum to a maximum value
• Rules - Which allows you to define multiple Boolean rules to
determine the colour
• Field Value - Which lets you choose a column or measure
containing the colour as a hex value.

- 437 -
Section 25. Dynamic Titles & Conditional Formatting

• The ability to create multiple rules offers considerable flexibility.

• Simply choose a field from the “Based on Field” dropdown


(typically a measure) and then define the colour associated with
each band that the values in the field can fall into.

• The key limitation of using the “Rules” option for conditional


formatting is that the logic you create in one visual cannot be
copied to another visual of a different type.

• So, you often end up having to set up or modify the same set of
rules repeatedly.

- 438 -
Section 25. Dynamic Titles & Conditional Formatting

• To clear conditional formatting


rules and return to using a static
colour, click on the eraser icon
next to the “fx” button.

- 439 -
Section 25. Dynamic Titles & Conditional Formatting

- 440 -
Section 25. Dynamic Titles & Conditional Formatting

• A more efficient
alternative to the use of
formatting rules is to
encapsulate the logic that
would normally be placed
in rules into a measure.

• An IF statement can be
used to test the value of
an expression or measures
and return the
appropriate colour in the
form of a string containing
a hexadecimal code.

• To assign a measure as a color, click on the “fx” button next


to the “Color” dropdown, in the appropriate formatting
section.
• Next, in the Color dialog, choose “Field Name” from the
“Format by” dropdown and then select the name of the
measure from the “Based on Field” dropdown.

- 441 -
Publishing and Sharing

- 442 -
Section 26: Publishing to the Power BI Service

Section 26. Publishing to the Power BI Service

- 443 -
Section 26: Publishing to the Power BI Service

- 444 -
Section 26: Publishing to the Power BI Service

• Power BI Desktop is an offline authoring tool and any


content you create using Power BI Desktop is initially only
available to yourself.
• Publishing your reports to the Power BI service has three
main consequences:
• Reports published to the Power BI service can be shared
with other users.
• You can edit the pages of your report in the Power BI
service.
• You can allow other users to edit your reports in the
Power BI service.

• When you publish content, the current page that is


displayed in your report will be the one which initially
greets anyone who opens your report in the Power BI
service.
• You should therefore ensure that you activate the most
suitable page before publishing.

- 445 -
Section 26: Publishing to the Power BI Service

• You should also ensure that pages which are dependent on


other pages, such as drill-through pages and tooltip pages
are hidden.
• If these pages are not hidden, the user will be able to
navigate to them and will arrive on the page with no
context, causing confusion and frustration.

• The sort order within each visual will also be preserved.


• To monitor and alter the sort order, click on the ellipsis
menu in the top right of each visual and choose “Sort by”.
• The field currently being used for sorting will be in bold as
will either ascending or descending.

- 446 -
Section 26: Publishing to the Power BI Service

• Any filtering on the page will remain active when the


report is published. So, it makes sense to ensure that any
selections on slicers are deactivated before publishing.

• If you have slicers which occur on several pages, click View


> Sync Slicers and activate or deactivate synchronization, as
necessary.

Synchronized Not synchronized

- 447 -
Section 26: Publishing to the Power BI Service

• The Filters pane can be used both as an authoring tool and a


useful aid to consumers of your reports.
• To enable the user to apply additional filters to report pages
(or to the entire report), simply drag the required fields into
the “Page” or “All Pages” areas of the Filters pane.

• To upload a report from the Power BI Desktop environment


into the Power BI service, use the Publish command in the
Home Tab of the Ribbon.
• If you have any unsaved changes, you will be forced to save
them.

- 448 -
Section 26: Publishing to the Power BI Service

• When you first start using the Power BI service, all reports
that you publish will end up in what is known as
“MyWorkspace”. This is a space which is reserved within
the Power BI service for your own use and which only you
can access.

• When you have created one or more app workspaces in the


Power BI service (or been added as a member of a
workspace created by someone else), you will have the
choice as to whether you publish to MyWorkspace or to
one of these other workspaces.

- 449 -
Section 26: Publishing to the Power BI Service

- 450 -
Section 26: Publishing to the Power BI Service

• Any content you upload to MyWorkspace can only be


accessed and edited by yourself.
• Although you can share individual items from MyWorkpace
with other users, the workspace as a whole cannot be
shared.

- 451 -
Section 26: Publishing to the Power BI Service

• Unlike MyWorkspace, app workspaces are designed for


collaboration and sharing.
• The ability of a user to create app workspaces is
determined by the Power BI administrators of a tenant.

• Some organizations will centralize the creation of app


workspaces and have all workspaces created by
administrators.
• Other organizations will distribute the ability to create
workspaces to their report creators.

- 452 -
Section 26: Publishing to the Power BI Service

• In the Power BI service, an administrator will click on Settings


> Admin Portal > Tenant Settings; then apply the appropriate
settings in the “Workspace Settings” group.
• Typically, the ability to create workspaces will be assigned to
specific security groups.

• In order to publish content to an app workspace, you also


need to have a Power BI Pro license.
• Users with the Power BI Free license can only ever publish
to their own MyWorkspace.

- 453 -
Section 26: Publishing to the Power BI Service

• If you have been assigned the ability, to create a


workspace, click Workspaces in the Navigation pane of the
Power BI service and then click “Create a Workspace” and
enter a name for the new workspace (which must be
unique within the context of the entire tenant).

• To assign a workspace image, to make the workspace easier


to identify, click the upload button and browse for a suitable
image (which will automatically be cropped into a circle).

- 454 -
Section 26: Publishing to the Power BI Service

• As workspaces proliferate, it is important to enter a full


description of each workspace you create, it’s content and
intended audience.

- 455 -
Section 26: Publishing to the Power BI Service

- 456 -
Section 26: Publishing to the Power BI Service

• Having published a report, you can continue working on it


in the Power BI service; but it is only the report pages
which you will be able to access.
• You cannot modify the data model in any way. All data
operations must be done back in Power BI Desktop.

P ower B I Desktop

Report Data Model


D Power Query
Po

P ower B I S ervice

Report Data Model Power Query

• To open a report, simply click on its name in the list of


contents.

- 457 -
Section 26: Publishing to the Power BI Service

• The report initially opens in reading view, just as it will for


any user with whom you later share the report.

• To edit a report, choose “Edit” from the ellipsis menu.

- 458 -
Section 26: Publishing to the Power BI Service

• The editing experience is very similar to the one provided


by Power BI Desktop, with very much the same interface
and tools.

• Having edited a report, click File > Save to save your


changes; but bear in mind that your changes are only being
saved to cloud, not to the original PBIX file.

• Having made changes to a report, and saved your changes,


you can exit Edit mode by clicking the “Reading View” button.

- 459 -
Section 26: Publishing to the Power BI Service

• If you need to make changes to the data model of a report,


you will need to download the file and open it in Power BI
Desktop.
• To download a report from the Power BI service, choose
“Download the pbix file” from the ellipsis menu.

• The download experience is controlled by your current


browser settings and is not a special function of the Power
BI service.
• Once the file is downloaded, simply click to open it in
Power BI Desktop.

- 460 -
Section 27: Power BI Dashboards

Section 27. Power BI Dashboards

- 461 -
Section 27: Power BI Dashboards

- 462 -
Section 27: Power BI Dashboards

• Normally
N ll created
t in • Al
Always created
t d in
i PPower BI
Power BI Desktop service
• Can have multiple • Single page overviews
pages
• Dependent on reports
• Mainly self-contained
• No slicers are allowed
• Can feature any type of
visual • No cross-filtering or cross-
highlighting
• Cross-filtering and
cross-highlighting • No drill-through and drill-
down
• Drill-through and drill-
down • Additional tiles available;
e.g. streaming

- 463 -
Section 27: Power BI Dashboards

- 464 -
Section 27: Power BI Dashboards

• Dashboards can be created either as blank objects or by


pinning a visual from a report.
• To create a blank dashboard, choose “Dashboard” from the
“New” menu, enter a name and click “Create”.

• Power BI uses the same JSON theme files to brand


dashboards as are used in reports.
• To edit a dashboard theme, while editing the dashboard,
choose “Dashboard theme” from the Ellipsis menu.

- 465 -
Section 27: Power BI Dashboards

• Since only a few basic preset themes are available, to fully


brand your dashboard, click upload “JSON theme” and
upload your corporate theme file.

• To add your logo to a dashboard:


• Choose “Add tile” from the “New” menu.
• Choose the “Image” tile and click the “Next” button.
• Paste the image URL into the “URL” field and click
“Apply”.

- 466 -
Section 27: Power BI Dashboards

- 467 -
Section 27: Power BI Dashboards

• The most common method of adding items to a dashboard


is to pin individual visuals.
• As you hover over each of the visuals within a report, you
will notice that, in the top right, you always have a Pin
Visual icon.
• Click the pin icon to display the “Pin to dashboard” dialog.

• There is no need to create a blank dashboard in advance;


we can simply click on the pin icon and, in the dialog which
appears, select the option New Dashboard.
• Alternatively, we can click “Existing dashboard” and choose
one from the dropdown.

- 468 -
Section 27: Power BI Dashboards

• In the “Tile Theming” section, we can choose “Use


destination theme” if the target dashboard already has a
theme associated with it; or “Keep current theme” when
the target dashboard has no theme or is being created by
the current pin operation.

• After you have pinned a visual to a new or existing


dashboard, Power BI displays a useful confirmation
message containing a “Go to Dashboard” link.
• (The confirmation message disappears after a few
seconds.)

- 469 -
Section 27: Power BI Dashboards

• The key exception to pinning is the slicer visual.


• Slicers simply cannot be pinned to a dashboard.

• Pinning visuals to a dashboard creates a dashboard with


dependencies on the underlying reports from which the
various visuals have been pinned.

Report 1 Report 2 Report 3

Dashboard

- 470 -
Section 27: Power BI Dashboards

- 471 -
Section 27: Power BI Dashboards

• As well as pinning individual elements to a dashboard, you


can also add an entire report page to a dashboard.
• The resulting dashboard is self contained with no
dependencies to the original page.

Pin Live Page

Self-Contained Dashboard Report Page

• Since pinned pages will be self-contained and have no links


to report pages, to avoid confusing users, it is useful to
create a special version of the page to be pinned and
remove any elements relating to external links, such as
buttons linking to other pages.

- 472 -
Section 27: Power BI Dashboards

• The page used for pinning should then be hidden, so that


users are not able to navigate to it.
• To hide a page, right-click the page tab and choose “Hide
Page”.

• In the “Pin to dashboard” dialog, select the option New


Dashboard; enter a name for the dashboard then click the
“Pin live” button.

- 473 -
Section 27: Power BI Dashboards

• Using the Pin live page option creates a totally self-


contained dashboard consisting of the entire report page
with all of its interactions intact.
• Slicers, cross-filtering and cross-highlighting all function
exactly as they did on the original page.

Dashboard

- 474 -
Section 28: Collaboration and Sharing

Section 28. Collaboration and Sharing

- 475 -
Section 28: Collaboration and Sharing

- 476 -
Section 28: Collaboration and Sharing
• Dashboards can be created either as blank objects or by
pinning a visual from a report.
• To create a blank dashboard, choose “Dashboard” from the
“New” menu, enter a name and click “Create”.
•• A
Dashboards
workspacecan (or be
appcreated eitherisas
workspace) blank
used objects
in the or by
Power BI
pinning a visual from a report.
service for collaboration on the creation of content and
provides different levels of access to its members.
• To create a blank dashboard, choose “Dashboard” from the
• “New”
When an menu, enter a name
app workspace and click “Create”.
is published, an app is created; a
• read-only
A workspacecopy(orofapp
theworkspace)
original workspace.
is used in the Power BI
service for collaboration on the creation of content and
provides different levels of access to its members.
• When an app workspace is published, an app is created; a
read-only copy of the original workspace.

Section 28. Collaboration and Sharing

• To grant access to a workspace, click “Workspaces” then


choose “Workspace Access” from the Ellipsis menu next to
the appropriate workspace.

• To grant access to a workspace, click “Workspaces” then


choose “Workspace Access” from the Ellipsis menu next to
the appropriate workspace.

- 477 -
Section 28: Collaboration and Sharing

• Enter the name of a security group or user, choose a role


and click the Add button.
• You can assign each group or user one of four roles: Admin,
Member, Contributor or Viewer.

• The Viewer role is used to grant other users, such as


managers or supervisors, a read-only experience. They can
view dashboards, reports, or workbooks in the workspace.
• However, they cannot edit content in the workspace or
view underlying datasets.

- 478 -
Section 28: Collaboration and Sharing

• Additionally, when publishing content, although the


workspace to which they have been give Viewer access is
listed, if they attempt to publish to it, they will be shown an
error: “Couldn’t publish to Power BI. Sorry, you don’t have
access to publish to this workspace. Please contact the
owner for access.

• The Contributor role provides users with full access to all


content within a workspace; they can publish content to
the workspace; they have full access to all reports,
dashboards and datasets and can edit and delete any of the
items in the workspace.

- 479 -
Section 28: Collaboration and Sharing

• However, contributors do not have the ability to share any


of the reports or dashboards in the workspace, or to
publish the workspace as an app.

• The Member role grants users all the capabilities of the


Contributor role; however, in addition, they can share
reports and dashboards and publish the workspace as an
app.

- 480 -
Section 28: Collaboration and Sharing

• Members also have the ability to add users and groups to


the workspace. However, they can only grant three
permission levels: Member, Contributor and Viewer.

• The Admin role is only really suitable for IT staff, since it


provides users with exactly the same capabilities as the
owner of the workspace; and this includes the ability to
remove the creator of the workspace from the list of
members.

- 481 -
Section 28: Collaboration and Sharing

• And, naturally, this means that the Admin role also allows
grants the user the ability to delete the workspace itself.

- 482 -
Section 28: Collaboration and Sharing

- 483 -
Section 28: Collaboration and Sharing

- 484 -
Section 28: Collaboration and Sharing

• Click Files > Get.

• Specify the location:


“Local File”, “OneDrive
- Business” or
“SharePoint - Team
Site”.

• Click the “Upload”


button to upload the
file into the workspace.

- 485 -
Section 28: Collaboration and Sharing

• Creating an app is not an all or nothing process; you can


decide which dashboards, reports and workbooks will be
included in the app by activating or deactivating the option
“Include In App” on the right of the name of each item.

• To create an app, navigate to the appropriate app


workspace; then click on the “Create App” button, in the
top right of the screen.

- 486 -
Section 28: Collaboration and Sharing

• In the “Setup” section, enter a name as well as a detailed


description of the app; its contents, the period it covers;
everything your audience needs to know in order to
distinguish this apps from others.

• You can also add a link to a support site where users can
find answers to questions regarding your app.

- 487 -
Section 28: Collaboration and Sharing

• The “Setup” tab of the dialog also contains two options for
branding: the ability to upload a circular app logo; and to
choose a preset “App theme color”.

• In the “Navigation” pane, Power BI automatically generates


a list of all the reports, dashboards, and workbooks in the
app.
• This default navigation system provides the user with a
good, interactive experience.

- 488 -
Section 28: Collaboration and Sharing

• However, it is also possible to customize the default


navigation in two ways:
• By placing navigation items in sections
• By adding custom links.

• Having created a new section by clicking New > Section, to


add items to a section, select the items and choose the
appropriate section from the “Section” dropdown.

- 489 -
Section 28: Collaboration and Sharing

• Sections allow you group related items together.


• Having created a new section by clicking New > Section, to
add items to a section, select the items and choose the
appropriate section from the “Section” dropdown.
• Sections can be expanded and collapsed while editing the
navigation, and also by users of your app.

• Links allows you to link to any URL accessible via the web.
• It is a useful facility for allowing end users to access related
information on an intranet or website or to download
related material such as PDF documents.

- 490 -
Section 28: Collaboration and Sharing

• The Permissions pane allows you to specify the groups and


users who can access the app, and what they are allowed to
do with it.
• Begin by entering the names of the groups and/or users
who can access the app.

• To create a read-only app for users who are essentially


consumers of content, deactivate the options “Allow users
to connect to the apps underlying datasets using the Build
permission”, “Allow users to make a copy of reports in this
app” and “Allow users to share the app and the apps
underlying datasets using the share permission”.

- 491 -
Section 28: Collaboration and Sharing

• If you are sharing an app with report-developers, then it may


be useful to activate the option “Allow users to connect to the
apps underlying datasets using the Build permission”.
• They will then be able to access these datasets from Power BI
Desktop when building reports.

• To “push” apps to end users, so that your app appears


automatically in you’re their list of apps, activate the option
“Install this app automatically”.
• Users will then not have to fetch the app from the Microsoft
AppSource.

- 492 -
Section 28: Collaboration and Sharing

• Sharing an app with a group of users does not give them an


access to the underlying workspace.
• To access the app, the user clicks on the “Apps” button in
the Navigation pane and then on the “Get Apps” button and
activates the “Organizational apps” tab of the “Power BI
apps” dialog.

• If the option “Install this app automatically” was activated


when the app was published, your app appears
automatically in the user’s list of apps, without them having
to click “Get Apps”.
• Users will then not have to fetch the app from the Microsoft
AppSource.

- 493 -
Section 28: Collaboration and Sharing

• If you wish to recall the app, for any reason, from within the
app, choose “Unpublish App” from the Ellipsis menu.
• This action uninstalls the app for everyone to whom you
have published it; however, it does not delete the original
workspace or any of its contents.

• If the option “Install this app automatically” was not


activated when the app was published, a “Delete” button
will be shown at the bottom of the app tile.
• Clicking this button simply deletes the app from that user’s
list of apps and has no other impact.

- 494 -
Section 28: Collaboration and Sharing

• Having published an app from an app workspace, the option


“Create App” changes to “Update App”.
• You will need to update an app whenever any of the
following occur:
• New content (report(s), dashboard(s) or workbook(s)) has
been added to the workspace.
• There have been structural changes to one or more
datasets (new measures, new tables, etc.).
• The app needs to be shared with different users or
groups.

- 495 -
Section 28: Collaboration and Sharing

• The experience of updating an app is identical to that of


creating the app, with the same three sections: “Setup”,
“Navigation” and “Permissions”. So, in many cases, you can
simply click the “Update app” button without making any
changes.

- 496 -
Section 28: Collaboration and Sharing

- 497 -
Section 28: Collaboration and Sharing

• Although sharing apps is the most efficient way of


making content available to other user, it is also possible
to share individual reports and dashboards.
• To share a dashboard or report, click on the “Share”
button next to the name of the item in the list of
workspace contents.

• The Share dialog contains


two tabs: “Share” and
“Access”. To share items,
enter the name of the
appropriate groups or
users in the “Grant access
to” field then click on
“Share”.

- 498 -
Section 28: Collaboration and Sharing

• The “Access” tab of the “Share” dialog lists everyone


who has access to the item by any route; both as a result
of item sharing and of being given access to the
workspace.

• Users and groups with Admin or Member permission are


listed as “Owner”.

- 499 -
Section 28: Collaboration and Sharing

• Contributors are listed have “Read and Edit” access.

• Viewers have “Read” access.

- 500 -
Section 29: Power BI Mobile

Section 29. Power BI Mobile

- 501 -
Section 29: Power BI Mobile

- 502 -
Section 29: Power BI Mobile

• Even without any mobile optimization on your part, the


Power BI mobile user experience is acceptable.
• By default, mobile users view Power BI report pages in
landscape orientation.

• From a report-developer perspective, when designing a


portrait layout for a report page, you start with a blank
canvas containing no visuals.

- 503 -
Section 29: Power BI Mobile

• Dashboards are slightly more


mobile friendly than reports; by
default, they are displayed in
portrait view, with the tiles on
the original dashboard
automatically resized and
repositioned in a single column.

• When designing a portrait layout for a dashboard, you start


with a completed layout, automatically generated by Power
BI, which contains all visuals.

- 504 -
Section 29: Power BI Mobile

- 505 -
Section 29: Power BI Mobile

• Mobile reports are based on the regular web report which


you will have already created, with the layout adapted and
optimized for mobile.
• For example, adapting a four-column desktop layout into a
single-column mobile one.

• Mobile reports must be


designed on a page-by-
page basis, with a
separate design for
each page, and the Page 1 Page 2 Page 3

starting point for each


page design will always
be the visuals used on
each page in the
desktop layout.

- 506 -
Section 29: Power BI Mobile

• The Selection pane (View >


Selection) is very useful for
organizing your page elements
and demarcating web assets
from mobile ones.
• The visuals used in your web
layout should be regarded as
the originals and can be used in
both web and mobile layouts.
• However, any visuals (or visual
arrangements) which are
unsuitable for mobile display should be substituted, either
by duplicating and modifying the web versions or by
creating new, mobile-only alternatives.

• When preparing a mobile layout,


it is useful to create at least two
groups of visuals: one for web
assets and one for mobile-only
assets.
• To create a group, in the Selection
pane, use Click > Shift-Click (for
contiguous selection) and Click >
Control-Click (for discontiguous
selection); then Right-click the
selected elements and choose
“Group > Group”.

- 507 -
Section 29: Power BI Mobile

• If you need to create visuals for use on mobile only, you


will need to hide these visuals in your desktop layout.
• However, unfortunately, any visuals which are hidden
using the Selection pane will be hidden in both desktop
and mobile layouts.

• The first step to hiding mobile-only assets is to drag the


mobile group below the desktop group, so that all mobile-
only elements are at the bottom of the stacking order.

- 508 -
Section 29: Power BI Mobile

• Next, highlight the mobile layout group and, in Format >


General, set the width and height to 12 pixels each, the
minimum allowed.

• Since the group as a whole is only 12 pixels by 12 pixels, the


individual visuals will now be tiny.

- 509 -
Section 29: Power BI Mobile

• As a final precaution,
the mobile group can
be positioned behind
any visual in the
desktop layout group
which has a solid
background.
• Dragging the mobile
group will now be
impossible, so you will
need to use Format >
General and set the X
and Y coordinates,
within the context of a
1280 x 720 pixel page.

- 510 -
Section 29: Power BI Mobile

• To create a mobile report layout in Power BI Desktop, click


View > Mobile Layout.

• To create a mobile report layout in the Power BI service, edit


the report, then click the Mobile Layout button.

- 511 -
Section 29: Power BI Mobile

• To add visuals to the report page, either drag the visual from
the Visualizations pane into the mobile preview or simply
double-click the required visual.

• To remove a visual from the report page, click on the “X” icon
in the top right of the visual.

- 512 -
Section 29: Power BI Mobile

• When accessing a report on a mobile phone, if the report


has at least one mobile-optimized page, a special mobile
icon is displayed next to the report name.

• When the user clicks the


report name to access the
report, they will
automatically be taken to
the portrait report layout
that you have prepared.

- 513 -
Section 29: Power BI Mobile

- 514 -
Section 29: Power BI Mobile

• To create a mobile-optimized dashboard layout, from


within the dashboard, click Edit > Mobile View.

• Additionally, whenever you pin an item to a dashboard, a


pop-up message is displayed containing a “Create phone
view” button which will also take you into mobile view.

- 515 -
Section 29: Power BI Mobile

• The default mobile layout contains all visual tiles from the
original dashboard.
• To unpin a tile from the layout, click the unpin button in the
top right of the tile.

• Any tiles removed from the layout are displayed in the


“Unpinned tiles” pane.
• To pin a tile onto the layout, click the pin icon in the top
right of the tile.

- 516 -
Section 29: Power BI Mobile

• Unlike mobile report layouts, changes made to a dashboard


layout are automatically saved and immediately reflected
in the mobile experience.

- 517 -
Section 30: Refreshing Data

Section 30. Refreshing Data

- 518 -
Section 30: Refreshing Data

- 519 -
Section 30: Refreshing Data

• The key capabilities of an on-premises data gateway are as


follows:
• Schedule refreshing of data imported from on-premises
sources
• Access data using DirectQuery mode
• Access on-premises Analysis Services data using live
connection mode
• Compatible with PowerApps, Power Automate, Azure Analysis
Services, and Azure Logic apps
• Multiple on-premises data gateways can be registered for the
same user
• Can be configured in high-availability clusters
• Needs to be installed on a computer which is always on;
usually a server.

• The gateway software is a freely available download; in the


Power BI service, simply click Download > Data Gateway.

- 520 -
Section 30: Refreshing Data

• As well as standard or enterprise mode, a gateway can be


installed in “Personal” mode.
• The following features are unavailable in “Personal” mode:
• Data sources which use DirectQuery
• Analysis Services connections using live mode
• Sharing the gateway with other users
• The creation of gateway clusters.

• Having installed the


gateway software, to
configure the gateway,
you need to sign into
your Power BI tenant
using your regular
credentials.

- 521 -
Section 30: Refreshing Data

• After signing in, you will be asked to name the gateway and
enter a recovery key.
• The recovery key is used to generate a key which encrypts
the data source credentials stored in the Power BI tenant.
• You will need to re-enter
the recovery key if you
need to reconfigure a
crashed machine, migrate
the gateway to a different
machine or change the
user account associated
with the gateway.

• When you click configure, the


gateway configuration
completes, and the utility has
done its job.
• You can now close the on-
premises data utility and the
software will continue to run
as a service.

- 522 -
Section 30: Refreshing Data

- 523 -
Section 30: Refreshing Data

• To avoid failure when using an on-premises data


gateway to carry out scheduled refreshes or to connect
to databases in DirectQuery mode, gateways can be
configured as high-availability clusters.
• The gateway cloud service always attempts to connect
to the primary gateway in a cluster (the first gateway
configured).
• However, if the primary gateway is unavailable, it
automatically switches to the next available gateway in
the cluster.
• To ensure constant availability, each gateway in a
cluster must be on a different machine.

- 524 -
Section 30: Refreshing Data

• When configuring a gateway, if the option “Add gateway to


a cluster” is activated, the configuration is treated as a
cluster instance configuration.

• Choose the existing cluster


to which the new gateway
will be added from the
“Available gateway
clusters” dropdown.
• To authenticate the cluster
to which the gateway is to
be added, enter the
recovery key which was
used when installing the
primary gateway.

• In the Power BI service, in Settings > Manage Gateways,


only the primary server will ever be listed, even if it is
currently unavailable and another server in the cluster is
in use.

- 525 -
Section 30: Refreshing Data

- 526 -
Section 30: Refreshing Data

• Reports which are built from on-premises databases will


normally require a gateway.
• In Import mode, the gateway is only required if data refresh
is required.
• In DirectQuery mode, the database credentials must be
added to the gateway from the outset; since, without it,
the report cannot be displayed in the Power BI service.

• To access the gateway in the Power BI service, click the


Settings button (the cog icon) and choose “Manage
Gateways”.

- 527 -
Section 30: Refreshing Data

• Each on-premises data source to be accessed by the


gateway must be added to the gateway, by clicking the
“Add Data Source” button.

• The credentials required to access the data source all need


to be saved; in the case of a database source: Server name,
Database, authentication method, username and
password.

- 528 -
Section 30: Refreshing Data

• To set up a scheduled refresh to synchronize imported data


with the on-premises version, activate “Scheduled refresh”,
choose a frequency (e.g. “Daily”), specify the time zone
and click “Add another time”.

- 529 -

You might also like