100% found this document useful (3 votes)
467 views381 pages

Power BI - 3 in 1 - Beginne...

This document provides guidelines and disclaimers for using the information within. It states that the publisher is not liable for any damages caused by use or misuse of the content. Reproduction or transmission of the content without permission is prohibited. The information is intended for informational purposes only without guarantees.

Uploaded by

Rajasekhar Kolla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
467 views381 pages

Power BI - 3 in 1 - Beginne...

This document provides guidelines and disclaimers for using the information within. It states that the publisher is not liable for any damages caused by use or misuse of the content. Reproduction or transmission of the content without permission is prohibited. The information is intended for informational purposes only without guarantees.

Uploaded by

Rajasekhar Kolla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 381

© Copyright 2020 by Daniel Jones - All rights reserved.

This document is geared towards providing exact and reliable information in regards to the topic and
issue covered. The publication is sold with the idea that the publisher is not required to render
accounting, officially permitted, or otherwise, qualified services. If advice is necessary, legal or
professional, a practiced individual in the profession should be ordered.
- From a Declaration of Principles which was accepted and approved equally by a Committee of the
American Bar Association and a Committee of Publishers and Associations.
In no way is it legal to reproduce, duplicate, or transmit any part of this document in either electronic
means or in printed format. Recording of this publication is strictly prohibited, and any storage of this
document is not allowed unless with written permission from the publisher. All rights reserved.
The information provided herein is stated to be truthful and consistent, in that any liability, in terms of
inattention or otherwise, by any usage or abuse of any policies, processes, or directions contained
within is the solitary and utter responsibility of the recipient reader. Under no circumstances will any
legal responsibility or blame be held against the publisher for any reparation, damages, or monetary
loss due to the information herein, either directly or indirectly.
Respective authors own all copyrights not held by the publisher.
The information herein is offered for informational purposes solely, and is universal as so. The
presentation of the information is without a contract or any type of guarantee assurance.
The trademarks that are used are without any consent, and the publication of the trademark is without
permission or backing by the trademark owner. All trademarks and brands within this book are for
clarifying purposes only and are owned by the owners themselves, not affiliated with this document.
TABLE OF CONTENTS

Power BI
A Comprehensive Beginner’s Guide to
Learn the Basics of Power BI from A-Z
Introduction
Who is this Book meant For?
What is Covered in the Book?
Chapter One: Introduction to Power BI
Who are the People Using Power BI, and Why?
Important Features of Power BI
How to Download Power BI
Getting Acquainted with Power BI
Power BI Desktop Options
Uploading Data into Power BI
How to Create your First Visualization
How to Create a Visual Manually
How to Arrange your Dashboard
The Interaction of Multiple Visuals on a Dashboard
Introduction to Quick Insights
Formatting of Reports
Modifying a Report
Chapter Two: Sharing the Dashboard
How to Invite a User to View a Dashboard
How to Create a Workspace
How to Share a Report on Mobile Devices
Chapter Three: Loading Data from Different Sources
Power BI Desktop Query Editor
The Different Data Sources Allowed on Power BI
How to Load a CSV Data File
How to Load an XML Data File
How to Load an Excel Data File
How to Import Queries and Models Created in Excel to Power BI
How to Load a Windows Access File or Database
How to Load a JSON Data File
How to Load an Entire Folder into Power BI
How to Load Selected Files in a Folder
How to Create your Own Data on Power BI Desktop
Database Data Source
How to Import Data from SQL Server
How to Import Data from ODBC Sources
Chapter Four: Data Transformation
Power BI Desktop Query Editor
The Power BI Query Editor Environment
Add Columns
View
Transformation Steps in the Query Editor
Restructuring the Data in a Query
Filtering the Data in a Query
Chapter Five: Data Models
How to Create a Data Model in Power BI
Power BI’s Data View Window
Exploiting Tables
Creating Hierarchies
Creating Joining’s between Tables
Relationship View
Managing Relationships
Classifying Data
Arranging Data in the Data Model
Creating Sort- By for Data Model
Connecting Column Contents
Selecting the Right Table for Joined Calculations
How to carry out Logical Functions
Carrying Out Basic Aggregations
Conclusion
Resources

Power BI
A Comprehensive Guide of Tips and Tricks
to Learn the Functions of Power BI
Introduction
Business Intelligence Software (BI)
Treatment Of Data In Power Query
The Query Editor Interface
Data Processing
Data Relationship And Modeling
Calculations And Dax
Visualization
Principles For Creating Visuals And Reports
Showing Compositions And Flows
Power BI
Sharepoint
Power Bi For Mobile
Power BI And Excel
Chapter One: Review Of Getting Started With Microsoft Power BI
Basic Theoretical Concepts
Explanation Of The Practical Example Of Power Bi
Connection With Excel File
Connection To A Web Page
Data Transformation in Power BI
Apply The Transformations Performed In Power Query
Creating A Report With Graphics
Dynamic Filters
MAPS
Chapter Two: Introduction to Power Pivot
Power Pivot Ribbon in Excel
Steps to Enable Power Pivot in Excel
Power Pivot Management Window
Excel Power BI Components - Power Pivot
Chapter Three: Introduction to DAX
Where Are We On The Road?
What is DAX?
DAX Syntax
DAX Functions
Aggregation Functions
Chapter Four: DAX in Practice
Understanding the Contexts
Row Context
Query Context
Filter Context
DAX Functions
Aggregation Functions Ending in "X
Practical Example of DAX
Using DAX Studio and Excel as Power BI Measurement Verification
Tools
DAX Studio: A Really Useful Tool
Power BI and the SSAS Service
Chapter Five: Power BI and Power Query (M Language)
The Role of BI Self-Service in the Development of a DataWarehouse
Power Query much more than Self-Service BI
Population Register. The Source Data Source
Population File Record Design
Data Import with Power BI
Query Editor. The Power Query Development Environment
Modifying the Default Names
Optimization of Data Load Times
Creation of Columns from the Source Data
Chapter Six: Data Model Using Power Query
Nationality. Import from Excel
Chapter Seven: Power Pivot Engine To Design A Population Data Model
Data Designer Introduction
Data Designer Population Count Measure
Report Designer Elementary Operations in the Use of Controls
Report Designer Results Display
Measurement Control Test
Tables Need Relationships
Relationships Designer. Relationship Creation
Data Designer Hierarchy Creation
Demographic Structure Indicators
Demographic Structure Indicators
Conclusion
References

Power BI
Simple and Effective Strategies to Learn
the Functions of Power BI and Power Query
Power BI: A Disruptive Reporting Platform
Introduction to Power BI
Power BI Online Service
Power BI Desktop
Power BI Mobile
Manage Data Sources in Power BI Desktop
Benefits of Power BI
Manage Data Source
Q&A (Natural Language Query)
Strategies to Learn Power BI Functions
Introduction
Power BI Architecture
Creating, Publishing and Scheduling a Dashboard
Creating Parameters in Power BI
Calling Oracle Package Function in Power BI
Limitations in Power BI
Power BI Desktop Functionalities
Power BI Desktop Introduction
Data Connectivity Modes
Pbit Template File Implementation
Assigning Parameter Values Dynamically
Maps in Power BI Desktop
Power BI Real-Time Dashboard
Introduction
Power BI Preview
Navigation Pane
Dashboards
Dashboard Tiles
Q&A Question Box
Functionalities of Power BI Preview
Share a Power BI Dashboard
Various Data Sources
Power BI Designer File
Refresh your Data
Steps to Refresh Schedule
Power BI for Report Generation and Mail
Introduction
Setup
Report Generation Using Visualization
Publishing the Report
Subscription and Mailing of the Report
Report Creation in Power BI Desktop with AX 2012
Developing Power BI Reports with NAV 2016
Integration of Power BI Modules with MS Excel
Steps to Enable Plugins
Tips for Using the Power BI Dashboard
Dynamic Row Level Security in Power BI
Introduction to Power BI
Benefits of Power BI
Steps to Define a Role in Power BI Desktop
Toggle Button and Tooltip Features in Power BI
Introduction
Designing a Dashboard using the Imported Dataset
Toggle Button with Bookmark Feature
Report Page Tooltip in Power BI Desktop
Publishing Reports on Apps in Power BI
App Workspace
Sourcing an Existing Power BI Report into a New Power BI Report
Using Live Connection
Power BI and Share Point
Introduction
Power BI Desktop
Views in Power BI Desktop
Build Reports
Creating Charts For Sharepoint List Data Using Power BI
Integrating Power BI with SharePoint
Create Relationships between Two Charts
Create Custom and Calculated Columns in Power BI
Create a Calculated Column
Share the SharePoint Page with PowerBI Report Embedded in It
Hosting of Power BI Reports in SharePoint
Publish the Power BI Report on Dynamics 365
Power Query for Report Generation
Introduction
Setting up Power Query
Power Query for Excel
ETL Process
Synoptic Panel in Power BI Desktop
Synoptic Panel by SQLBI
Filters and Slicers in PowerBI Report
Filters in PowerBI
Different Types of Filters in PowerBI
Slicers
Slicers vs. Filters
How to Toggle in Power BI Report Using Images
Cognos Self Service BI
Self Service BI: Overview
Self Service BI: Challenges
Why Self Service is Required in Today’s World
The Business Case for Self Service BI
Need for BI Users to be More Empowered and BI Tools to be More
Exhaustive
Features and Functions
The Tradeoffs
Conclusion
Power BI

A Comprehensive Beginner’s Guide to Learn


the Basics of Power BI from A-Z

DANIEL JONES
Introduction

Microsoft garnered a lot of attention announced its intention to incorporate


Self-Service Business Intelligence (BI) in 2009. With that in mind, they
released the Power Pivot add-in for Excel in 2010. When Power Pivot was
released, it did not come with a massive marketing campaign plan, few
announcements and conferences were planned. Due to this, the general
awareness of Excel users about this new add-in was poor. And the majority
of the users that knew about the new technology were reluctant to adopt it.
Professionals in the BI community were not pleased with the response, as
there were clear advantages of using the add-in to gather insights from data.
The professionals did not hold back in their response to Microsoft’s
marketing strategy and pestered Microsoft to expand their promotion of Self-
Service BI, and make it appeal to data analysts, decision-makers, data
scientists, and BI fanatics all over the world. They also requested an
additional feature that allowed them to share reports between a team.
Microsoft answered their request by adding a feature called SharePoint to the
first version of Power BI, SharePoint allows users to share reports offline and
online. This still wasn’t satisfactory to the professionals who complained
about the different bug issues of the version.
Microsoft browsed through all the constructive feedbacks and created the
version of Power BI that is currently available. The version was released with
a massive marketing strategy, and it applied all the necessary changes and
improvements requested by users. As established above, users did not want to
use SharePoint to share documents; hence Microsoft excluded it from the
features that accompanied the latest version. The users also wanted more
power, creative visualizations, mobile experience, and simplicity, which
Microsoft delivered in the new version.
A lot of thought, effort, and consideration went into the creation of Power BI.
When the users were done observing the updated features, they referred to
Power BI as the end-product of the evolution of previous Excel add-ins:
Power View, Power Pivot, and Power Query. Power BI can work outside the
confines of Excel (the latest version is not dependent on the Microsoft Office
installed on your computer).
As of 2019, Microsoft’s Power BI is the leading analytics and business
intelligence platform available on mobile applications, clouds, on-premise
data gateway, data modeling applications, report authorizing applications,
and other utilities.
This book offers a comprehensive analysis of the powerful tools and features
contained in Power BI’s arsenal. It includes the stepwise directions on how to
start a Power BI project and how to share the project with a large number of
users. As a reader, the book will get you familiarized with the basic concepts
of Power BI and how its datasets, dashboards, and reports can be used to give
insights and interactive experiences.
This book will help you become conversant with management techniques and
administration topics available on Power BI. With the knowledge acquired in
the book, you will be able to utilize Power BI’s powerful features and carry
out successful Power BI projects for your organization.

Who is this Book meant For?


This book targets beginners who are planning to start a career as a business
intelligence professional. It is highly recommended for beginners that are
totally new to the BI world and are interested in reading introductory data
modeling topics on Power BI.
It is also an enlightening read for BI (Business Intelligence) professionals
with the responsibility of developing Power BI solutions or handling the
management and administration of Power BI projects in their organization.
The book can also serve as a reference resource for BI developers and
managers, to aid them in the creation and delivery of successful Power BI
projects.

What is Covered in the Book?


Introduction to Power BI – This part is mainly for beginners. It shows how
to get started with Power BI, upload data, use quick insights, make reports,
decorate reports, create visual interactions, save reports, and manage pages.
Dashboard features – provides guidance on how to invite users from within
and outside an organization to see a dashboard, shows how to create a group
workspace, and view Power BI reports on mobile devices.
Loading Data from different sources into Power BI desktop – shows readers
how to load data into Power BI from different sources of data, explains what
Query Editor is, how to load data into Query Editor, and types of data
sources. This chapter also gradually guides the reader on how to explore the
Power BI desktop.
Data Transformation – shows readers how to transform data with the help of
Query Editor. The chapter describes the Query Editor environment, explains
the function of each button in the window, and shows how to use them to
achieve your goal. The chapter dabbles a bit into the transformation steps
possible on Power BI and gives instructions on some of the most popular
transformation steps. Steps like how to add, remove, rename, reorder, choose,
and filter columns. It also shows how to perform some activities on rows.
Data Models – this bulky chapter goes into the rudimentary of data modeling
on Power BI Desktop. It shows you how to create a data model, describes the
Power BI Data View environment, highlights the different data types possible
on Power BI, shows you how to arrange data in Power BI, exploit tables, use
calculated columns, and how to add measures to your data model. It also
offers a little on DAX language.
The flow of the book is designed for the readers to follow and apply the
instructions given as they are reading along. The book is full of practical
tutorials and examples that stimulate understanding in readers. This approach
is enlightening and exciting because it will create a classroom-like
environment for the reader and encourage the reader not only to visualize but
also actualize the step-by-step form of instructions given in the book.
Chapter One:
Introduction to Power BI

Microsoft Power BI is a Self-Service Business Intelligence (BI) platform that


delivers tools for analyzing, collecting, sharing, and visualizing data to its
users. For new users accustomed to using Excel’s environment, performing
actions on Power BI is not so difficult and requires just a little bit of training.
There are two different versions of Power BI available depending on the
payment plan and its use;
Power BI Desktop: a free version designed for small scale
business owners
Power BI Plus: a paid professional version available to its users
after payment of a monthly subscription fee. The payment plan
comes in two packages depending on the number of users able to
create and consume contents. Power BI Pro allows users to create
contents and share with other users. It comes at a monthly rate of
$9.99 per user that has access to the content and edits. Power BI
Premium allows a user to license the contents created and stored
in the premium account. Only the creator of the content can edit,
the other users only have access to view it. The price of the
package varies depending on the number of users allowed to
view the content.

Power BI is available for download on Android, iOS, and Windows devices.


You can download it from any of the authorized platforms such as Play store
for Android and website for Microsoft.

Who are the People Using Power BI, and Why?


It is commonly used by data scientists, data analysts, BI professionals,
department representatives, and decision-makers in organizations.
Management executives, department representatives, and decision-makers
use Power BI to develop reports and make predictions that improve sales and
marketing strategies of an organization. Department representatives primarily
utilize the tool to observe how individual employees and the department as a
whole are reaching and advancing towards the organizational goals.
Power BI can also be used by people without any analytical background
(when necessary) to create reports. With Power BI, they can connect separate
data sets, clean and transform the data into a model, and construct charts or
graphs to visualize the data.

Important Features of Power BI


The first time Power BI was released in 2011, it was called Project Crescent.
The renaming occurred in 2013, and it was rebranded as Power BI for
Microsoft Office 365. The original version was based on features present in
Power Query, Power Pivot, and Power View. Eventually, it was released as a
separate product in 2015 and stood apart from the other tools. Microsoft
updates Power BI every month, and every time they update Power BI, it
comes with new and exciting features. Some of those features include;
Quick Insights
Artificial Intelligence
Hybrid deployment support
Cortana integration
Common data model support
Customization
Integration APIs
Modeling views
Self-service data preparation

The features that are essential for your tutorial will be explained in the
appropriate chapter in the book.

How to Download Power BI


This book is a manual on how to operate Power BI. What do you need a
manual for if you don’t have the equipment yet? So, your first mission is to
download Power BI, and a few worksheets and databases to get started. You
may use the online version of Power BI, but for effective learning, it’s better
to use offline resources that are available to you anytime. To download the
offline Power BI Desktop, carry out the following steps;
Visit the Power BI Desktop website.
Click on the “Download Free” button on the homepage
Select your language of choice and click “Download.”
Select the files to install and click “Next.” The file will begin to
download on your PC.
Install the .exe files with your package installer and launch the
program.
Log in to your Microsoft Office account.

Getting Acquainted with Power BI


To fully understand the process and enhance the learning process, a scenario
will be created. The scenario involves Mike Edwards, a budget manager at
Enigma industries. The company produces and sells cigars in several
countries through local retail shops and online stores. In each of the
countries, the product is available, the region managers have the
responsibility of estimating figures for the yearly budgets of their countries.
When this was done, Mike’s continues the job by combining all the different
budgets and create a bigger budget for his bosses. Mike intends to create a
2019 budget for Enigma by compiling all the budgets of the regions. A
colleague informed him of Power BI’s ability to give insights on data and
simplify his work. He was amazed and promised to try it out. Mike Edwards
just downloaded Power BI. He’s never used it before, but he has created
several budgets with Excel.
NB: This book assumes you know your way around Excel to a certain
degree.
NB: Power BI is not only used for budgeting; this is just a scenario
designed to show you how to use Power BI to create a sophisticated
report. Follow and replicate the steps Mike takes to acquaint himself
with Power BI as this is also his first time using the tool. Your
purpose for using Power BI may not necessarily be budgeting so
don’t bother yourself with the complexities involved in creating a
budget, just absorb the steps he took on Power BI to achieve his goal.

Power BI Desktop Options


Like you, Mike Edwards just downloaded Power BI, and he is running the
application for the first time. The first thing he notices is the Power BI splash
Screen which prompts him to “Sign in” his Power BI account. There is the
pop-up menu on the right side of the screen that seeks to give him more
information on Power BI. The options available are:
What’s New- which gives information on the latest updates and
changes made to Power BI
Power BI Blog- which redirects the user to the blog dedicated to
Power BI
Forums- which takes the user to the community created for
Power BI users to interact and ask questions
Tutorials- this option provides information on how to carry out
basic steps on Power BI

Since Mike is not interested in any of the options given, he clears the menu
by clicking the “X” symbol at the top of the menu. He proceeds to Sign in
with his Microsoft 365 Office account.
He uses his work email to register and sign in as Power BI does not allow
personal emails like “[email protected] or
[email protected].”
NB: The preferred email format allowed is “[email protected]
Once he signs in, he is directed to a blank Power BI Window (environment).
Here, he notices the dashboard canvas, the Power BI ribbon at the top of the
screen, the view type at the top left side of the screen under the ribbon, the
page selector at the bottom left side of the screen, and the visualization
properties and field lists at the right side of the screen. Generally, the
environment is simple and organized for easy access. The functions of each
the options listed above include:
_ Power BI Ribbon: These contain the categories of features needed to
develop dashboards on Power BI. The categories on the ribbon are:
File
Home
View
Modeling
Help

The function of each category will be discussed at the right junction.


_ View Type: These options allow you to select the page you want to be in
view. The options available are
Dashboard view- screen where the dashboards and reports are
created
Data view- screen where the data calculation takes place
Relationship view- screen where data from multiple sources are
joined together.

_ Dashboard Canvas: this is the whiteboard that takes up about 80% of the
window. Designing of visualizations and dashboards take place here
_ Visualization Pane and Palette: the pane is the area for filtering and
allocation of element attribute. Formatting of prepared visualization also
occurs here. The palette contains the sample structure of all the possible
visualizations on Power BI. Selection of the shape of a visual takes place
here.
_ Fields list: contains all the fields in the source data that can be used to
create a visualization
_ Page selector: it is used to switch from one page to another
Uploading Data into Power BI
Mike Edwards finds what he is looking for on the Home ribbon, after
observing the components of each tab on the ribbon. He was looking for a
way to upload the data he has into the software. He sees “Get Data” and
clicks on it. This brings up a dialog box, which shows him all the possible
places he can import data from. Since the data he has is in Excel format, he
selects Excel and clicks “Connect.”
Windows Open File dialog pops up, and he selects the location of his data
file, in this case, RegionBudgets.xlsx. Immediately he opened the file; Power
BI started the uploading process.

How to Create your First Visualization


Now that the data is safely imported into the Power BI Desktop, you will be
able to create charts, graphs, maps, tables, and any other element available on
the visualization palette with your data. Before you proceed to work on the
data, you need to understand a few terms that will be used in the course of the
book
Visualizations: these are visual representations of the data
uploaded into the software. It may occur in the form of charts,
gauges, graphs, maps, matrixes, basically anything available on
the visualization pane. Any of the words italicized can be used
interchangeably with visualization in the course of the book.
Dashboard: The dashboard is a canvas that can contain the
visualizations created. The user may prefer to create his
visualization on multiple dashboards rather than creating all his
visuals on a single dashboard. There is no strict rule about it, as
long as he understands how he arranged the visuals. Page and
dashboard can be used interchangeably, so don’t be bothered if a
page is referred to as a dashboard. This is because a page
contains all the possible visualization, just like the dashboard.
Report: this word refers to the total pages (dashboards) created
from a single data source.
Datasets: all the data sources uploaded to Power BI
Now that you understand the words, it’s time for Mike Edwards to create his
first visual.
Sale
Country/Region Brand Month Sale 2016 2017 Sale 2018 Budget
United Kingdom Victory January 23,234.00 1,945.00 416.66
United Kingdom Victory February 6,370.00 7,059.00 416.66
United Kingdom Victory March 4,352.00 416.66
United Kingdom Champion January 12,418.26 5,735.48 1,559.87 3,041.66
United Kingdom Champion February 31,770.26 2,937.90 3,041.66
United Kingdom Champion March 3,689.85 5,489.23 11,163.94 3,041.66
United Kingdom Dark Horse January 1,271.55 3,236.31 9,945.86 7,875.01
United Kingdom Dark Horse February 7,372.34 5,995.55 1,303.01 7,875.01
United Kingdom Dark Horse March 11,364.07 2,767.32 3,437.26 7,875.01
Germany Victory January 6,270.00 1,125.01
Germany Victory February 11,790.00 2,072.00 1,125.01
Germany Victory March 5,016.00 3,215.00 8,151.00 1,125.00
Germany Champion January 6,249.47 719.55 1,250.00
Germany Champion February 8,711.52 2,934.00 1,780.00 1,250.00
Germany Champion March 22,928.18 559.65 1,250.00
Germany Dark Horse January 8,172.92 93.78 6,800.52 4,166.67
Germany Dark Horse February 4,672.77 7,585.29 1,707.56 4,166.67
Germany Dark Horse March 12,430.38 2,683.39 5,318.82 4,166.67
Germany Dark Horse April 9,626.06 241.77 3,324.75 4,166.67
United States Victory January 5,016.00 3,492.00 2,500.00
United States Victory February 5,794.00 10,336.00 2,500.00
United States Victory March 2,508.00 188.50 2,500.00
United States Champion January 8,459.46 1,968.69 1,300.00

Excerpt of Mike’s Data on Excel


The first column in the excerpt shows the countries that sell Enigma’s
products; the second column shows the brand. From the excerpt above, you
will notice that Enigma industries have four brands of cigars
Victory
Champion
Dark Horse
Victory II (not shown in the excerpt)

The third column shows the month of the year, and its relevance depends on
the fourth to the seventh column. The fourth to sixth column shows the sales
of the product per month. The seventh column shows the budget allocated to
each country for each brand per month.
The fields column highlights each of the columns in the Excel file Mike
uploaded.
Country/region
Brand
Month
Sale 2016
Sale 2017
Sale 2018

The country field has a globe symbol in front of it, which means Power BI
recognizes the column contains the name of several countries. The fourth to
the seventh field has the “Σ” symbol in front of it. This means that Power BI
recognizes the fact that the column comprises of only figures.
NB: If Power BI does not recognize the components of your data, it might
create a problem for you when trying to create a visual.
Mike wants to create a visual for the sales of each cigar brand per month, but
he is quite confused about what to do next, he notices a button on the home
ribbon and decides to use it. The button is called “Ask a Question.” He clicks
the button, and it produces an input box. He types in “create a visual for sales
by month.” Power BI automatically generates the necessary column from his
data. Mike isn’t satisfied with just the column, he wants a visual. Being a
naturally curious and intuitive person, Mike clicks on the type of visual he
wants to create with the columns Power BI generated. He clicks on the
“Clustered Column Chart” on the visualization pane (to find out the name of
a visual on Power BI, hover your pointer on the shape and the name will
automatically come up). Alas, a visual is automatically generated on the
column Power BI generated.
How did this happen? With Power BI, it is possible to carry out operations by
asking questions. The feature that allows this to happen is called natural
language queries. With this feature, you can ask Power BI to perform
operations, in the same manner, you ask your colleague or junior to perform
an operation. Not only will Power understand your question (query), it will
also suggest meaningful actions it can perform on your data. This feature
does not require the user to have any previous skill on Power BI, you just
need to have an idea of the type of visuals you want and the feature will help
you bring it to life.
To save the visual created, click on the pin button in the top right corner of
the visual on the desktop. This will save the visual to your dashboard, and it
will be available to you on any device you connect to your Power BI. When
you click on the pin button, a dialog box will pop-up about where to store the
visual and what to name it. If it’s a free Microsoft account, you will only be
able to save to existing dashboard. You can name the visual anyhow you like,
as long as you remember what the name represents.

How to Create a Visual Manually


Mike needs another visual that shows the total sales of the three different
countries on a single chart. Since he wants this on a new dashboard, he went
to the page selector and clicked the plus button. This presented a fresh page
free of any visual.
He wants a matrix that shows the values to be used for the visualization, so
he clicked the matrix symbol on the visualization pane, then he took his
pointer to the fields and selected the columns he needed from the data, which
was
Country
Sales, 2016

To represent the data selected on the matrix, he wanted a pie chart. To do


that, he selected the pie chart symbol on the visualization pane. Immediately,
Power BI generated a pie chart for the data highlighted.
Mike was able to create a pie chart without any previous knowledge of Power
BI because the environment was simple and easy to understand. Do you have
a particular type of visualization you want to create? Upload your data file
now and start creating. Emulate Mike and select the fields you want to use
and the type of visual you want to create, it is pretty easy when you do so. If
you get confused at any point, do not forget to use the “ask a question” button
on the Home ribbon. It will help you create the visuals in your imaginations.
To show the importance of selecting fields, Mike will create another
clustered column chart but with different fields selected.
First, he selects the field he wants to use, which are country,
month, and sale 2016
Then he selects clustered column chart on the visualization pane

The combination of the fields and selected visualization created-


This visualization is different from the first one created because the fields
selected are different. When creating your visual, only use the relevant fields
for accuracy.

How to Arrange your Dashboard


You have been creating pages to hold new visuals, however, it possible to
create all the visuals on a single page. You just need to resize and arrange
them.
Resizing a Visual
To do this,
Click on the visual, it will produce four corners
Move your pointer to any of the corners
Adjust until you are satisfied with the size

Arranging a Visual
To do this, you need multiple visuals on the page.
Resize the visual on the page with the steps above
When you are done resizing, click on the blank white space on
the dashboard to deselect the visual
Create another visual by selecting the necessary fields and a
visualization of your choice.
Immediately a different visual will be created on the page. Adjust
and resize it to your taste.

Quick Facts to Note:


➢ You can create as many visuals as you want on a page, but for a
legible and well-arranged dashboard, it is advisable to create only
four visuals on a page.
➢ You can change the visualization of any visual on the dashboard
with a click on the visualization pane. The same applies to the Fields
that make up the visual.
➢ With the simplicity and ease of creating a visual on Power BI, you
can easily create four different visuals in less than 10 minutes. Once
you have uploaded your data file, your visual is just a click away.

The Interaction of Multiple Visuals on a Dashboard


For this part, you need to upload data to Power BI if you have not been
following practically before. Mike’s data will be used as an example. Closely
observe the following steps performed on Mike’s data,
He clicked on the “+” button in the page selector to create a new
page
He created a slicer by clicking on the necessary field and
selecting the slicer symbol on the visualization pane. Slicers can
only allow the selection on one field, and in this case, it was
“brand.”
He resized the visual till it was about one-fourth of the page
He created another visual, this time it was a clustered column
chart using the fields:
Brand
Country
Sales, 2016
He resized it to fit the right side of the screen beside the slicer on
the dashboard. With this, half of the dashboard is occupied.
He then created two more visuals, an ArcGIS map, and a matrix.
The matrix was created with the same fields as the clustered
column matrix while the map is similar to the slicer and only
allowed the selection of one field, which was country.
He resized both visuals to fit the bottom half of the dashboard.

In general, the dashboard he created looks something like this:

To see the interaction between the four visuals created, Mike clicked on the
slicer visual and selected one of the brands, for example, Champion. If you
were able to get or create a data similar to the one Mike has and performed
the actions Mike performed above, you would notice the change that occurs
across all four visuals. The clustered column changed to show only the sales
of Champion in the three countries, the map didn’t change because all four
brands were sold in the same countries, and the matrix changed to only
include the total amount generated for the sales of Champion brand in all
three countries. Check out the difference in the visual below and the visual in
the previous image.
The same type of changes that occurred above will happen again upon the
selection of another brand in the slicer.
To check this out, Mike selected Victory II in the slicer and noticed that all
the visuals changed to reflect only the properties of Victory II. He selected
the other brands available and noted similar changes.
This change does not only happen when an option in the slicer is selected.
Out of curiosity, Mike clicked on one of the countries (Germany) on the Map.
The visuals changed to highlight the sales that happened in the country. The
clustered column chart changed to reflect the sales of each brand in the
country and dulled the remaining, the matrix changed to show the total sales
the country generated in 2016. There is no change in the slicer because the
same brands were sold in the three countries. Check out the visual Mike was
able to produce by selecting a country on the map visual:
As you can see, clicking on a particular point in a visual may result in a
change in all the visuals on a dashboard. Play around by selecting random
points to notice the change it will cause, you will learn this way because the
next time you are creating a visual similar to this, you will know how to bring
to life the kind of dashboard you want.
This shows the dependence and interactivity of dashboards on Power BI. This
feature is only a little example of the powerful features Power BI has to offer.

Introduction to Quick Insights


Quick insights, a recent feature added to Power BI with the new update, uses
artificial intelligence to analyze a dataset uploaded to Power BI. It utilizes
sophisticated algorithms to create interesting patterns and analysis that helps
the user understand the report better.
To use Quick Insights, right-click on the report, you want to perform the
analysis on your dashboard and select the “Analyze” option. Note that this
feature does not work with all visuals. To be able to use this feature, your
report has to be in the following visuals;
Stacked bar chart,
Stacked column chart,
Clustered bar chart,
Clustered column chart,
Line and stacked bar chart, and
Line and stacked column chart.

If your report is not in any of the visuals above, the analyze option will not
show up when you right-click the report. When the Analyze button is
selected, it will bring up another option, “Find where this distribution is
different.” Click on that option too, and an analysis will be performed on
your report. The analysis can be generated within seconds, or it can take
longer, it depends on the size of the report.
Mike wants to know if he missed something in the analysis of his report, so
he decided to try out the Quick Insights feature. The report he wants to check
is the third visual he created, the clustered column chart on the sales of 2016.
The analysis of the report took about two seconds, then generated two quick
insights, one on sales 2016, the other one on month.
Since Power BI does not have any previous knowledge of your business or its
economic condition, it will only interpret the result based on the data
uploaded. It cannot imitate your brain’s understanding when interpreting the
numbers, therefore quick insights should only be used when you want to
confirm an analysis, find out if there is something you missed in the
interpretation of your data, or to generate fresh ideas. In some cases, the
quick analysis insights produce may not be relevant to the purpose of the
report, but this is very rare, and if it does happen, it will likely reveal a hidden
gem in the numbers causing the deflection from the course.

Formatting of Reports
With Power BI, a user can create multiple visuals in record-breaking time.
The visuals are contained within a report. Most times, professionals use
Power BI with the intention of generating a report for presentation during a
meeting. Just creating a visual is not enough, the report has to be arranged,
decorated, and formatted to be presentable to colleagues. Power BI offers a
lot of ways to enhance the look and feel of a report resulting in a presentation
that will leave your audience in awe of your presentation skills.
How to format a report
The process of formatting a report is not so difficult as Power BI does not
require a different technique to format each type of visual. Therefore, you
only need to learn a few basic techniques.
Create a visual.
Make sure the visual is still selected, then click on the Format
icon in the visualization pane. The icon is in the form of a paint
roller.
The format icon will generate a drop-down menu with the
following options.
General
Legend
X-axis
Y-axis
Data colors
Data labels
Plot area
Title
Background
Lock aspect
Border
Tooltip
Search
Style
Grid
Column headers
Row headers
Values
Subtotals
Grand total
Field formatting
Conditional formatting
Category label
Word wrap
Selection controls
Slicer head
Items, etc.

Not all the options listed above will come up for one visual. The options that
are featured in the drop-down menu depends on the type of visual selected.
NB: It is possible to format multiple visuals at the same time as long as they
are of the same type. Two clustered column charts can be formatted at the
same time, while a map and a slicer can never be formatted at the same time.
The major reason for this is because the formatting pane will generate
different format options for a map and a slicer, and this can’t be joined
together.

Borders
This formatting option is common to all the visuals on Power BI. It creates a
boundary around the visual that separates it from other visuals. To create a
border
Click on the visual
Click on the paint roller symbol
Scroll down till you see the border option and click on it
Turn the switch button on
Select the color of the border
Adjust the size of the border to your taste

Background Color
The option of a background color is also available to all visuals on Power BI.
This option allows a user to change the background color of a visual and
differentiate it from others, especially if the visuals are of the same type and
have similar data. All visuals have a default background color, white. To
change the default color
Click on the visual that needs a change in background
Click on the format icon (paint roller)
Scroll down to back-ground color
You do not need to switch it on as it is already on, all you need to
do is to select a color from the palette and adjust the transparency
until you are satisfied.

Titles
While the title formatting option is not available to all visuals, it’s quite
relevant to the message and delivery of some. You can use the automatically
generated title of some visuals based on the selected fields, or you can adjust
it to a title of your choice. To change the default title of a visual
Click on the visual
Click on the format icon in the visualization pane
Scroll down to the title option, switch it on if it isn’t
From the drop-down menu created, type in the new title you
want, the color of the title, the background color of the title
ribbon, the font, alignment, and the size of the title.

Grid
This option is particularly used for visuals containing rows and columns,
such as table and matrix. The grid option adds lines (gridlines) to separate the
values in a table visual. To create a grid
Select the visual you want to grid
Click the format icon
Scroll down to the grid option
You have two options, a vertical grid and (or) a horizontal grid
For the vertical grid, select the color of the grid
Adjust the size of the text in the visual
Adjust the outline weight (thickness of grid)
Select the row padding and the image height.
For the horizontal grid, there are two additional options of
“horizontal grid color” and “horizontal grid thickness.”

NB: You can activate both types of grid, but you have to do it one after the
other. Finish filling in the requirements of the first one before switching to
the other type of grid off.

Data Colors
This is available to all visuals with a color. The option allows the user to
decide what color is best to represent the data. Giving data a color makes it
different from other data in the visual, and during a presentation, it will be
easy to identify a particular data point. To change the color of a data on
Power BI;
Click on the visual
Click on the format icon in the visualization pane
Scroll down till you see data color, it will generate a drop-down
menu which contains all the default color of your data.
Click on the group of data whose color you want to change and
click on your desired color from the palette. Automatically the
color of the data will change in the visual.

There are many more formatting options available on Power BI, the ones
mention above are just the basic options that you can adjust in minutes. If you
want to explore other format options, create each type of visual on the
visualization pane, and adjust the format options available to find out their
uses. This should only be done for practice visuals as it may not end up in a
visual that is presentable. The only thing you will gain from such a visual is
the knowledge of what the formatting option does and how to apply it.

Modifying a Report
You already know how to create a report, now you need to know how to
manage and modify it. This will involve the creation of new pages, the
renaming of pages, the deletions of pages, the moving of pages, the
duplication of pages, and scrolling through numerous pages. The pages on
Power BI are much similar to those on Excel, the way Excel users can
separate data on different pages, Power BI users can also separate visuals on
different pages.

How to Create a Page


You already learned a method on how to do this in The Interaction of
multiple visual on a dashboard. If you didn’t catch the method;
Method 1: Click on the plus button in the page selector corner to create a new
page. The page selector is on the bottom left corner of the screen.
Method 2: Click the New Page button on the Home ribbon to create a blank
page. The ribbon is at the top of the screen.
It’s not very difficult to create a page, is it?

How to Rename a Page


To be able to differentiate between pages easily, they need to have a unique
name. To rename them from their default name which is the page number,
Double click on the tab with the page name, the default page
name will be highlighted
Type in the name you desire
Press Enter. Click on a blank space in the dashboard to confirm
your changes. If the name of the tab remains as the one you
typed in, the renaming was a success.
How to Delete a Page
This should only be done when the page is no longer relevant to prevent the
loss of valuable information. To delete a page.’
Hover your cursor on the tab of the page, it will produce an “X”
symbol after a few seconds. Click on the X to delete the page
Clicking the symbol will generate a dialog box, which will warn
you of the danger of deleting the file. If you still want to delete,
click the Delete button in the box. All the visuals and data on the
page will automatically be removed without a trace.

How to Move a Page


This is done to change the default arrangement of a page. By default, a page
is arranged in the order of creation, to change the natural order,
Click on the tab you want to move
Hold down the tab and drag it to the position you want it to stay.

It does not take blood and sweat to move a page, it can be done in two
seconds.

How to Duplicate a Page


If you want to reuse the template and background of visuals you already
created on a page, you don’t need to start the process all over again. Just copy
the entire page and adjust it to what you want. To duplicate a page
Hover your cursor over the tab of the page you want to copy
Right-click on the tab, it will generate a few options. Click on the
Duplicate Page option. An identical copy of the page you
selected will automatically be created.
You can also duplicate a page by clicking on the New Page
button on the Home ribbon.

How to Scroll through Pages on Power BI


It is very stressful to scroll through pages one by one, especially when you
have a report with numerous pages. Just like on Excel, you can access a page
on Power BI by clicking on the tab. You can also use the scroll button in the
page selector corner to move between pages very fast. There are two scroll
buttons in the page selector corner, each button has an arrow facing away
from each other. The direction of the arrow shows the direction it will move.
Chapter Two:
Sharing the Dashboard

Mike Edwards still has a long way to go with his budget. With the skills he
learned in chapter 1, he was able to create a dashboard on the first round of
analysis. For the next stage of the report, he needs to involve other members
of his budget team. Depending on the feedback he receives from his
colleagues, he will be able to advance to the next stage with his budget. This
chapter will you, the reader, how Mike was able to share his dashboard with
his colleague using the in-built features of Microsoft Power BI.

How to Invite a User to View a Dashboard


The first person Mike wants to share his dashboard with is his partner, Perri
Johnson. He was able to do that with the following steps
He opened his Power BI desktop application.
He clicks the “Share” button on the Home ribbon. The button is
located at the extreme right side of the ribbon, directly under the
“Publish” button.

NB: The share feature is only available on paid accounts, users with free
accounts will not be able to share access to a dashboard.
Clicking the share button generates a dialog box. The dialog box
has two tabs, one is named Share and the other Access. The
Access tab shows the people that already have access to the
dashboard. When Mike clicked on the tab, only his name was on
the list, and it was tagged “Owner.” On the Share tab, he saw an
input box for the email address of the recipient. Under the email
box, he saw another input box for an optional message to the
recipient. Below both boxes were the permission boxes, which
allows him to choose the activities the recipient of the access can
perform. The three permissions available include
Permission to share the report to other users
Permission to create new content using your
datasets (this permission was not included
before, it came with the latest update on Power
BI)
Permission to receive email notification about
details of the report.

The type of activities the user can perform is left to you, in this case, Mike.
Mike inputs Perri’s email address as [email protected].
Power BI did not allow him to input the address in full before it
automatically generated Perri’s email address. This is because
Perri is a registered member of Enigma industries, and Power BI
has access to the email addresses of all workers in the domain.

NB: It is possible to share the report with people that are not members of the
organization, and it is also possible to share with more than one person at a
time.
Mike added an additional message to inform Perri about the
progress of the report and the type of feedback he needs on the
report.
The last item on the Share tab is the URL (website link) of the
report.

Perri will receive an email containing the link and message from Mike. If
Perri is already a user on Power BI, she will be directed directly to the report,
but if she is not a user, she will have to register and create an account to gain
access to the report.
NB: You can also send the reports to users outside your organization with the
same steps listed above. Power BI will recognize the fact that company email
does not belong to your organization and will point it out to you. Ignore the
warning and continue with the process. Once the user receives the email, he/
she will be able to access the report.
Another way to share your contents with users outside your organization is to
publish the report to the web. The publish button is directly above the share
button. Click it and publish the report on the web. This feature converts the
report into a web link. The major disadvantage of this method is that anyone
with a working internet connection and the address of the link can access it.
There will be no restriction for the viewing of the report. This method
involves the exposure of delicate company information to the general public,
so do not use this method unless your organization authorized the publishing
of this report.

How to Create a Workspace


Perri has approved the report and has adjusted it in the relevant places. The
report is now ready to be viewed by your teammates (the budget managers of
each country that sells Enigma’s product). Mike doesn’t want to share the
report separately to each team member because there are more than 20 people
on the team, and each of them will have different editing ideas. Sending the
report to them separate will cause a clash of ideas and several
misunderstandings. Mike reasons that if each of them has access to a single
report at the same time, they will be able to combine ideas and generate a
better report within a short period of time.
Before Mike joined Power BI, he heard of a feature called Group Workspace
that allows multiple users to edit a single report at the same time and leave
messages for each other on the changes they made. Mike was able to access
this feature with the following steps:
He opened the Power BI application on his PC
He clicked on the “Workspace” option on the navigation pane
The option generated a menu that had an input box, which served
as a search engine for workspaces and a button named “Create A
Workspace.”
Mike clicked on the button. This will automatically generate a
dialog box. The dialog box instructed him to name the
workspace, provide a description for the workspace, and upload a
picture for it (optional).
When he was done filling in the dialog box, he clicked save to
finish.
A welcome screen was displayed for the new workspace. Mike named his
workspace Budget 2019, therefore the welcome screen displayed “Welcome
to the Budget 2019 workspace.” To upload a file to the workspace, he clicked
the get files button on the welcome screen.
Mike found that it was impossible to transfer reports from his dashboard to
the workspace. Power BI does not allow the transfer of reports from
dashboards to workspace. Mike would have to recreate the report Perri
adjusted on the workspace. Regular users of Power BI create group files on
the workspace instead of their personal dashboard to prevent the loss of time
involved in recreating a report.
Within minutes Mike was able to replicate his old report due to the ease and
simplicity of working on Power BI. The next item on the list is to add
members to the workspace, he was able to do that in the following steps:
He clicked on the workspace menu
From the menu generated, he left clicked the three inverted
ellipses beside the Budget 2019 Workspace. This generated
another menu.
The had two options
Workspace Settings
Workspace Access

Mike clicked on the Workspace Access button.


On the dialog box generated, Mike saw his name as the owner of
the workspace. He also saw an input box that allows him to input
the email address of his coworkers.
In the second box, he clicked the category the owner of the email
fell into. The four categories include
Admin
Member
Contributor
Viewer.
When he was done with both boxes, he clicked the “Add” button.
He kept repeating the process until all 20 members of the team
were added.

NB: Only users with paid accounts can create workspaces, it’s not allowed on
free accounts.
You can restrict the activities of users on your workspace by placing them in
the right category. For example, Mike wants all 20 team members to be able
to edit the report, hence he registered all the team members in the contributor
category.

How to Share a Report on Mobile Devices


For any reason, you may want to view your Power BI reports on your phone
or tablet. In Mike’s case, he wants to get advice from a close friend. After
office hours, Mike met up with his friend Steven at a restaurant. Steven is the
budget manager of a company that sells electronic products. During their
conversation, the budget Mike was making came up, and he wanted to show
Steven some of the visuals he created. Since he wasn’t with his laptop, he had
to access it on his phone. With the following steps, Mike was able to access
his reports,
He downloaded and installed the mobile version of Power BI
from the authorized store. Play Store for Android and iTunes for
Apple
He signed in to his account on the app.

After signing in, he was able to access all the visuals he created on his
dashboard. He was able to access the report because he was already signed in
on his Power BI Desktop. It’s possible to use the desktop version without
signing in, but as it says on the splash screen when you first launch the
desktop app, to get the most out of the software you have to sign in.
The mobile reports are not editable and have no interactive functions.
Basically, the app is only good for viewing and accessing the reports on the
go.
Chapter Three:
Loading Data from Different Sources

Before you can create a report or perform analysis on Power BI, you need to
load your data into the software. The data may be from different sources and
exist in different formats. Whatever or wherever you get your data from, you
have to access it, restructure it, clean it up, and sometimes join separate data
from different sources together before you can create a data model for
dashboard and reports. The beauty of Power BI is that you can do all of this
on the Power BI Desktop without employing the use of other data structuring
tools and software.
Power BI Desktop will help you discover, load, clean, and modify your data,
that’s one of its area of specialty. With the app you will be able to achieve the
following;
Data discovery: Discover numerous data sources containing
possibly useful data. The sources may be from private or public
domains.
Data loading: Once you have selected the source of your data,
upload it to Power BI Desktop for restructuring and shaping.
Data modification: Adjust, filter, and clean the data until it is
presentable and workable.
Data shaping: Combine all the data you uploaded (if you
uploaded more than one) to create a unified data model.

In most cases, the four steps above are not usually carried out individually
and may be blended into a single process. It is possible that you may have
cleaned and structured the data before you loaded it into Power BI; in that
scenario, you don’t need to bother yourself with the process all over again.

Power BI Desktop Query Editor


In Chapter 1, there was a brief tutorial on how to upload an Excel file to
Power BI Desktop, however, this chapter will help you take your limited
uploading skills to the advanced stage. The chapter will teach you how to
upload your data into the Query Editor before uploading it directly to your
workspace. With the Query Editor, you will be able to adjust, filter, and
cleanse the data before you start creating reports. If your data is clean, you
can jump the process and start creating your own data model. The Query
Editor feature will be fully discussed in the next chapter.

The Different Data Sources Allowed on Power BI


Power BI allows you to upload and manipulate data from different sources.
The sources include;
➢ Database,
➢ Files,
➢ Online services,
➢ Azure, and
➢ Other.
NB: Microsoft is constantly updating and adding new features to Power BI,
by the time you are reading this book there may be additional sources
available, sources that are not mentioned in this book.

File-Based Data Source


Power BI can access data located on a file in your system. It can even upload
an entire folder if needed to access the data. The type of file sources readable
by Power BI are:
Excel – it can read Excel files created in the 97 to 2016 format.
CSV (comma-separated-format) – these are text files that follow
the CSV format
XML – these are XML files written in a format readable by
humans
Text- general .txt files
Folder – an entire folder can be uploaded if it contains files
readable by Power BI
SharePoint – connects to the SharePoint folder and upload files
in it
Microsoft Access – connects to the Access folder and upload
files in it
JSON – Power BI can extract data from a .json file

NB: Power BI classifies Microsoft Access as a database source, but for this
book, we will treat it as a file, not some a database on some server.

How to Load a CSV Data File


The first thing you have to do when dealing with a CSV is to open the file
outside Power BI and determine what needs to be done on the file. If it is
arranged and workable, you can load it directly into Power BI but if it still
needs some polishing, consider loading it into Query Editor first. The
following steps will show you how to load the contents of this file to Power
BI and Query Editor
❖ Open the Power BI Desktop App on your system.
❖ Exit the splash screen
❖ Click the “Get Data” button on the Home ribbon. As you know, the
act will generate a dialog box
❖ Select “File” among the options given
❖ From the categories of files acceptable click “Text/CSV.”
❖ To leave the get data dialog box click “Connect.” This will generate
the Windows Open dialog box
❖ Find the location of your .csv file. Select it and click “open.”
❖ On the dialog box generated after clicking open, there will be a
sample of the file you want to upload, and below the sample, there
will be three options to select from- Load, Edit, and Cancel.
Cancel – you already guessed what this does, it cancels the
entire actions you performed from clicking the Get Data
button.
Load – this loads the file directly into Power BI for use
Edit – this option loads the file into Query Editor for editing.

The choice of the option to click on rests on your shoulders, but for the
purpose of explaining how to load .csv into Query Editor click “Edit.”
❖ On the Query Window, you will be able to add another source and
to perform all the necessary edits for the file. When you are done
editing, click “Close and Apply” on the Home ribbon. This will close
the Query window and take you back to the Power BI Desktop data
window.
NB: The process to upload a .txt (text) file is identical to that of CSV.
Though they have their little differences, they can be accessed in the same
manner.

How to Load an XML Data File


As you probably know since you are using it, an XML file comprises of text
formatted in a specific way. To load an XML file into Power BI or Query
Editor;
❖ Click the “Get Data” button on the Home ribbon. This will generate
a Get Data dialog box
❖ Select “XML” among the options given
❖ Click “Connect” to leave the dialog box
❖ On the Windows dialog box generated, find your XML file and
click “Open.”
❖ A navigator dialog box will open, and you will be required to select
the dataset you want to load. To choose a dataset, click on the
checkbox beside the name. The contents of the selected dataset will
be displayed on the right side of the dialog box.
NB: An XML file can contain multiple datasets at once. Power BI allows the
user to choose the dataset he wants to upload at that time, meaning only a
part of the file may be uploaded at the end of the process.
Note that not all data files will be like XML which allows you to load
multiple datasets at once.
❖ Until a data set is chosen, the Load and Edit button will be disabled.
After choosing a dataset, you can either click Load, Edit, or Cancel.
❖ Whatever option you choose (except Cancel) when the process is
done, you will land on the Power BI Desktop data window. You will
be able to access the datasets uploaded in the Fields column on the
left side of the screen.

How to Load an Excel Data File


This is the most popular type of data file uploaded to Power BI, most users of
Power BI are also professional Excel users. The followings step will cover
how to load an Excel file into Power BI;
❖ To take a shortcut from the normal process, click on the small
triangle button directly below Get Data.
❖ From the small menu generated, click Excel
❖ Locate the file you want to upload and click Open.
❖ Like XML, Excel can contain multiple datasets at once. Click on the
dataset(s) you want to upload to enable the Load and Edit button.
❖ Edit the file in the Query Window by clicking Edit or access the file
immediately on Power BI by clicking Load.
❖ The datasets selected can be accessed in the Fields column on the
right side of the Power BI Desktop data window.

How to Import Queries and Models Created in Excel to Power


BI
Since the majority of Power BI users have experience in using Excel to create
data models, Microsoft designed a way for the users not to lose the data and
start again by allowing them to import their worksheets and Power View
dashboards from an Excel file into Power BI. The transfer of data from Excel
to Power BI is quite easy and can be achieved with the following steps;
❖ Open your Power BI Desktop app and exit the splash screen
❖ Click the File tab on the ribbon
❖ From the drop-down menu created, click “Import.”
❖ From the options listed in the import menu, click “Excel Workbook
contents.” This will generate the Windows Open dialog box
❖ Locate the file containing your Power Pivot and Power View data
and double click on it to open.
❖ Once you open the file, Power BI will display a message while
importing the file. The message basically states the following
Power BI does not work directly with Excel workbooks,
so it will only extract the items in the file that are
compatible with Power BI’s operating system.
From the data imported from the Excel file, Power BI
will create a different file which contains the compatible
items
The importing and file creation process will take a few
minutes

Under the message, there are two buttons “Start” and “Cancel.” Click on Start
to begin the import process
❖ You will be able to see the progress of the importing process. Once
the process is completed, Power BI will display the summary of the
items imported. When you are done checking the items that
successfully imported, click Close to exit the summary dialog.

How to Load a Windows Access File or Database


The reason for classifying MS Access as a file-based data source is because
the data source has to be present as a file on your system before you can
access it. MS Access databases can contain hundreds of tables and
worksheets, which are accessible to Power BI Desktop users. You don’t even
need to install Access on your system before you can access it with Power BI
Desktop.
To import an MS Access file to your Power BI Desktop, carry out the
following steps,
❖ Open your Power BI Desktop app and exit the splash screen
❖ Click on the Get Data button on your Home Ribbon
❖ From the menu generated, click “More.” This will generate another
list of options
❖ From the options generated, click “Database.”
❖ From the types of database listed, select “Access.”
❖ After selecting Access, click “Connect” to generate the Windows
Open dialog box.
❖ On the Windows open dialog box, locate the Access file on your
system. When you find the file, click on it and press “OK.”
❖ The navigator dialog will automatically generate all the tables and
queries present in the file, click the checkbox beside the datasets you
want to upload. When you are done, click “Load.” To differentiate
between the types of data, the navigator dialog box uses two symbols
A table
Two windows on top of each other.

The table represents Access tables while the windows represent Access
queries.

How to Load a JSON Data File


Using a JSON data file is a relatively new way of storing large amounts of
data in a small file. Most JSON files are small in size but can contain millions
of data at once. JSON is an acronym for JavaScript Object Notation. To
import a .json file into Power BI and Query Editor, carry out the following
steps,
❖ Click the “Get Data” button on the Home ribbon. This will generate
a Get Data dialog box
❖ Select “JSON” among the options given
❖ Click “Connect” to leave the dialog box
❖ On the Windows dialog box generated, find your .json file and click
“Open.”
❖ The file will be transferred directly into the Query Editor. In the
Query Editor, the file will appear as a list of records, and on top of
the file, there will be a List Tools Transform ribbon. On the ribbon,
click the button named “To Table.” This will generate the To Table
dialog box.
❖ Below the options listed in the To Table dialog box, there are two
button-OK and Cancel. Click the OK button to convert the lists in the
.json file to tables. The dialog box will close.
❖ Back in the Query Editor, the list of records will change to column
of records. Beside the column header, a button will appear. The
button has a symbol on it, two curved arrows going in opposite
directions. Click on the button.
❖ The button will generate a small dialog box. In the dialog box,
uncheck the option (box) that states, “Use original column name as a
prefix.” Close the dialog box by pressing “OK.”
The .json file will then appear as a standard dataset with the columns named
appropriately and containing the right data. A .json file cannot be uploaded
directly into Power BI without editing it in the Query Editor. If you upload it
directly, you won’t be able to access your data, and any analysis you perform
will give false results.

How to Load an Entire Folder into Power BI


Eventually, you will want to upload more than one file at once, probably a
hundred. The thought of having to upload each of them one at a time is a
discouraging thought. Power BI has a method of getting data that simplified
the entire process, it allows the entire contents of a folder to be uploaded at
once. However, before the folder can be loaded, it has to fulfill the following
requirements
✓ The files in the folder have to be of the same type. This means
that if you want to upload a hundred files present in a folder, the
hundred files can either be Excel or XML, not XML and Excel. If
the folder contains more than one type of format, the importing
process may not be a success.
✓ The data in the files have to be arranged in a similar format.
✓ All the files have to be in a single folder, you cannot upload
more than one folder at once.
To import an entire folder into Power BI,
❖ Open a new Power BI file. To do that, click on the File tab on the
ribbon and select “New.” A blank file will be created.
❖ You must know the drill by now. Click Get data, click File, select
Folder, and then close the dialog by clicking Connect.
❖ After Connect, the folder dialog box will be generated. As you can see,
it is different from the Windows open dialog box. In the folder dialog
box, click Browse to find your file. When you find your file, click on it,
and you will be directed back to the folder dialog box.
❖ Once you are sure you have the right file, click “OK.” The contents of
the file will be displayed in the navigator dialog box.
❖ Click Edit to take the files to Query Editor, Load to take the files
directly to Power BI, and Cancel to stop the entire process. Now there is
another option that makes importing folders different from others. Click
“Combine” to join all the individual files into one. This is the reason
why the files had to be of the same format, and its contents had to have
the same structure.
❖ If you click on Combine button, it will generate a pop-up menu. On the
menu, click Combine and Load. This will generate the combine files
dialog box. In the box, select the sample file to be used to order the
combination of the files.
:. The combined file will be structured in the format of the sample file. It’s
best to have all the file ordered in the same manner because using this
method may scatter the data in the file. Note that there is a “Skip files with
errors” option at the bottom of the box, the option is to command the machine
to skip files that are not in the same format or order as the sample file.
❖ Click OK to start the combination process. Once it is done, the
combined file will be loaded into Power BI Desktop.

How to Load Selected Files in a Folder


If you are not interested in loading all the files in a folder into Power BI
Desktop, Power BI provides you with the option to connect the folder to the
Desktop without actually loading all the files in the folder. To connect the
contents of a folder to Power BI Desktop, carry out the following steps;
❖ Open a new Power BI Desktop file
❖ Click the Get Data button on the ribbon
❖ Click File, select Folder among the options generated, and click
Connect.
❖ Locate the folder you want to connect in the dialog box generated and
click OK
❖ This time around, instead of clicking Combine among the options
generated, click Load. The paths to the files in the folder will be listed
in the Fields column of the new Power BI Desktop file.

How to Create your Own Data on Power BI Desktop


Sometimes the data you need may not be available on a file. Power BI
developers added a feature in one of its updates that catered for this need. The
Feature allows you to create your own data directly on Power BI. Imagine
you already loaded some datasets into Power BI and you're about to start
creating a report, but in the process of creating your first visual, you realized
that a necessary dataset is missing from the files loaded and the file
containing the data is not on your system. What are you going to do then, if
you can’t work on the other data without that dataset and you know the
contents of the file, you just need to find a way to get it into Power BI
Desktop? No need to head over to Excel, Access, or any other Platform to
create your data, Power BI Desktop has got you covered.
Creating your data on Power BI Desktop is easy just carry out the following
steps,
❖ On the ribbon at the top of the screen, click Enter Data. It is two
buttons away from “Get Data.”
❖ A dialog called “Create Table” will be generated. In the dialog box,
input the name of your dataset in the box below and fill in the details
of your data in the rows and column provided. If you need more
rows, click on the asterisk “*” symbol at the end of the column and if
you need more columns, click on the asterisk symbol at the right side
of the column provided.
❖ When you are done filling in the data, click Load at the bottom of
the dialog box to import the dataset into the Power BI Desktop
mem0ry.
NB: This feature is designed to help out with small amounts of data. If you
need to input huge amounts of data; head over to Excel or use a software that
can handle huge amounts of data, the “Enter Data” option is for emergency
cases where small datasets end up missing, and it is only effective when the
user has knowledge of the contents of the missing dataset.

Database Data Source


The world is full of data, and most of them are in databases on the internet.
Fortunately, Power BI is able to connect to most of them, even the ones that
are not so recognized. This part of the chapter will cover how to import and
load data directly from the database or data warehouse into the Query Editor
or Power BI Desktop. The chapter may not be able to cover all the possible
databases, data websites, and data warehouses, however, it will cover the
major ones, and this will give you an idea of how to approach the rest. Let’s
get on with it.

Relational Databases
The difficulty you will face when trying to load a data file from a relational
database won’t be from Power BI, rather it will be from the Guardians of the
data on such databases. Once you can get through the logins, special
passwords, and other security roadblocks, loading the data into the Power BI
Desktop becomes easy. This book will not be able to teach you how to pass
the guardians, but it will be able to teach you what to do when you pass the
guardians.
The various relational database Power BI Desktop can link you to are listed
below;
➢ SQL Server database
➢ Access database (you already know this, it has been covered in the
chapter)
➢ IBM DB2 database
➢ Oracle Database
➢ IBM Informix database
➢ IBM Netezza
➢ MySQL database
➢ PostgreSQL database
➢ SAP HANA database
➢ Sybase database
➢ Teradata database
➢ Amazon Redshift
➢ Impala
➢ ODBC data sources
➢ OLE data source
You will be able to connect to all the databases listed above and import
records of the data tables that you are permitted to access.

How to Import Data from SQL Server


You won't need to install any special software to import the data from the
SQL server into your Power BI Desktop. The approach to import the data is
direct. The method used here also applies to Oracle and DB2 database. A
great advantage of importing from this server is that you will be able to
import several table and data files at once. To connect your Power BI
Desktop to an SQL Server, carry out the following steps;
❖ Start afresh, create a new Power BI file on your desktop application.
❖ Navigate your cursor to the Home ribbon at the top of the window.
On the ribbon, click the small triangle below the Get Data button.
❖ On the menu generated from the small triangle, click SQL server.
Immediately, a dialog box for it will pop up.
❖ In the dialog box, there are two text boxes for the server and
database. Type the address or name of your SQL Server in the first
box. The SQL server does not necessarily have to be personal, it may
also belong to your company. Either of them is acceptable.
❖ In the second box, you may enter the name of the database you want
to import. This is optional, but to make the process faster, ensure you
have the knowledge of the name of the database.
❖ After filling the two boxes, click the Import option below the boxes.
❖ Click OK to end the first stage of the importing process. Another
dialog box will pop up on the screen, the SQL Server database dialog
box.
❖ The new box generated is going to ask you detail about your access
to the website. If your Window login details is authorized to access
the server, click the “Use my current details” option. But if you have
an alternative way of accessing the server and database, click the
other option, which is “Use alternate credentials.” This will activate
the Username and Password box below the options. Input the
authorized username and password into their respective boxes.
❖ Click Connect to start loading the data file. This will generate a
Load dialog box, which will show the progress of the file being
imported.
NB: If your internet connection is unavailable, and your Windows login
details (or typed-in username) is not authorized to access the file, your
Connect command will generate an error, and you won’t be able to import the
file. So make sure your internet is working, and you are authorized to get that
file.
❖ When the file is finished loading, the load dialog box will close
and give way for the Navigator dialog box. On the Navigator dialog
box, click the boxes of the tables you want to import from the
database.
❖ Finally, click Load at the bottom of the dialog box to import it
directly to Power BI or click Edit to send it to the Query Editor first.
You know the drill.
Now you have successfully imported a data file from the SQL server
database into your Power BI Desktop. Go ahead and start transforming it in
the Query Editor or creating reports if you loaded it directly into the Power
BI Desktop. You can apply the same methods above for most of the relational
databases, especially Oracle. The major difference is that in the Get Data
dialog box, instead of clicking SQL Server, click Oracle or whatever
relational database you want to import from.

How to Import Data from ODBC Sources


The reason why this particular relational database requires it’s own separate
instruction is that it requires you to install a special software before you can
begin importing. The software is called Open Database Connectivity, the full
meaning of the acronym ODBC. There are different ODBC drivers for
different data sources. An ODBC driver written for a particular data source is
going to be slightly different from other data sources and cannot be used for
any other data source. If you have a data source that requires ODBC, it’s best
to download the driver that is particular to it. For this part of the book, you
will need to install an ODBC driver to be able to carry out tutorial
instructions. You can still follow along if you don’t wish to install any, but
the best understanding comes from practice. Carry out the following activities
to import a data file into the Power BI Desktop through from an ODBC
source;
❖ Install the ODBC driver of your data source. If your data source
requires ODBC drivers, it will have a download link on the website.
Download the software based on the processor of your desktop, if
your desktop runs on a 32-bit processor, make sure that is what you
download and if it runs on a 64-bit processor, make sure you don’t
download the version for 32-bit.
❖ After the installation, launch the ODBC Administrator app. Make
sure you install this software too if you don’t have it already.
❖ On the tab generated for the ODBC Administrator App you, click
on the System DSN button at the top.
❖ Click the Add button, it’s located on the left side of the screen. This
will generate a list of all the drivers installed on your system. The
driver you installed in the first step will appear on this list, and any
other driver you have installed on your desktop.
❖ Select the Driver for the data source you want on the list.
❖ After selecting the driver, click the Finish button. The dialog box
for the driver you picked will be generated. Generally, all ODBC
drivers have the same interface with little minor changes to
distinguish it from others, but the major features of the drivers are
usually the same, which is why the following instructions below
apply to all ODBC drivers.
❖ On the ODBC driver dialog box generated, click Next. The button
will take you to the tab where you will configure your data source.
❖ On the Next tab, fill in the Name and Description of your data
source in the boxes provided. When you are done filling the boxes,
click Next.
❖ On the new page generated, type the IP address of the database you
want to connect to. Click Next when you are done.
❖ On the next page, select the database you want to connect. From this
point, the pages that will be generated will be significantly different.
Just follow the trend of the previous instructions and input the
required information and click Finish, Next, Done, or whatever final
button your driver uses.
❖ When you are “Done,” the driver for your data source will be
installed in the ODBC administrator app. Click OK to exit the
software.
❖ You are back to the Power BI Desktop. Open a new file in the
application, you will need a fresh start.
❖ By now, you should know the drill. Click the Get Data button,
select Others, choose ODBC in the list generated, and finally click
Connect to get started.
❖ In the ODBC dialog box generated, there will be a menu box for the
data source names. Select the name that matches the driver you
installed above.
❖ Click OK at the bottom of the box to select that data source.
❖ In the Credentials dialog box generated, click the Database option.
Enter your username and password details in the appropriate box. The
requirement of the third box is optional, ignore it if you don’t have
the details.
❖ Click Connect to get to the next stage.
❖ In the navigator dialog box generated, select the data files you want
to import, then click Load or Edit to import the files to Power BI
Desktop and Query Editor respectively.
While this entire process may look tiring, remember that you only have to
install the driver once. Once it is installed, you can get any file you want
easily by clicking on the Get Data button as the first step.
The other databases, data warehouse, websites, and clouds mentioned in the
beginning do not require much stress. With the knowledge and experience,
you have gained from importing data from the sources explained in this book,
you should be able to get the requirements of their importation easily. If you
have data on any of data sources not explained, try to import it now as a form
of practice.
Chapter Four:
Data Transformation

Loading your data into Power BI Desktop is just the beginning of your work.
After loading the data, you have to modify, clean, and filter it to make sure it
is ready to be used. This chapter will cover the numerous methods and
techniques you can use to transform your data. The numerous methods and
process can be grouped into four major categories. The categories do not, in
any way, define the order the tweaking or editing process goes. The
categories are just meant to intensify your understanding of the process.

Data transformation: This category involves the addition and


the removals of rows and columns, the renaming of columns, and
the filtering of data.

Data modification: This category involves the altering of


original data present in rows and columns.

Increasing Datasets: This category involves the addition of


more data to data sets. This process involves expansion of an
original column into multiple columns.

Combining Datasets: This involves the joining of two or more


datasets into a single data pack.

Power BI Desktop Query Editor


This topic was briefly discussed in the previous chapter. Chapter 3 only gave
you a little idea of what this feature entails. The full course will be broken
down and downloaded for you in this chapter. You already learned how to
load data into Query Editor in the previous chapter, but you did not learn how
to use it.
It’s not all the time a dataset is available in a ready to go format. Most times,
they need to be cleaned over and over till it is ready for use. Query Editor
helps you achieve this goal directly on Power BI, you don’t need to stress
yourself by carrying out the editing process in another software. Power BI
Desktop offers two options when loading data into the software, you can
either load it first in the Query Editor, or you can load it directly for use.
Despite offering these two options, it does not really matter whichever you go
for when loading the data. Power BI is not strict on which comes first, if you
load the data directly and you noticed the need for editing while creating a
report, you can easily go the Query Editor window from the Data Window.
You can perform the changes you need, then go back to creating to your
dashboard. With this feature, Power BI made editing a data set easy and fast.
The editing tools available on Power BI Desktop are quite sophisticated and
can rival the tools available on top editing software. The amazing thing is
Power BI Desktop offers the tools for free. To access them on another
software, you need to pay hundreds or thousands of dollars per year. While
the tools are sophisticated, they are quite easy to use as long as you know
what you want to achieve on the data.
The files undergoing a transformation in the Query Editor are called queries.
To carry out a query, you need to select the data you want to use and begin
the importation process. If you're not sure whether to perform a query before
loading or after loading, the following scenarios should help you decide;
➢ If you are positive the data in question is clean and well-structured,
skip the Query Editor process and load it directly into the Power BI
Desktop.
➢ Do you have multiple datasets that need to be combined into a
single dataset with the same structure? In this scenario, the best
option is to load the data into the Query Editor first. You will be able
to see the contents of the file and combine them before transferring it
into the Power BI Desktop.
➢ Is your data from a database, a warehouse, or an SQL Server? Then
you should probably load the data directly into the Power BI Desktop
because most of the data imported from there are usually clean.
➢ Does the data need to be filtered? Maybe some parts of the data are
unnecessary and may cause confusion while creating the report. If so,
head over to the Query Editor first.
➢ Do you need to change the names of some of your columns for easy
understanding? Do you need to modify the data to make it more
presentable? Then you have to become friends with Query Editor
first.
Your situation may be similar or different from the scenarios above, they are
just listed to help you decide on what option to pick when importing a data
into Power BI Desktop. The more you work on Power BI, the more intuition
you will have on what option to choose.

The Power BI Query Editor Environment


You have to get familiar with the environment of the Editor since the entire
data transformation process will happen in there. Query Editor’s environment
is very different from the Power BI Desktop’s environment. The main
elements of the Query Editor include;

The four ribbons at the top of the screen and the File menu. The
ribbons are named

– Transform
– Add Column
– View
– Home

Query list pane which contains the all the files (queries) added
to the Query Editor. It is found at the left side of the screen.

The data window is the space where the sample of a query is


displayed. It is located in the middle of the screen

Query Settings, the pane is located at the extreme right side of


the screen. It contains the list of all the transformation performed
on the query.

The Formula bar displays the code that performs the


transformation. It is located directly under the ribbons at the top
of the screen

The status bar is found at the bottom right corner of the screen.
It shows the number of columns and rows in the query, and it
also shows the date the query was loaded into the Query Editor.

The contents of the cell are shown at the bottom left corner of
the screen. It states the exact number of rows and column
present in the query.

Applied Steps
Beneath the Properties menu on the Query Settings pane, there is a menu
called Applied Steps. The menu contains a list of all the possible
transformations that can be performed on a query. As a transformation
process is carried out, the menu automatically checks the checkbox beside the
performed transformation. It is able to detect every little step performed on a
query and records it for future purposes. It is a form of recorder that shows
you all you’ve done on the query.
When you click on a box in the Applied Steps menu, the queries displayed in
the Data window will change to reflect the effect of the particular
transformation the box covers. Each step you perform on the query is named,
this allows you to trail your every step in the modification process. The
manner in which the steps are named will be discussed when the possible
transformation steps are explained later in the book.

The Four Ribbons


You already know the name of the four ribbons present at the top of the
Query Editor Window, but you don’t know their functions. Each button
present on the ribbon will be discussed in this chapter. You don’t have to
memorize all the functions. You just need to have a general idea of what the
buttons do and the button to click when you need to perform a particular
modification. You could always refer to this book later on when you need to
carry out a transformation you don’t know much about. All the buttons and
their possible functions will be listed and explained.

Home
Below are the description and functions of all the button present on the Home
ribbon as of the last update on August 2019. The ribbons are arranged
according to the way they are located on the ribbon.
Buttons Functions
Close & This is the first button on the Home ribbon.
Apply Selecting this button will save all the
changes performed on the query and close
the Query Editor window. You should only
use this button when you are done with the
transformation process.
New Source This button allows you to add more queries
to the one present i the window
Recent This button lists all the queries you have
Source edited on the window recently. It also
allows you to open them again in a separate
window different from the one you're on.
Buttons Functions
Enter Data This allows you to create your own
custom-made data in the Query Editor
Data Source This gives you control over the data
Settings sources already connected to the Query
Editor
Manage Parameters Grants you access to modify the
parameters defined for the query file
Refresh Preview This performs a refresh on the sample
query
Properties Shows the basic properties of the query
file, such as the size, the name of the file,
and the date it was created.
Advanced Editor Shows the editor of the M language used
in data modeling
Manage Allows you to copy, delete or cite a
query
Choose Columns Gives you the power to select which
columns to retain among all the columns
available in a query

Remove Columns Grants you the ability to delete one or


more unnecessary columns in the query
Keep Rows This allows you to choose the number of
rows to keep in a query, counting starts
at the top of the table.
Remove Rows This allows you to remove a specific
number of rows from the original
number of rows in a column. Counting
also starts at the top of the table.
Sort Arrange (sort) the table using a specific
column in the query as a sample
Split Column Divides a single column in the query into
other columns after a fulfilling a
particular requirement
Group By Assembles the columns into categories
based on the contents of the columns
Data Type Allows you to choose a data type and
apply it to a particular column
Use First Rows as Gives you the ability to convert the
Headers function of the first row in a column.
The first row stops being a simple row
and becomes the title of the entire
column.

Replace Values This button carries out the search and replace
operation in the Query Editor. It only
changes the values specified in the search
box to the values in the replace box. It won’t
affect the other values that are not present in
the search box.
Merge Queries This allows you to combine two or more
queries together. It joins the columns and
adds the values to make a single query.
Append Queries This allows you to add the data from a
previous query to the query opened in the
Query Editor. This does not join the column
or adds the values as Merge Queries does.
Combine Files Joins and combine the data from multiple
files into a single table. This is possible as
long as the files are of the same format, have
the same number of columns, and have the
same type of data in each column. This is
different from the Append query because it
does not deal with previous queries, it deals
with files.
Transform
The transform is the richest of the ribbons in terms of features and functions.
It has about 32 buttons on it, and they all have different functions. The
buttons on the transform ribbon can be classified into seven major categories,
they are;
❖ The Table Transformation Buttons: These are the buttons in charge
of the transformation of a table as a whole. They include:

Buttons Functions
Group By This button can also be found on the Home
ribbon. It assembles the columns into
categories based on the contents of the
columns.
Use First Rows as This is also present on the Home ribbon. It
Headers grants you the ability to convert the
function of the first row in a column. The
first row stops being a simple row and
becomes the title of the entire column. As
you can see, this affects the table as a
whole. That’s the reason why this button is
in this category.
Transpose This button interchanges the directions of
the rows and columns. With this button, the
rows become columns, and the columns
become rows.
Reverse Rows This button interchanges the order of a
table. The bottom rows become the top
rows, and the top rows become the bottom.
While this might look confusing, the
interchange occurs in a specific order, the
last become the first, and the first becomes
the last. The remaining rows follow that
order.
Count Rows This performs a count operation on the
table and automatically replace the data in
a row with the number the row falls on in
the table.

The Column Transformation Buttons: These buttons are in charge of


transforming a column. The buttons can only affect the dynamics of a
column. They include:

Buttons Functions
Data Type With this button, you can select the type of
data present in each column. It could be
text or numbers.
Detect Data Type This automatically detects the data type
present in each column and uses it to
determine the appropriate data type to
apply to the column.
Rename This allows you to change the name of any
column in the query.
Replace Values This button performs the same function as
the one on the Home button. It carries out
the search and replace operation. It changes
the values specified in the search box to the
values in the replace box. It won’t affect
the other values that are not present in the
search box.
Fill Copies the content of an entire cell and
dumps it into an empty column. You can
decide the order it copies the content, it
may be from above or from below.
Pivot Column This button converts the contents of a
column into the titles of other columns.
This means that each row of a particular
becomes the title of different columns.
Unpivot Columns Performs the opposite of what the Pivot
Column button does. It takes the titles of
each column in the query and converts it to
rows in a single column, while the data
present in the columns are merged to
become a single column. At the end of the
day, two columns are formed- the column
for all the titles and the column for the
data.
Move This button can change the position of a
column
Convert to List When clicked the button will convert all
the columns in the queries to a list

❖ The Text Transformation Buttons: Performs actions that are


related to the text in the query. The text transformation buttons are:

Buttons Functions
Split Column Divides a single column in the query into
other columns after a fulfilling a particular
requirement
Format Formats the text in the columns.
Regularizes the use of lowercase,
uppercase, and the capitalization of the
text. It also removes excess space in the
columns.
Merge Columns This button performs the opposite of what
the Split Column button does. It joins two
or more columns together to form a single
column. It separates the data in the column
by placing them on different lines.
Extract The function of this button is quite
complicated. In a way, it limits the number
of characters that can exist in a column.
After clicking the button, you must specify
how many characters should exist in the
column. With the button, you can also set a
condition that requires each cell in each
column begins with a specific character
and replace the data in a column with a
defined subset of data.
Parse This button converts the contents of a
column into a .json, .xml or .txt format
document.

❖ The Number Transformation Buttons: These buttons are only


corned with the values in the query. Their actions are directed
towards transforming the numbers in the table. Buttons in this
category are:

Buttons Functions
Statistics This performs statistical operations on the values
in the columns. The possible operations include
the calculating of the total sum of the values, the
mean of the values, the median, pinpointing the
largest value, the smallest value, calculating the
Standard Deviation, performing a count of all the
values in the column.
Standards This button also performs calculations on the
values in a column, but unlike Statistics Button
the operations performed here are rather basic. It
is used to calculate the addition, subtraction,
division, multiplication, integer division, and
modulus of the values in a column.
Scientific This is also another button that performs
calculations. The calculations here are scientific.
Calculations like finding the Square, Raise-to-
power, Cube, Square root, Exponent, Factorial,
and Logarithm of values in a cell.
Trigonometry Performs trigonometric operations like finding the
Cosine, Sine, Tangent values of each row in a
column.
Rounding This button approximates the values of data in a
column. It can either round it up or down
depending on the factor specified.
Information Tests condition of data in a column. The possible
results are Even, Odd, Positive, and Negative.

❖ The Date and Time Transformation Buttons: Include buttons that


are helpful when some of the data in the queries are time-related.
The buttons are:

Buttons Functions
Date This button only works when the values
involved are dates. This could be values
stating the day, month, or year. It isolates
the date element from others in the column.
Time This button only works when the values
involved are related to time. This could be
values stating the hour minute, seconds, or
nanoseconds. It isolates the time element
from others in the column.
Duration This button takes account of two values
and measures the duration, be it in minutes
or days. Before this operation can work,
the Editor has to recognize the values in the
columns as dates and time.

❖ Structured Column Buttons: These buttons are only activated


during the combination process of two or more queries. They help to
structure the combined columns of the queries, they are;

Buttons Functions
Expand This button allows you to combine two identical
queries together. It joins the columns and adds the
values to make a single query.
Aggregate This button allows you to sum the values of the
two queries together. Basically, it performs an
expanded function of the Standards button. It adds
the numeric values in the columns of two queries
and presents it in the current query.
Extract Values This button converts the values in a column to text
and extracts it.

❖ The Run Scripts Buttons: Carries out instruction written in


machine language. Languages like “R,” and many more. There is
only one button in this category, it is:
Buttons Functions
Run R Scripts Runs instructional codes written in R

Add Columns
This ribbon does not exist just for you to be able to add columns to a query, it
can break a single column into multiple columns, and it can add new columns
that contain information on date and calculations from existing columns in a
query. The Add column ribbon is divided into four categories, namely:
❖ The inserted column buttons: These buttons are in charge of
adding new columns to a query, they include:

Buttons Functions
Column From This button allows you to select an existing
Examples column as the sample of how the new
column to be created should be. After
clicking the button, you will have to select
the sample column to begin the process.
Custom Column This button creates a new column whose
contents are custom made from existing
columns. The new column is created with a
formula that uses variables from existing
columns.
Invoke Custom Using this button will require the
Function knowledge of “M” language. After clicking
the button, an input box will be generated
for the code of the language. When you are
done with the code, the interpreter of
Power BI Desktop will run the code and
apply it to the necessary part of the query.
Conditional This button creates a column based on an
Column existing column fulfilling a particular
condition. When a column fulfills the
requirements, interpreted values from the
column will be added to the new column.
Index Column This button creates an index column to
identify the existing rows. The index
column numbers each row in the query
with a unique number or roman numeral.
Duplicate The function of this button is pretty basic.
Column It merely duplicates the contents of a
column.
❖ The text column buttons: The functions of the buttons here are
similar to the “Text transformation tool” in the Transform Ribbon.
The buttons present in this category are:

Buttons Functions
Format Formats the text in the columns. Regularizes the
use of lowercase, uppercase, and the capitalization
of the text. It also removes excess space in the
columns.
Merge Columns This button joins two or more columns together to
form a single column. It separates the data in the
column by placing them on different lines.
Extract The function of this button is quite complicated.
In a way, it limits the number of characters that
can exist in a column. After clicking the button,
you must specify how many characters should
exist in the column. With the button, you can also
set a condition that requires each cell in each
column begins with a specific character and
replace the data in a column with a defined subset
of data.
Parse This button converts the contents of a column into
a .json, .xml or .txt format document.

❖ The number column buttons: The buttons in this category deal


with columns that contain numbers in a query. With the buttons, you
will be able to manipulate the numbers and perform actions on them.
The buttons include:

Buttons Functions
Statistics This performs statistical operations on the values
in the columns. The possible operations include
the calculating of the total sum of the values, the
mean of the values, the median, pinpointing the
largest value, the smallest value, calculating the
Standard Deviation, performing a count of all the
values in the column.
Standards This button also performs calculations on the
values in a column, but unlike Statistics Button
the operations performed here are rather basic. It
is used to calculate the addition, subtraction,
division, multiplication, integer division, and
modulus of the values in a column.
Scientific This is also another button that performs
calculations. The calculations here are scientific.
Calculations like finding the Square, Raise-to-
power, Cube, Square root, Exponent, Factorial,
and Logarithm of values in a cell.
Trigonometry Performs trigonometric operations like finding the
Cosine, Sine, Tangent values of each row in a
column.
Rounding This button approximates the values of data in a
column. It can either round it up or down
depending on the factor specified.
Information Tests condition of data in a column. The possible
results are Even, Odd, Positive, and Negative.

❖ Data and time column buttons: Buttons in this category deal with
the columns that contain details on the time and date of an activity.
The buttons include:

Buttons Functions
Date This button only works when the values
involved are dates. This could be values
stating the day, month, or year. It isolates
the date element from others in the column.
Time This button only works when the values
involved are related to time. This could be
values stating the hour minute, seconds, or
nanoseconds. It isolates the time element
from others in the column.
Duration This button takes account of two values
and measures the duration, be it in minutes
or days. Before this operation can work,
the Editor has to recognize the values in the
columns as dates and time.

View
View is the last column in the Query Editor ribbon but not the least used.
While the significant transformation actions take place in the other ribbons,
the view ribbon is used to monitor the appearance of queries in the Query
Editor. The buttons on the ribbon include:
Buttons Functions
Query Settings This button allows you to choose whether the
Query Settings column should be visible or not.
The Query Settings column appear at the right
side of the Query Editor window, and one of the
items on it is the Applied Steps list.
Formula bar This is not really a button, it’s more of a
checkbox. The checkbox allows you to choose
whether or not the formula bar should appear at
the top of the data window. The formula bar is the
input box where the M language for coding is
written.
Monospaced This is also a checkbox, not a button. It is used to
display the text in the query in a monospaced font
(Courier).
Show Whitespace This is the third checkbox in this ribbon. It allows
you to decide whether you want to see the
whitespace present in the query or not. This
checkbox is always clicked by default, if it’s not
what you want, you have to turn it off.
Go to Column This button allows you to move your cursor to a
particular column in the query. It lists the columns
available, you can go to the column by clicking on
it. It’s a very fast method of shuffling between
columns in queries with large contents.
Always Allow This checkbox allows you to turn on
parameterization.
Advanced Editor This button generates an Advanced Editor dialog
box which shows the codes of the transformation
steps performed on the query.
Query Dependencies This button shows links and dependencies of the
query in the Query Editor.

Transformation Steps in the Query Editor


Now that you know the name and functions of all the buttons in the query
editor, you also need to learn how to apply them. While most of them are
self-explanatory, you may need help to understand the right instance or the
necessary circumstance for a button to be used. This part of the book assumes
that you already have a file imported into the Query Editor. At this point, you
are no longer a novice when it comes to Power BI, so Mike Edwards and his
file problems won’t be used anymore in the book. The rest of the book will
offer instructions that are designed to help you improve your file
transformation skills.

Restructuring the Data in a Query


At the beginning of the chapter, the editing process that happens in the Query
Editor was divided into four; Data transformation, Data modification,
increasing datasets, and combining datasets. It was also stated at the
beginning of the chapter that the classification of the editing process into four
categories was not a clear classification and that the classification was just to
ease your understanding. It will be easy to categorize the restructuring
process of a query under Data Transformation, but data transformation covers
a whole lot more. The editing/transformation steps that fall under this
heading, they include:
➢ Renaming of Columns,
➢ Reordering of Columns,
➢ Removal of Columns,
➢ Merging of Columns,
➢ Removal of Records, and
➢ Filtering of data.
These processes/steps belong to this heading because they affect the general
structure of the data in a query. You will discover more transformation steps
in the future.

How to Rename a Column in the Query Editor


The method available to rename a column in the Editor is quite easy to learn
and memorize. You can rename a column with the following steps;
❖ Click on the column you want to rename. It does not necessarily
have to be the first row in the column, you can click on any part.
❖ Click on the Transform ribbon at the top of the Editor. The default
ribbon is the Home ribbon, you will need to click the Transform
button in the ribbon to display the buttons on the ribbon.
❖ You are interested in the Rename button on the ribbon. Click on the
Rename button, and this will highlight the original name of the
column in the first row. Enter the new name of the column into the
box.
❖ When are done typing, click the Enter button on your keyboard to
save the name.
NB: The moment the name is saved, the Applied Steps column will have an
item on it. The item is called Renamed Columns. If you click on the item, it
will highlight the name of the column you renamed.

How to Reorder Columns in the Query Editor


In the scenario that the rows in your data are disordered, you can arrange
them in the Query Editor of the Power BI Desktop. First, you have to import
the dataset into the query editor. After that, you can reorder the columns with
the following steps;
❖ Click on the header of the disordered column.
❖ Drag the column to the position you want it to be in, then unclick
the column to drop it in that position.
You can also perform this action with a button in the Transform Ribbon;
❖ Click on the column you want to move.
❖ Click on the “Move” button in the Transform ribbon
❖ It will generate a set of options, they are
Left
Right
To Beginning
To End

Click on the direction you want the column to move, keep clicking until it
reaches your desired position.
NB: The name of this process in the Applied Steps column is Reordered
Columns.

How to Delete/ Remove a Column in the Query Editor


Assume you have a data file with excess and (or) conflicting information on
it. Before you can work on that type of file, you need to remove the excess
information, so it does not conflict with the data you need to create your
reports. To remove a column from a query, carry out the following
instructions;
❖ Click on the column you want to delete. If you want to delete
multiple columns at the same time, Hold Control and click on all the
unwanted columns.
❖ When the columns are selected, click on the Remove Columns
button on the Home ribbon. All the columns will disappear
immediately, and Removed Columns will become an item on the
Applied Steps column.
In the scenario that your file is from a database and you only need a few
columns from all the columns available in the dataset, Power BI has a
separate option for such needs. To only keep specific columns from all the
columns available in a query, carry out the following steps;
❖ Hold Control and click on all the files you want to keep
❖ Head over to the Home ribbon at the top of the Query Editor, find
the Remove button and click the triangle below the button. From the
options listed, click remove other columns. Immediately, the
unselected columns will be deleted, and an item named Removed
Other Columns will appear in the Applied Lists column.

How to Choose Columns in the Query Editor


Files obtained from databases usually contain large contents, more than you
may need for your report. To prevent the unnecessary columns from showing
in the Power BI Desktop and crowding your Fields column, you can select
the ones to be displayed. In a way, it is similar to the Remove Other Columns
action performed above but, in this case, the columns are not deleted, just
hidden away from view and cannot be used to perform any action in the
Power BI Desktop. To choose columns to be used to create reports in the
Query Editor, perform the following actions;
❖ Click on the Choose Columns button in the Query Editor. It can be
found at the center of the Home ribbon.
❖ A “Choose Columns” dialog box will be generated. In the dialog
box, there are checkboxes besides all the columns present in the
query (data file). Click the checkbox beside the “Select all Columns”
option at the top of the list to deselect all the columns.
❖ Then, click the checkboxes of the column you want to work on in
the Query Editor and Power BI Desktop. You can search for the
columns you want in the search box at the top of the dialog box, and
you can also arrange the columns alphabetically to make the selection
process easier. Click the A->Z button beside the search box to
arrange the column alphabetically.
❖ When you are done choosing columns, click OK to apply the
changes.
Only the columns selected will be available for use in the Query Editor, and
finally in the Power BI Desktop data window.
NB: This action will not generate an item in the Applied Steps column
because the query will be refreshed and only the columns selected will be
displayed. Since you haven’t performed an action on the new set of columns,
there will be no item in the Applied Steps column.

How to Merge Columns in the Query Editor


Source data files do not always come in a presentable or refined order.
Sometimes data that can exist in a single column may be spread into multiple
columns that may or may not have a meaning. Power BI allows its user to
adjust files like that to have more meaning. The feature that allows the
merging of columns is present in the Query Editor, you can perform the
action with the following steps;
❖ Hold Control and click on all the columns you want to merge.
❖ Click the Transform ribbon to reveal all the buttons on it. Click on
the Merge Columns button. This will generate a Merge columns
dialog box.
❖ Click on the Separator box, it will generate a menu which contains
all the possible options you can use to separate the columns. You can
choose any separator on the list.
❖ In the second box in the dialog box, input the new name for the
merged column.
❖ When you are done filling the two boxes, click OK to start the
merging process.
NB:
There is no limit to the number of columns that can be merged,
any number is possible.
If you don’t name the new column in the dialog box, by default,
it will be named as “Merged” when created. After creation, you
can then rename it with the rename button on the ribbon.
The order in which you select the columns in the first step is
critical. The items in the merged column will be arranged
according to the order they are chosen. This means that the first
column to be selected becomes the first item to appear in the
merged column. Make sure you take note of this fact when
selecting the columns to be merged as it will not be possible to
change the order when the merged column is created. Once the
column is disorganized, you will have to undo the action
(Control Z) and start the merging process all over.
The merging process removes the original columns from the
query. Once the columns are merged, you won’t be able to
perform any action with the old columns. If you still have use
for the individual columns, it is best to duplicate them before
you merge it.
In the separator box in the dialog box, there are several
separators you can choose from. The options include;
i. Colon (:)
ii. Comma (,)
iii. Equals to Symbol (=)
iv. Semi-Colon (;)
v. Space ( )
vi. Tab (->)
vii. Custom

The custom option lets you create a unique separator that is different from the
ones present on the menu. When you click the custom option, an input box
will be generated, and you will be asked to type in the character you want to
use as the separator.
The action generates an item on the Applied Steps column. The
item is named Merged Columns.

How to Select a Specific Column in the Query Editor


In queries with hundreds of columns, moving through the columns one after
the other may become tedious after a while. Power BI’s Query Editor has
simplified this process by creating a quick way to select a specific column
with one of the buttons on its ribbon. To select a specific column, carry out
the following steps;
❖ The button you need to carry pout this action can be found on the
Home ribbon. Find the Choose Columns button on the ribbon and
click the small triangle below it. This will generate a Choose
Columns dialog box.
❖ In the dialog box, there will be a list of all the columns in the
query. The columns will be arranged in the original order they were
saved in the query. To arrange them alphabetically for easy surfing,
click on the A->Z button beside the search box. Find the column you
want to select, click it, and click the OK button at the button to exit
the dialog box.
When the dialog box closes, the column you selected will be highlighted.
NB:
With this method, you can only select one column.
This action does not generate an item in the Applied steps
column since it didn’t cause a change in the query.

How to Manage Rows in Query Editor


So far, we’ve only covered how to manage the columns in a query. It showed
how to select, rename, reorder, move, delete, and merge columns. All the
actions that were used to manage the columns cannot be applied to rows, it
has its own unique set of buttons. There are three basic approaches when it
comes to managing rows in a query. They are;
➢ Keeping specific rows
➢ Removing specific rows
➢ Removing blank rows

How to Keep Specific Rows in a Query


In the scenario that you downloaded or imported a file from a database, the
file will contain more data than you need. Let’s assume you are interested in
all the columns and only need a few rows for your report. In that case, you
will need to find a way to delete the other rows. You can keep specific rows
in a query with the following steps;
❖ Find the Keep rows button on the Home ribbon in the Query Editor.
Click on it when you see it. This will generate a menu.
❖ In the menu generated, there are three options available to pick
from.
Keep Top Rows
Keep Bottom Rows
Keep Range of Rows

What you pick will determine the type of dialog box that will be generated.
1. If you select Keep Top Rows, a Keep Top Rows dialog box will
be generated. In the dialog box, you will see a box, which
allows you to input the number of rows at the top you want to
keep. This means that if you input 10 in the box, only the top
ten rows will be kept.

_ When you are done, click the OK button at the bottom of the
box to finish the process.
_ An item will be generated on the Applied Steps column, the
item will be named Kept First Rows.
2. Selecting the Keep Bottom Rows option will generate a Keep
Bottom Rows dialog box. In the input box, you can type the
number of rows at the bottom you want to keep.

_ When you are done, click the OK button at the bottom of the
box to finish the process.
_ Immediately an item will be generated on the Applied Steps
column, the item will be named Kept Last Rows.
3. The last option is the Keep Range of Rows option. Selecting
that option will generate a Keep Range of Rows dialog box.
There are two boxes in the dialog box, the First-row box and the
Number of rows box.

_ In the First-row box, input the index number of the first row
you want to keep. This is where the counting will start from.
_ In the Number of rows box, type in the number of rows you
want to keep. The number here starts counting from the row
mentioned in the First-rows box. This means if you input 25
in the First-row box and 50 in the Number of rows box, the
rows 1 – 24 will be deleted, 25 – 74 will be kept, and 75
downwards will be deleted.
_ When you are done, click the OK button at the bottom of the
box to finish the process.
_ An item will be generated on the Applied Steps column, the
item will be named Kept Range of Rows.

How to Remove Specific Rows in a Query


You already learned how to keep specific rows, now you have to learn how to
remove specific rows which is the opposite of keeping certain rows. To keep
certain rows in a query, carry out the following steps;
❖ On the Home ribbon, click on the Remove Rows button. This will
generate a menu similar to that of Keep Rows.
❖ In the menu generated, there are five options available
Remove Bottom Rows
Keep Errors
Remove Top Rows
Keep Duplicates
Remove Alternate Rows

Ignore the Keep Duplicates and Keep Error buttons, for now, click on any of
the other options on the menu. It depends on the position of the rows you
want to delete. For Remove Bottom Rows and Remove Top Rows, the dialog
box generated is identical to that of the Keep Top Rows and Keep Bottom
Rows dialog box. Just input the numbers you want to remove then end the
process with the OK button. The item generated in the Applied Steps column
will be named Removed Top Rows and Removed Bottom Rows respectively.
For Remove Alternate Rows, the dialog box generated is very different from
the other options. There are three input boxes in the dialog
First row to remove
Number of rows to remove
How many rows to keep.

Clicking this option is tricky, and it should only be used when you want to
create a new set of data from the original query. To use the alternate row
option;
_ Input the index number of the first row you want to keep in
the first box. For example, 10.
_ Then input the number of rows you want the editor to remove
after the first row mentioned in the box above. For example,
2.
_ Finally, type in the number of rows you want to keep to form
a new query. For example, 10.
The editor will interpret the instructions given above as a command to alter
the query to contain only ten rows. It will take the tenth row as the first row,
delete the next 2 rows after the tenth row, save the original thirteenth row
(add it as the second row in the altered query), and continue the process of
deleting two rows then saving the third until a total amount of ten news rows
are created.
Now you can see the reason why the alternate rows option is a tricky process.
The new rows formed will be totally different from the original rows in the
query. Only use this option when you are totally sure of what the process will
achieve.
NB: When the Alternate rows are created, the step will be named as Removed
Alternate Rows in the Applied Steps column.

How to Remove Blank Rows in a Query


Sometimes, a data file might contain empty columns and rows. In a bid to
clean the file, you have to remove all these unnecessary excesses in the file.
To remove the blank rows in a query, carry out the following steps;
❖ On the Home ribbon in the Query Editor, click on the Remove Row
button.
❖ On the menu generated in the button, click Remove Blank Rows.
This will order the editor to identify and remove all the blank rows
present in the query.
On the Applied Steps column at the right side of the editor, an item will
appear on the list. The item will be named Removed Blank Rows.

How to Remove Duplicate Data from a Query in the Query Editor


One of the most annoying situations that can happen when handling a file is
having a document with repeated data. Creating a report with such a file will
only end badly. Power BI’s Query Editor has a feature that identifies repeated
entries and allows you to delete them in one go. Sometimes, you may not
even notice that a part of the data has been duplicated, this won’t matter in
the Query Editor as it automatically identifies all the cells containing
identical characters. To remove duplicate data entries in your query, carry out
the following steps;
❖ Click the top left corner of the table grid. This will generate a pop-
up menu
❖ On the menu, click the Remove Duplicate option. This will
automatically remove all duplicates and add an item called Removed
Duplicates to the Applies Steps column.
NB: This removal of Duplicate contents is a very risky process, it will delete
all entries with identical characters. If a single character is different, it will
not be counted as duplicate content, so it is pretty accurate in that manner.
The reason why it is risky is that it will remove all duplicate contents, not just
one half, it will remove all. The feature does not allow some of the contents
to be saved, all the entries that look identical will be deleted. This is risky
cause you may need some of the deleted entries when creating your report.
Before you resort to this method, make sure you delete all the columns and
rows in the query you don’t need for your report because some cells may
contain identical contents and result in the deletion of contents you actually
need.
Alternatively, you can check out the duplicated contents before you delete
them. To do this, click on the Keep Duplicates option in the table menu. This
will show you all the contents that were duplicated in the query. Take notes
of all the cells containing duplicate contents that you may still need. Then
delete the Kept Duplicates item on the Applied Steps list to undo the action
or simply press Control + Z. This will take you back to the original query.
There you can manually delete the duplicates of the contents you may still
need so it isn’t deleted along with the other duplicate contents.

Filtering the Data in a Query


As you must know, data files may come with so much unnecessary and
irrelevant information. Before you start creating reports on your dashboards,
you need to filter all the irrelevant parts of the data. Filtering on Query Editor
is much like filtering with a sieve, the menu the column generates becomes
the sieve that filters unwanted entries from critical entries. There are two
basic tactics employed when filtering a data file, they are;
➢ The selection of specific entries or records
➢ Defining the range of the relevant data

How to Filter Data by Selecting Specific Records


This method allows you to choose the particular records you want to use to
create your reports. While this method might be very similar to the Choose
Columns feature explained above, it’s quite different. With Choose Columns,
you will have to select the entire column, but with specific values filtering,
you can choose the parts of the columns you want to keep. It does not restrict
you like Choose Columns. To filter your data file by selecting specific
values;
❖ Click on the small triangle beside the title of the column you want
to filter. This will generate a popup menu.
❖ On the second part of the menu, there is a list of all the entries in the
column. Click the checkboxes of all the entries you want to keep. All
the boxes will be checked by default, simply uncheck the boxes of the
entries you don’t want to keep.
❖ Click the OK button at the end to finish the process. Immediately,
Filtered Rows will appear as an item on the Applied Steps column.
NB: In the spirit of removing irrelevant data, you can click the Remove Empty
option on the menu to remove blank rows from the data. It’s also part of the
filtering process.

How to Filter Data by Defining the Range of Data to be Kept


While selecting the specific rows to keep is more precise, it will become a
laborious process, especially when you are dealing with queries that contain
hundreds of column. Defining the range of the entries to be kept makes the
process easier. You can define the range of the data in a query by;
❖ Click on the small triangle beside the title of the column to generate
its menu.
❖ In the menu, there is a search box above the list of all the rows in
the column. In the menu, type in the entry you want to keep. When
the search results are generated, click the Select all Search results
checkbox to keep all the entries in that category. You can perform
this over and over till all the entries you are interested in are ticked.
This is much faster than selecting the entries one by one.
❖ Click the Ok button at the button to initiate the filtering. The same
Filtered Rows will appear on the Applied Steps column.
The filter popup menu can carry out several actions, depending on what you
order it to do.
If the column contains text, a Text filter option will be available.
With the option, you will be able to set or exclude the presence
of a specific text in the row, set the character the text must begin
with, not begin with, end with, not end with, contain, and does
not contain. This is as precise as it can get.
If the column contains numbers, a Number filter option will be
available. With the filter, you will be able to specify the exact
numbers in the allowed entries and the numbers that must not be
in the entry. You will also be able to set a limit for the values of
the numbers, whether maximum or minimum (greater than, less
than, greater than or equal to, and lesser than or equal to).
And if the column contains time values, date, minutes, seconds
and the likes, a Date and Filter option will be available on the
menu. With the filter, you will be able to determine the type of
dates or times you want to be filtered out and many more.

As it was said above, the filter feature in Power BI is a very powerful tool. It
can even weed out air if you set the right parameters. That was a joke!
How to Save all the Changes made in the Query Editor
You can save the changes made in the Query Editor at any time, even when
you are not done with the transformation process. To save the changes made,
carry out the following steps;
❖ Click on the File menu at the left edge of the ribbon at the top of the
Query Editor.
❖ On the menu generated, click the Save Option. This will generate a
dialog box with three buttons
Apply
Apply Later
Cancel.

At this point, you have to decide whether or not the changes you made in the
Query Editor should be applied to the original data file imported into the
Power BI Desktop. Selecting the Apply option will do just that, it will apply
the changes made in the Query Editor to the original data file.
The Apply later option will save the changes made to the data file in the
Query Editor, but it won’t change the original file in the Power BI Desktop.
Doing this only saves the changes made to the data file in Query Editor,
leaving the original data file in its untouched state.
The Cancel option cancels the Save action you just carried out. Choose the
option that serves your purpose best.
How to Exit the Query Editor
You already learned how to exit the Query Editor in Chapter 3, but that was
just the basic way of exiting the Editor. There are more options that apply
when leaving the Query Editor. To close the Query Editor carry out the
following steps;
❖ Click the first button on the Home ribbon at the top of the Query
Editor. This button is called the Close & Apply button. It will
immediately update the original data file with all the transformations
that took place in the Query Editor and exit to the Power BI Desktop
window.
❖ If you want to have other options, click on the small triangle below
the Close & Apply button. This will generate a pop-up menu with
two options.
Apply
Close

The Apply option will perform the same activities as the Close & Apply
button.
The Close option will close the Query Editor without applying the changes
made in the editor to the original data file. It is best to save the transformation
made in the Query Editor before choosing the option to prevent loss of data.
When you click the Close option, a small notification box will be generated
at the top of the Power BI Desktop data window, imploring you to apply the
changes made in the Query Editor.
The Query Editor is a very powerful tool for editing in the Power BI Desktop,
not all users know how to handle and perform operations with the tool. But
for those skilled in using the tool, and for you reading this book (this chapter
to be precise), cleaning, filtering, modifying, and transforming your raw data
file won’t be so difficult. Once you know how to edit your data in the Query
Editor, any problems that may occur during the creation of reports will not be
from incorrect or improperly structured data. Not all the buttons or features
were explained in this chapter, just the basic and popular editing steps carried
out with the Query Editor were explained. With practice, you will be able to
perform any transformation you want with the tool.
Chapter Five:

Data Models

How to Create a Data Model in Power BI


In Power BI, creating a great visualization is essential, and to achieve this,
you will need an excellent source of data for that. To be precise, there is a
need for specific and correct data to be inputted into the data model of the
Power BI, this way, millions of data from multiple sources can be utilized to
build a framework on which you can base your dashboards and analyses.
Once your data is accessible, there is still a need for a few ground works to be
carried out. As you learned earlier, using query to search, input, and edit your
raw data is basic in the preparation of data for a Data model.
This chapter is going to cover how to create data, model data, and convert
inputted data into a well-structured dataset. This well-structured Dataset
makes it easy for you to analyze your data, get perception and information
from the inputted Dataset. The few topics to be covered are
Defining data types
Exploiting Tables
Creating hierarchies
Creating a joining or relationship between tables
Classifying data
Arranging data in the data model
Creating a sort-by column that secures the dashboard element
in the right sort order

Establishing the relationships between tables is the most basic aspect of data
modeling. You must ensure that your Power BI desktop can derive the
relationship between data on one table and another to get an accurate and
precise result.
N.B- Data modeling can only be done when the data has been inputted into
the Power BI desktop model, i.e., any data changes that occur in the Query
editor must be applied before returning to the Power Desktop BI to prevent
inaccurate results.

Power BI’s Data View Window


When you import data into your BI Desktop, the default Data View ribbons-
Home and Modelling will come into view. The second ribbon, Modeling, is
used for organizing and classifying data and tables. It is also used to add
calculated metrics and column. The Modeling ribbon contains a series of
buttons, and their functions are shown in the table below:
Button Function
New measure It allows the addition of a new calculation
to a table (Data).
Home Table This button allows you to pick a table that
will contain your calculations or value.
New table It allows you to create a new table in the
data file.
Data type The button helps to outline the type of data
you want in a particular column.
New column This button is in control of the addition of a
newly calculated column to a table.
Sort by column This button helps you select the column
containing data that can be used for sorting
the data in another column.
Manage This button allows you to merge tables
relationships (this merging are referred to as
relationships) and also delete them.
Format This helps you define the way numbers
will be formatted in a table.

Before you start creating your own data model, it is important to get familiar
with the tools that will make the process easy to navigate after running the
Power BI Desktop. To achieve this;
Import all the queries to be used.
Switch to the Data View where all tables are visible by clicking
on the Data view icon on the left side of the window.

The Data View window is very similar to the Query Editor window, but there
are some major differences between them. One of them is that only a sample
of your data can be seen in Query Editor while all the dataset are made
available in Data View once it has been imported into the data model.
Another difference between them is that in Data view, you are working with
the entire dataset and modifications are made in line with the dashboard
requirement and specification. A major similarity is that they can both be
used to create calculated columns.
N.B- Always remember that Query Editor is for searching, clarifying, and
merging up while Data View is for enhancing and computing metrics in your
data model. Also, note that you have to close your Query Editor before
modeling your data.
Defining Data Types
There are nine different data types available to you on the Power BI desktop.
When you transfer files from an external source, the Power BI desktop will
try to change it to fit one of the nine data types. The nine different data are
listed below with their description:

Data type Description


Decimal numbers Data types in this category are saved as real
numbers, and they have a maximum 15
significant decimal numbers.
Fixed decimal This saves data as numbers, with the
numbers number of decimal specified.
Whole numbers The data are saved as positive or negative
integers, i.e., 2^63 and -2^63
Date and Time Data are saved in the form of date and time
on the Power BI Desktop. The dates are
valid from January 1st, 1900.
Date Saves data in the form of date
Time Saves data in the form of time
Text Data are saved in the form of 536,870,912
bytes of a Unicode string.
True / False The data are saved in a True or False
format (Boolean).
Binary Data are saved in the form of 0 and 1.

NB: When using fixed decimal numbers, it is easier to avoid the overflow of
calculation errors that occur when using an ordinary decimal number. Also
using decimal numbers creates additional storage.

Exploiting Tables
After you have successfully imported and transformed your data, your next
plan should be to exploit and manipulate the tables. Tables will be used in
place of data because it is mostly the result generated when data are
transformed in the Query Editor. Manipulating tables involves the following:
➢ How to rename a table
➢ How to delete a table
➢ How to rename a column
➢ How to delete a column
➢ Setting width to a column
How to Rename a Table
Imagine you don’t feel comfortable with the name of a particular table that
has successfully been transformed and imported from the Query Editor, and
you wish to change or modify it to another, there are a series of steps to be
taken to achieve this;
❖ Go to the field list which is on the right side of the Power BI
Desktop window, there you will see the name of the table listed.
❖ Right-click on the name, this will generate a menu.
❖ On the menu, click on rename.
❖ Input the new name or modify the former name
❖ Press enter
Remember that Table is the result generated from the transformation of data
by the query, so changing the name of a table will also change the name of
the query

How to Delete a Table


This process is similar to that of changing the name of a table, but instead of
clicking on rename, you click delete. This action will remove the table,
including the series of query that has been used in transforming it. Due to
this, the Power BI Desktop will ask for confirmation before carrying out this
task because any mistake can make you lose not only your table but also your
transformation steps.
Now that you are well acquainted with how to manipulate a table, you need
to be able to perform similar actions within the table.

How to Rename a Column in the Power BI Desktop


Changing the name of a column is a simple and direct action that involves a
couple of steps, which is pretty similar to renaming a table, with the only
difference being the selection of a column instead of a table. You cannot use
a name that is already existing for another column.
When renaming your column, you should put into considerations the Power
BI questions and answer natural language features which will recognize a
name that is mostly used in queries. Also renaming a particular column that is
in a different visualization can cause confusion for you, so it is better to give
this column a name you are comfortable that will cut across the dashboard.
This allows the same data to have the same name.

How to Delete a Column in the Power BI Desktop


This is also similar to the process of deleting a table that was discussed
earlier, deleting a column has some advantages in that it helps reduces the
memory needed to store a dataset. It also helps to increase the time of refresh
operations. This action also has a permanent effect that cannot be recovered
by the undo and refreshing actions. Deleting a column by mistake can be
recovered by shutting the file without saving it. Reopening the file will make
it revert the previous version containing the deleted column. Another method
is adding the name of the deleted column back in the source query.

Setting Width to a Column


Setting the column width is very crucial because this gives certain readability
to your data, i.e., it makes it much easier to understand your data. It is quite
simple and straightforward to achieve this, you can do so with the following
steps;
❖ Place your cursor on the column you wish to adjust the width
❖ The cursor is placed in the column title over its right-hand limit
❖ Adjust the cursor to the left or right depending on your choice

Creating Hierarchies
Creating hierarchies is important in the organization of data, it helps you to
create a structure for your work. This structure helps to understand better the
information you are trying to get across. When creating hierarchies, the
following steps are to be taken;
❖ Switch your Power BI desktop to report view
❖ Click on the stock table
❖ This will take you to a field, right-click on it. In the new hierarchy,
this will be the top-level element.
❖ Click on new hierarchy (make hierarchy will appear which consists
of Make field serving as the top-level element).
❖ The model Field is then dragged to the newly created hierarchy title.
Then you are done creating your hierarchy. This can then be used to create a
table by dragging it to the report canvas where multiple elements that make
up the canvas is put into use. This gives you access to the data in any visual.
They also make starting material for drill-down charts and matrices.
Renaming and deleting of any level in the hierarchy or the hierarchy itself is
also possible if you are not comfortable with it.

Creating Joining’s between Tables


Creating a joining (also referred to as relationship) between tables is
fundamental when you want to create a logical and useable dataset. A Table
relationship occurs when links exist between tables containing data. This
allows the column of data in one table to be used in another table. A typical
example is Invoices line and Invoice tables. They have been created in such a
way that meaningless data duplication can be avoided. The technique used to
create this table is referred to as relational modeling. Both invoice line and
invoice table share a field that links them together in a way that allows the
user to see data from both tables. Any element in both tables that would have
repeated is seen in the header table i.e. invoice table, while the non-repeating
data are stored in a detailed table, i.e., Invoice line table. Although it is
possible to store this data in one table, it will create unnecessary repetitions
that will increase the size of the Power BI files. Real-world data that are
imported from other database have such links existing between them. When
you decide to use multiple data source for your analysis, create a link that
joins the table in a common field. If you are knowledgeable about SQL, it is
easier to create a relationship between the tables from the source using the
Query Editor. This helps to reduce the creation of unnecessary new tables.

Relationship View
Relationship view allows you to view your entire dataset as a whole without
bordering you with the details. It gives an overview of your entire data tables,
Also you can view those tables that are already joined together. Power BI
tries to derive any possible relationship existing between the relationships
yourself. You can view your data in the relationship view by simply clicking
on the relationship view button at the left of the Power BI desktop. The
relationship view also helps in maximizing and minimizing tables. This can
be carried out by clicking the maximizing or minimizing button at the right of
the table name tables and creates this relationship automatically. It saves you
time and effort.

How to Create Relationships


Knowing the fields linking two or more tables is very important because it
makes it easier to establish a relationship between them. You should also take
note that on Power BI desktop, tables can only be joined together if they are
in a single field.

How to Create Relationships Manually


You can also identify the tables and field you want to use to establish a
relationship. It is not necessary to be in a relationship view before you create
a relationship between these tables. Creating a relationship can also be carried
out manually through the following steps;
❖ Pick a table that you wish to appear in the relationship.
❖ On the Home ribbon, click on the Manage Relationship button. This
will generate a Manage Relationship dialog box.
❖ On the manage relationship dialog, choose “new.” This will take
you to the Create Relationship dialog box.
❖ Click on invoice table from the list of tables that pops up in the
upper part of the dialog.
❖ Choose an invoice line table at the lower part of the dialog. An
invoice-ID field that will establish a relationship will appear
automatically. Also, if the Power BI already derived the field, it will
establish the relationship, if not or if it chooses the wrong field, you
can pick the correct field. Then click okay, this should return you to
the manage relationship dialog.
❖ When you are done creating the dialog, close the manage
relationship dialog. The relationship will be established.
How to Create a Relationship Automatically
Like it was mentioned earlier in the chapter, Power BI can automatically
guess whether a relationship exists between two tables. You can set the
Power BI desktop to be able to detect these relationships when you are
working. This has a major advantage because it helps reduce the manual
work that goes into creating these relationships yourself, also it greatly
reduces the risk of an error occurring between tables. However, this is
relative. To carry out this process is very simple and straightforward, follow
the steps below;
❖ On the Home ribbon, click on the Manage Relationship button. A
Manage Relationship dialog box will pop up.
❖ On the manage relationship dialog, select AutoDetect, this will
bring out the detected relationships found by Power BI desktop.
❖ Click close to activate the selection. All relationships, both pre-
established relationship and those created through Auto detection
will be listed in the relationship management dialog.
❖ You can now return to the relationship view by selecting close.

How to Delete a Relationship


There are times when you will need to remove a relationship that you no
longer want or a relationship created by mistake. To perform this task, you
simply need to;
❖ Go to the Home ribbon, select the design view. This will display
all the tables in the relationship view.
❖ Click on the relationship to be deleted, this will highlight the two
tables and the arrow connecting them becomes a double link.
❖ You can press delete from your keyboard or right click your
mouse, and select delete, Power BI desktop will bring out a
confirmation dialog, select delete. And you're done.

Managing Relationships
Learning how to manage relationships is crucial, especially if you want to
alter a field that serves as the foundation of a relationship. This is also useful
when you are trying to create or delete several relationships at the same time.
The process of creating and deleting several relationships is similar to those
discussed earlier. Managing a relationship can be described as the key to
creating effective and operative data model. To manage a relationship, you
have to:
❖ Click on the Manage Relationship button on the home ribbon.
A manage relationship dialog box will appear.
❖ Select the relationship you want to modify
❖ Double click on the relationship and select edit, this will bring
out the edit dialog
❖ Modify the relationship.
You also have the option of deactivating relationships. This occurs when you
no longer want a relationship to exist between two tables, and you don’t want
to delete it. Go to the manage relationship dialog, unselect the table in the
active box. The same process applies for reactivating a relationship.
However, the edit relationship dialog has an advanced option that might be
useful on some occasions, they are Cardinality and cross filter direction.
Cardinality helps you to outline the number of column in a table that is
associated with a similar column in the joined table. Cross filter directions
define whether a filter can be used for all the tables in a related group of
tables or in one particular table where the aggregation is carried out.
NB: If a set of joined tables are deleted, reimporting the tables will not bring
back the created relationship unless the joining are also reimported, i.e., once
a set of Joined table is deleted, Power BI Desktop will not remember the
relationship between them, such that any relationship that exists between
them has to be created manually.

Classifying Data
The dashboard is made up of hyperlinks, facts, figure, and geographical data.
A human can invariably recognize hyperlinks, but that is not always the case
for the Power BI. So to make your work easier, you have to classify the
column that house these types of data. For example, if you want a table that
will contain cities as the data source;
❖ Choose a city table in the field list
❖ Select the column containing the city name (this will be
highlighted).
❖ Select the box to the right of the data category button, a
context menu will appear
❖ Select a city from the menu
There are different data category options to pick from when classifying data.
Few of these categories are listed below:
➢ Uncategorized: This encompasses all data that are not involved
in the creation of mapping or hyperlinks.
➢ City: Indicates a city for creating maps
➢ Web URL: Specifies a URL used for hyperlinks
➢ Barcodes: This shows the fields containing the barcodes
There are also several other data category options apart from the once above,
such as country, continent, place, latitude, postal code, image URL, state,
province, longitude, etc. They are all used for creating mappings.
Even though you do not specify the data, the Power BI can still create maps
in the Dashboard, the downside of this is that the result will have a slim
chance of being a success. Nevertheless, if you specify that a column holds a
particular type of data, this can be avoided.

Arranging Data in the Data Model


When you create an arrangement for the data in a table, Power BI allows the
arrangement to be used in all the visualizations across the dashboard.
Creating an arrangement reduces the problem of creating several repetitive
operations, and it saves time. This is achieved by creating a format, which
will be applicable across all visualizations. The data are better understood
when there is a format defining it.

How to Format a Column


❖ Select from the field list the name of the table containing the
column you wish to arrange
❖ Click the inside of the column that you want to format
❖ Select the thousand-separator icon from the modeling ribbon.
The appearance of all the figure in this column will change to a
thousand separator and two decimals.
If you don’t want a format for your figure and you wish to return it to the
plain data, you can click on the general format. Also note that unlike excel,
you can only format a whole column and not just a range of figures. The
selection of several adjacent columns and formatting it in a single operation is
not possible for Power BI desktop. The general principle operated by the
Format once and then application of your formatting. When formatting, you
should note that Date and time Format cannot be applied if the data does not
contain date and time. In other words, the column containing data can only be
formatted with the format option that applies to it.
There are several format options available for use:

Format option Description


General The data are left unformatted
Currency It creates two decimal places and a thousand
separator between figures. It also gives your figure a
monetary symbol
Date and time It gives date and time format
Whole number It gives your figure a thousand separator and then
removes any decimal point
Percentage The percentage symbol is added as a prefix. It also
multiplies your figure by 100.
Scientific text Gives your figure a scientific arrangement
Boolean Your figures are presented in the true/false format
Binary Your data are represented in the 0 and 1 format
Decimal number Gives your figure a thousand separator that has two
decimals

The Power BI desktop also has a wide range of currency format to choose
from if the data you are dealing with involves currency. You just need to
select the one you will be working with. The series of steps below show you
how to do that;
At the right of the currency icon, there is a downward-facing
triangle, click on it, it will bring out a variety of format.
Choose your currency symbol of choice.

Creating Sort- By for Data Model


If you want to search for a dataset in a visualization that is based on the
content of another column, you have to use the sort-by column. For example,
if you have a data table containing month sales. If you sort this by month
name, it will give you an alphabetical arrangement of the month rather than
starting with January, your column will start from April. To avoid this, you
can sort this data based on the month number with January being the first.
❖ Load your sample file
❖ Go to data view, from the field list, choose the date dimension, this
will bring out the date data
❖ Highlight the column by selecting the of the month full column
❖ Select the sort-by column from the modeling ribbon, this will display
the list of column available
❖ Select month number
This way your month name has been sorted by the factor of their month
number, this will display the month name from January and not in
alphabetical order. You can also remove the sort-by column from a data if it
is not needed by selecting the sort-by column button and then picking the
original column name.

How to Hide Fields and Tables from Users


There may be some excess columns in your data that may not be useful in the
creation of your report. The columns may be there because;
The column already exists in hierarchies.
The column contains data that are not needed yet but will serve
future purposes
The column will be used for intermediate calculation
Sort-by column

At a point, the columns might be too much and clutter your work. When this
happens, you will need to hide some of the columns that are not relevant to
your analysis. This helps in the clarification of your work should a new user
want to use the data created by you, because it will eliminate the confusion of
seeing so many columns and guarantee that only the important data are
available.
When you want to hide a table or file, all you need to do is
❖ Select the table you want to conceal
❖ On the popup menu, go to report view and click hide
Once you are done with the process, the table will be hidden from view, and
this achieves your goal of reducing the clutter in your work. You are now left
with essential data needed for your analysis.

Using a Calculated Column to Extend Data Models


Power BI Desktop makes most of the calculations easy to carry out. The first
thing you need to know is that in the Power BI desktop, not all data models
need extensive calculation. Some data are self-explanatory without the need
to brush it up, but at a point, there will be a need for you to apply basic
mathematics to work like calculation of percentage or even comparing
figures.
DAX, which is an acronym for Data Analysis eXpression, is the language
written for calculations in power desktop BI. It is a formula language
program because it is made up of over 300 formulas that can be used alone or
combine to create metrics. This formula is almost similar to those found in
Excel.

Types of Calculation
When your imported data contains all that is needed to create your
visualization, Power BI will make your life much easier. But this is not
always the case, there is still a metric to be calculated or added to tables
leading to the extension of data. A tool like Power BI desktop requires just
the addition of all metrics both calculated and imported from the source to the
dataset and not the output. The probability of an error being in your work is
reduced. Components that will be of important use to your dashboard are also
created when creating DAX metrics, the components include;
➢ Addition of components used in filtering visualizations
➢ Creation of component used in the classification of data, e.g.,
grouping
➢ Creation of derived metrics that will be seen in the
visualization
➢ Creation of new metrics that are based on the existing metrics
➢ Adding specific calculations of your own
➢ Creating order and rank for your Data
➢ Addition of weightings to value
➢ Addition of the new column to a dataset
Creating and adding a new column to a dataset is one of the two ways a
dataset can be extended. Reasons why you might want to extend your current
dataset:
Connecting the data from two already existing column to give a
new column
When carrying out fundamental calculations such as addition and
subtraction in every row of a table for more than one column
When you extract the part of a data in one column to another
column where you need it
When you extract from the date column, the date element to a
new column
When you want to extract a part of data from a column to a new
column

There are still several other reasons for extending a dataset, but the important
thing is that at a point, the need will arise to extend a current dataset. There
are several ways of extending a dataset, and these ways are very similar to
that of Excel. The knowledge of extending dataset is based on that of Excel,
i.e., the function, extension techniques, and the way it is designed all follow
the same pattern as excel. You should also note that when a formula whether
derived or existing in the Power BI, is added from the start to a column, and a
new column is created, this formula also applies to the new column. The data
can only be recalculated when you refresh your source data.

Connecting Column Contents


Sometimes when you import data from a different source, you can have two
columns containing the data you need. The best thing is to merge the columns
and connect them. To achieve this, you have to be able to concatenate the
data into one column. For example, you want to create a column containing
the make and model for flashy cars, and this data are imported from a
different source. You need to create a new column that will take the data
from both columns. The steps below explain how to join the columns
together:
❖ Open the data file in Power desktop BI and activate the data
view
❖ Open the Stock table by clicking on it.
❖ Go to the modeling ribbon and select New Column. The new
column will appear on the right side of the final column.
❖ The text displayed in the formula box will look like this
Column=
❖ After the Equals sign in the formula bar, press the “[” symbol
on your keyboard. This will display all the fields in the table.
❖ In the pop-up list of columns, double click a field, go to the
formula box and add & “ ” &, the formula box will display
[Name of the field you selected] & “ ”&.
❖ Repeat the actions above and click on another field in the list
generated, the formula box will display [Name of the first field]
& “ ”& [Name of the second field]
❖ When you are done, press Enter to activate the instructions.
The two fields selected will be joined together.
❖ Click the column header and type in a new name for your
column.
NB:
As it was said earlier, this process is very similar to that of Excel, so for a
user familiar with Excel, this would be a walkover. Despite the similarities to
Excel, some differences that exist between them, for instance;
Any newly created column is always on the right side of an
existing column and cannot be shifted elsewhere.
Also, when you are creating a function, it must start with the
equality sign.
Another difference is that the column is referenced rather than a
cell, unlike Excel where the cell can be referenced.
The names of columns are always inside square brackets.

In the field list, new columns are always designated with a small Fx icon so
they can be distinguished from other fields.

How to Modify Text


DAX offers you a variety of functions that can help in the modification and
standardization of a text. For example, if you have a data file containing
information on the names and address of your clients and you want to modify
the text in such a way that the new column will contain acronyms of the
names of the clients. To achieve this, you have to carry out the following
process;
❖ Open the data file in Power desktop BI and activate the data view
❖ Open the Stock table by clicking on it.
❖ Go to the modeling ribbon and select New Column. The new
column will appear on the right side of the final column.
❖ The text displayed in the formula box will look like this Column=
❖ Type LEFT after the equality symbol
❖ Click your preferred function once it appears in the popup menu,
click the inside of the column containing your text, then press
comma.
❖ Since the acronym is going to be three characters, enter or press 3,
this will tell the left function that you are isolating the first three
characters for each row, click or press)
❖ Rename the column as Name Abbreviation and press enter.
The Power BI desktop contains some core text functions: LEFT (), RIGHT (),
MID (), UPPER (), LOWER (). The first two extract a specific number of
characters from the left and right column, while the mid extract a specified
number of character from specific positions inside the column. The last two
do not require any parameter but are used in the conversion of data to either
upper case or lower case.

How to Carry out Simple Calculations


It has been established that carrying out basic calculations is one of the ways
by which original data can be extended. Sometimes while doing our data
analysis, there is a need to carry out simple calculations. Calculations are also
needed when we are comparing figures, e.g., if you want to know the
percentage of cars your company sold between the last month and the present
one. In Power BI Desktop, some core math operators are used to carry out
our calculations. You are probably familiar with the math operators listed
below:
➢ Addition operators (+)
➢ Subtraction operators (-)
➢ Division operators (/)
➢ Multiplication operators (*)
Once again, this will be familiar to the Excel users. The arithmetic calculation
in Power BI desktop is the same as that of Excel and much easier because
you don’t have to apply the formula individually to the row, it automatically
applies to all the rows. There are still a few differences, like the appearance
of a table on the right rather than at the bottom in excel. There is no formula
button present like it is in excel. You should note when carrying out all these
operations, your Power Desktop BI must be in data view, for example, you
want to know the direct cost involved in the purchase of a fridge, this
includes the purchase cost and all other cost incurred whether during
transportation.
❖ Click the stock table
❖ On the modeling ribbon, Click New Column
❖ Name the Column
❖ Go to the list of fields and enter the name of the column you
want to reference and select it.
❖ In this order type
_ minus sign
_ left square bracket
❖ Choose the transportation column and enter the right square
column, you are going to have something like this on your screen
❖ cost = [cost price] – [transportation price]
❖ Press enter, a new column containing your solved data will be
created
At this stage, you are already modifying your data’s successfully, another
modification to your data is rounding values, you can either round up or
round down your figures to the nearest value. Power BI contains several
functions for carrying out this task.

Selecting the Right Table for Joined Calculations


In Power BI Desktop, data can only be imported to a column if the column
you are importing from is made up of reference data or sub value of the
current column. You cannot import data from columns that are made up of
reference data, e.g., a table containing countries, color, etc. But data can be
imported from tables like invoice table because they contain original data.
Power BI can be used to perform other operations apart from carrying basic
calculations, such operations include safe division, counting reference
elements, carrying out the statistical function, creating a specific format for
calculation, etc.

How to carry out Logical Functions


Logical functions include IF, NESTED IF, and others, we are moving on
from the easy use of Power BI to a more complex use. The exception
indicator is very important, and they help in comparing facts and figures.
Now let’s go into how you can use the exception indicator IF in your data
analysis.
❖ Create a new column, at the right of the equal symbol, press IF
❖ Enter the right bracket [
❖ Select the column you want to use for comparison in the list
and enter any of the comparison operators
❖ Enter the value you are using for your comparison, put a
comma after this
❖ Enter your text (make sure the text is in double-quotes) and
add the closing parenthesis, it should look like this
❖ = IF ([your selected column] > value, “your text”)
❖ Press enter, this will perform the operation such that any row
that is greater than your value will display your text
❖ You can now rename the column.
The greater than (>) symbol is part of the comparison operators used in
Power BI desktop, other comparison operators include
_ Equality (=)
_ Not equal to (<>)
_ Less than (>)
_ Greater than or equal to (>=)
_ Less than or equal to (<=)
The IF function can carry out about three arguments. When the content of the
column is compared to a fixed value, the outcome, the test is true. The first
two arguments are compulsory for the IF function, while the third argument
is optional, and this is the outcome of if it is false. Most times, the focus is
always on the first two arguments.
How to carry out the Nested IF Function
Often time in data analysis, there is a need to classify your data by a range of
values. To achieve this, you need the nested IF, i.e. one IF inside another IF.
The test will be applied to all the three possible outcomes as compared to the
IF function in which the third argument is optional. For example, if you want
to separate cars in a column into low, medium and high mileage, the steps are
very similar to that of the IF function
❖ Create a new column and to the left of the equal sign, enter
Class and to the right enter IF
❖ Enter the square bracket, this will give you the field list
❖ Select mileage and enter <= 10000 (remember this is your
comparison value), press comma
❖ Type “low,” it must be in double quotes, press comma
❖ Press IF and open a bracket
❖ Select mileage and enter <= 15000, press the comma
❖ Enter the “medium, “high,” these two must always be in
double-quotes, and a comma must be in between the two
❖ Press two right bracket, one for each IF function
❖ Click enter
When performing a task in nested IF, it must follow a logical sequence such
that the Nested IF is acting as a hoop. This way, you get appropriate results
for your tests. When categorizing data, it can sometimes involve the use of
logic where two or more conditions applied to the evaluation of data. When
using the logic function, you can test more columns for a condition. The logic
function is limited to the application of two parameters, i.e., only two logic
operators can be applied at the same time. The logical operators are the AND
(&&), OR (||) and NOT (|).

How to Add Measures to a Data Model


Adding a new column to data always leads to the addition of extra data to
your data model, but the addition of metrics to a data can perform all the
analysis needed for your work, especially when your formula application is
for the whole table and not rows in a column. In general, you need another
formula for that can apply to your table as a whole. This type of formula is
referred to as a simple measure or metrics. This simple metrics can give a
powerful result that can be of great help to your analysis. This simple
measure can perform analysis that cannot be done in a calculated column.
To carry out a simple measure;
❖ Load your Power BI data file
❖ Go to the data view
❖ Choose the table to wish you are adding the measure
❖ Select the new measure button in the modeling ribbon
❖ Add your formula to the formula box
❖ Select the table, to wish the measure will derive analysis
❖ Press enter to confirm your creation.
NB: Unlike the addition of new column in the dataset, there is no new
column created for your data in measures, the only proof that it exists is when
the table is expanded, it can be seen in the field list. Measures in the field list
can be renamed by right-clicking the measure name and selecting Rename
from the pop-up list. One important thing to observe is that a properly applied
measure can be used in any visualization, table, and chart. When applied to
this, it will give the correct result. Measures can also be applied to hierarchies
of data. When measures applied to a visualization gives calculations that are
in decimal places, but you don’t need the data in decimals, apply format
measures. This process is the same with format column in Power Desktop BI.

Carrying Out Basic Aggregations


When learning measures, you will become acquainted with the DAX
functions because they are DAX formulae. Many of the techniques that were
discussed earlier in the creation of column can be applied when creating your
measures. Like it was mentioned earlier, to perform these operations, your
Power Desktop BI must be in the data view.
❖ Click the stock table
❖ On the modeling ribbon, select New Measure
❖ Name the measure
❖ To the right of the equal sign, enter the function Sum, then
press the left parenthesis.
❖ Enter the left bracket to restrict the field list in the current table
❖ Type your field name, this will display all tables with the field
name
❖ Select the field you want for the operation
❖ Press the right parenthesis then click enter. This should display
your formula, You can now arrange this column to suit what you
want
Note that if there are several fields with the same name as that of the field
you are using, you add the table name to your field name so data the power
desktop BI, is sure that it is using the correct field from the correct table.
Table’s names should be in single quotes if it contains spaces and field name
must be confined in a square bracket.
Measures can also be created by combining several DAX functions. These
measures are known as multiple measures. For example, you want to apply a
ratio calculation to a table, it is similar to the steps for basic aggregation of
measures above but in step 8 above, paste or type your formula and then
press enter. Measures can also be applied across all field in a data model.

Data filtering in measures


Sometimes using the filter in the Power BI desktop does not give us the
expected results. Some of the reasons for this can be that we want a specific
filter for a single metric or you are developing a complex formula created for
a specific purpose. This might require you to filter your data in measures.
There are different types of filter
➢ Simple filters – This tool allows you to apply a series of filter to a
measure that you can apply when creating a visual on your
dashboard. It helps you to concentrate on a selected subset of data.
Example of simple filters are
Text filters
Numeric filters

➢ Complex filters – In the real world of data analysis, filtering of data


is not always so simple. For example, when you want to apply
multiple filters to data, calculating the percentage of totals, ALL
EXCEPT function.
Another thing you need to understand is the filter context, which creates the
basis for a dynamic data analysis. There are three key elements of the filter
context. They include
➢ Row context
➢ Query context
➢ Filter context
Data measure is a broad subject. A measure can be used to carry out a lot of
functions. As you familiarize yourself with the use of DAX, there are few tips
that will help you along the way. The first tip is to use a calculated column,
they make your work much easier and do not take up space. That means more
space will be available on your disk and in the memory. By default, all
calculated columns and measures are recalculated by Power BI desktop when
there is a change in data set. The main reasons why recalculation occurs are
When external source data has been filtered.
When you rename a table or column.
When you a new calculation to an existing measure or column.
When an external source of data has been updated.
Conclusion

With what you have read in the chapters of the book, you can see that it really
is a comprehensive beginner guide for learning the basics of Power BI. What
is in this book can help you create data models, reports, and visualizations for
your business or organization. If you read the tutorials and instructions given
in the book thoroughly, you will have an idea of how to operate and use
every feature Power BI boasts of. However, if you want to dig deeper into
what Power BI has to offer, you will need an advanced guide that will take
you farther into the Business Intelligence tool. Advanced guide books will
cover more about the DAX language and how to use it to create and edit data
models on Power BI.
Resources

www.techtarget.com
Adam Aspin (2018), Pro Power BI Desktop: Interactive data analysis and
visualization for the desktop. Apress
Johansen A. (2016), Python: The Ultimate Beginner's Guide! CreateSpace
Independent Publishing Platform.
Alberto Ferrari and Marco Russo (2016), Introducing Microsoft Power BI.
Microsoft Press.
Alberto Ferrari and Marco Russo (2017), Analyzing Data with Microsoft
Power BI and Power Pivot for Excel. Microsoft Press.
Brett Powell (2018), Mastering Microsoft Power BI. Microsoft Press.
Dan Clark (2016), Beginning Power BI with Excel 2013: Self-Service
Business Intelligence Using Power Pivot, Power View, Power Query,
and Power Map. Apress.
Power BI

A Comprehensive Guide of Tips and Tricks to Learn


the Functions of Power BI

DANIEL JONES
Introduction

Business Intelligence Software (BI)


Business intelligence software is capable of turning large volumes of data
into analytical and summary dashboards. They are configurable and capable
of automatically executing the routine of data collection, treatment1, analysis,
and visualization. The term BI began to be used for technology in mid-1958.
From the initial letters of business intelligence, it was tied to software
capabilities of transforming the way much information was consumed in
Hans Peter Luhn's article "A Business Intelligence System." The computer
scientist, who was currently working for IBM, described BI software as
automatic systems designed to propagate information to various sectors of the
economy. His research, among the developments of more than 80 patents,
was initially applied in IBM analysis software.
Nowadays, there are many business intelligence software in the world that
provides the basis for the functionalities that software of this category should
offer, such as data analysis through calculations using different languages,
connection to external sources in various ways and data visualization with
specific graphics and with its own design and configuration. Given all of its
similarities and differences, one of the most relevant in Power BI is the
learning curve.
Perhaps because of the strategy of making some of its resources available in
Excel before its release (Power Pivot and Power Query), but certainly not
only because of that but because of the very way it was logically architected,
the learning of languages and the process of building projects in Power BI is
considered by us one of the fastest and most consistent, enabling results at a
higher speed than many software in the same category.
Research that supports and shows some of the reasons why we, as business
intelligence experts, chose Power BI as the leading BI software is published
by Gartner, a leading global company focused on research and consulting in
several areas of information technology. Every year an extensive report and
graph summarizing it, called the "Magic Quadrant of Analytics and Business
Intelligence Platforms," are published with analysis of BI software, being
analyzed 15 critical aspects involving infrastructure, data management,
analysis and content creation, discovery and sharing, ease of use and return
on investment. Power BI is identified as "Microsoft" and is in the top direct
quadrant, i.e., the market leaders today.
After downloading, open Power BI Desktop and you will observe each
numerical legend commented below.
1. This is the Power BI ribbon containing the Home Page, Display,
Modeling, and Help. It is through this interface that the database
connections, the Query Editor (Power Query), the data modeling
options, the panel layout and others are accessed.
2. The three buttons located on the left vertical are called the
Report, which is the blank panel displayed in the previous image
— data, which displays the data imported into the Query Editor.
And Relationships, which show the tables and allows the
relationship of their key fields.
3. Set of Power BI views. Initially, only the default views will be
shown, but hundreds of others can be added by the Marketplace,
and can also be created with the R language.

Treatment Of Data In Power Query


Power Query Editor is a free add-on created by Microsoft in 2013 for Excel
2010 and 2013 and later also included in Power BI. It is the intuitive tool that
allows you to transform, maintain, manipulate, consolidate, merge, enrich,
and do much more with your data.
It acts like the ETL (Extract, Transform and Load) tool, extracting data from
nearly any source, transforming it and then loading it elsewhere - in this case,
Power BI or Excel. The Power Query Editor interface is separate from Power
BI, and its window opens when you click Edit Queries. The function
language M is its base, coming from the term data mashup, i.e., obtaining and
combining data.
There are over 600 functions in M language that, when combined, provide
comprehensive variation for data collection, processing, and joining. Its main
concept is in the automation of this whole process, being necessary to
connect only once with the data source and treat it so that the next updates
follow the same pattern. Among the categories of functions available, we
have:
Data retrieval Date and time Expressions
Binary Date, time and time zone Lists
Combination Duration Lines
Date Error handling Logic
Replacement Record Numerical
Type Uri Text
Separation Table Weather

The Query Editor Interface


In Power BI, we have a separate window, exclusive for data processing. Look
below at each of the regions commented on to begin familiarizing yourself
with your organization.
Another way to import data into Power BI is by using the Insert Data option,
located next to getting Data. In the window shown below, you can copy data
from other locations and paste it in, as well as declare it (by typing it in the
columns and rows). As this data has no connection to external sources, it will
be static and normally only used for fast data entry purposes that need not be
changed.
When connecting with data in Power Query, lines of code of language M will
be automatically created with the configuration of the connection made. As a
Power BI user, you do not need to know the M language to use Power Query.
Its interface was developed with the end-user in mind and is filled with
buttons that automate transformations, processing, and data creation.

Data Processing
When we need to present a report at a meeting or do some kind of analysis, it
is not uncommon to search for the data in various sources such as
spreadsheets, text files, databases, or reports exported from systems. Then
you have to start processing that data. When done in Excel, for example, this
work is done by copying from here and pasting their several formulas in
Excel to extract a part of the text, convert the data correctly, macro in VBA to
remove unwanted rows, join information from one report with another to this
information
Instead of filtering by a manually typed text, we will choose the filter by a
parameter. Note that we could have created a new parameter in this window,
too, by choosing the last option. Then, just select the parameter in the list
next to it and click OK.
The column will be immediately filtered for the value that is stored in the
Country parameter. Note the formula in Power Query: each [Country] =
Country, i.e., each item in the Country column that matches the text entered
in the Country parameter.
We can modify the current parameter by clicking on it and writing, for
example, "CA" in the Current Value box. Afterward, just press Enter on the
keyboard to save this new text in the parameter.

Data Relationship And Modeling


Before starting the technical studies in DAX, it is important to emphasize the
concept of data modeling. This type of project usually involves databases and
how to delimit them, obtain them, transform them, and model them. Data
modeling simplifies a natural complexity of data and big data and can be
defined as a logical process of relationships between different data,
enhancing its possible links to meet and respond to business needs.
Data in modeling projects are usually presented in tables. Some of them have
detailed operation data, de facto calls (such as sales orders, production orders,
invoices). They are the result of pro- cessation of business and usually store
numbers that can be calculated and summarized into scalar values that will be
distributed in the contexts of visual filters in Power BI.
The fact tables correspond to a specific event and should contain only
columns related to that event. For example, sales data for a company can
have the granularity daily or even temporal (with the time of purchase) and
contain information about the sale, such as quantity, values, method of
payment, product purchased, the customer who bought that product and the
seller who sold it. It is irrelevant to insert, for example, the date of birth of the
customer in this table, since here we are talking about sales facts and not
customers.
Other tables in the data model will have descriptive and unique data, the so-
called dimension tables. Basically, they describe why, when, where, who,
what, and how the events in the tables were recorded. They are able to group
several facts into specific attributes or sub-dimensions, categorizing them and
making it possible to filter through these similar descriptions among several
records in the fact table. In addition to this attribute, they are essential for
making the "connection" between fact tables, since they contain descriptions
that may be common to them, through the relation of the similar record (in
the same row). Size tables can be created from data standardization
techniques, which will be explored in the next chapter.
Note that in the customer registration table above, we have the location of
this customer in the columns Country, Province, and City, and the employee
(seller) responsible for it. These four columns do not need to compose the
sales fact table because we will have more than one record (row) of the same
customer, repeating the information of the four columns several times and
using hardware resources without need. Instead of having all the information
in just one table, two have been created: one fact and another dimension, and
both need to have a primary and foreign key to connect. In this case, the key
(column) that connects the tables is the Client Code.

Calculations And Dax


DAX is an expression language used to perform calculations and queries on
created data models, being very similar to Excel functions, however, with a
particularly different concept. DAX is an acronym for Data Analysis
Expressions. Some experts have given the evolution of the MDX
(Multidimensional Expressions) language.
Before we start exploring the language, let's first get to know the platforms
where she is present. Besides Power BI, it's also in:
Power Pivot is an Excel add-in released in 2010 used for data
mo-delay, measurement creation, and table relationship. Its
functionalities expand the usability of Excel for data analysis,
through new self-service BI concepts introduced.
Microsoft SQL Server Analysis Service, also known as SSAS, is
a tool of SQL Server to analyze data in OLAP cubes, that is, it is
capable of working in several dimensions in databases using
concepts of facts, dimensions, relationships, measures,
hierarchies, among others.

Created by the SSAS team of experts, with the Power Pivot, it is possible to
analyze more than 20 million lines inside Excel, something completely
impossible to execute previously. And all this, without harming performance,
by storing the data and calculations in computer memory. Donald Farmer
(2010), one of the top product managers at the time of Power Pivot
development, considers the technology to be a new type of Analysis Service
designed to put the power of SSAS calculation in the hands of an Excel user.
Due to the popularity of Excel and the robustness of a solution used in SSAS,
the DAX language was quickly spread and accepted after the release of
Power BI. Its functions are classified into ten categories. Between them:
Date and Time
Time Intelligence
Filter
Information
Logic
Mathematics and Trigonometry
Hierarchy
Statistics
Text
Other

The tables are stored using xVelocity in-memory technology, also called
VertiPaq, which compresses the data in the best possible compression
according to its variation, redundancy, classification, and type. Some
important features should be observed in Power BI:
The tables must have different names in the same data model.
Columns within the same table must also have different names.
Columns in different tables may have the same names since their
address will be the table name + the column name.
Unlike the language M, in DAX, all objects are case-insensitive;
that is, DATE and Date are considered equal names.

Rank Products = RANKX(ALLSELECTED(dCategoriaProduct);


[Sum Sales])
The previous expression classified the categories from 1 to 9, according to
their ranking based on sales. We use the ALLSELECTED function to
consider the ex-suit filter next to the table.
Now let's use this ranking for the accumulated sum of each category. With
the help of the CALCULATE function, we will calculate the sales according
to the return table of the TOPN function.
Sum Products = CALCULATE([Sum Sales];
TOPN([Rank Products]; ALL(dCategoryProduct);[Sum Sales];
DESC
)
)

Visualization
In the previous chapters, we have taken the necessary steps to reach this
moment: the visualization and the application of the data. We go through the
data collection and processing, we load and model it, then we create the
necessary calculations, all this process to show coherent, consistent, clean
data that answer business questions. Power BI offers dozens of visuals
between columns, bars, and stacked, horizontal and vertical, line, area, and
combination, ribbon, cascade, and scatter graphics.
Pizza charts, thread, and treemap. Real geographical maps, choleretic and
area maps. Funnel, indicators, cards, tables, matrices and segmenters.
Not only those, but there is also a Marketplace with hundreds of visuals
created by companies and experts and validated by Microsoft. Most are free,
and some have subscription services, like one of the most famous: ArcGIS
Maps. And you also have your own environment to create visuals and
program yourself in the R language.
Marketplace visuals are installed per Power BI file. This means that when
you open a new file, only the default looks will be displayed, and if you
constantly use a custom look, you must add it again (or use Power BI
template files).

Principles For Creating Visuals And Reports


The choice of the correct look, the fields to be displayed on it, the colors, and
their elements are determining factors for a data visualization project. Its
main objective should be to provide the fastest and simplest reading that
meets the informational needs of its customers. Some principles can be used
as a guide for building your reports.

Showing Compositions And Flows


When we analyze the total of two figures, for example, sales in 2016 and
2017, we do not immediately know the influences that these figures have
suffered to be positive or negative in relation to the previous one, but there
are ideal visuals to avoid this composition.
The first of these is the cascade graph, which aims to show the variation
between two or more points. For example, if a cascade graph shows the year
2016 and 2017 and the variation in performance over the target. We can
interpret that X and Y had great positive participation, but A and B
compensated negatively, resulting in 117 thousand in 2016 to 118 thousand
in 2017. Looking at these two figures in isolation, we can think that there
were only 1,000 sales, but in fact, there was a large internal variation in the
country segment.
The waterfall graph has an interesting feature that allows you to use it for
many categories. For example, if this company operated in more than 40
countries, we would have 40 columns on the chart, and this would certainly
hinder its reading and interpretation.
To get around this problem, you can format the look (by clicking on the "ink
roller" symbol) and choose the Split formatting to show only one or more
values of those with higher representativity and still add the rest in a category
called Other. In the following example, only two of the most representative
values are shown.

After performing the previous procedure, to run an automatic filter on the


tooltip according to the axis of the visual (where this tooltip will be
configured), it is important to select "Keep all filters" in the panel below
Filters, called Tooltip (it will only be displayed after defining the page as
Tooltip).
After this procedure, go to the main report page and select the look where
you want this tooltip to appear. For example, a column graph containing sales
values by country was selected. In the Format, the Look panel, under Tool
Tip, enable the report page and select the page name with the tooltip just
below. In this example, it is called "Details." When performing this
procedure, by positioning the mouse over Y, the mini-report will appear
with the data filtered for Y.
With the panel displayed, we will navigate to the page created with the order
details and click Add. The current stage of the page will be "saved,"
considering current filters and displays. The name of the indicator created
will be "Requests."
With the indicator created, after clicking the "View Orders" button, in the
Action configuration, we must inform that the type of it will be the Indicator
and that the indicator will be the "Orders."

Classifying By Columns
The values in the axis of the visuals will be classified according to the
standard order of the column. If it is formatted as text, it will be rated from A-
Z, but if it is numeric or date, from the smallest to the largest. It is very
common to have to change the classification from one text column to another
than the alphabetical one. The nation of your classification can be modified in
modeling.

Power BI
Power BI Service is a cloud platform used to publish and share reports and
dashboards, enabling you to access them over the Internet, configure your
automatic update, manage shared workspaces, measure the usability of
published reports and dashboards, and many other features.
Your access is via app.powerbi.com, and a user and password will be
required to access your workspace. Its interface is completely different from
Power BI Desktop because they are not the same version. In fact, they
complement each other with several different usabilities. However, they also
have similarities, and for example, you can create reports, connect to
(limited) databases, and create visuals. Despite these similarities, it is not
possible to perform data processing in Power Query or create measurements
with DAX.
Its interface can be divided as follows:
1. Favorites: reports and panels can be bookmarked to be stored in
this section.
2. Recent: displays recently used reports and panels.
3. Applications: shows applications (workspaces transformed into
applications) created or obtained.
4. Shared with me: displays the reports and panels that are not
owned by this user, but that was shared with him.
5. Workspaces: are containers that store data sets, data folders,
reports, and panels.
6. The selected workspace shows the currently selected workspace
and its components.
7. Notifications: displays account notifications, dataset update,
configured alerts, etc.

Reports and shared dashboards can be viewed in the application to cellular


Power BI normally, without limitations or need for special sharing.
To view or remove the access given to users, in the same panel, click on
Access and then remove the access by clicking on the options of each user
who has access. This setting can also be performed by clicking on the options
in this report's dataset and choosing the Manage Permissions option.

Sharepoint
A third way accessible only for Pro accounts is to insert reports into
SharePoint1. Its use is recommended for those who already use SharePoint in
the organizational environment or will start using it for Power BI reports. To
start it, the first step is to get the report link to SharePoint (different from the
web publishing link), in the File menu 'Insert in SharePoint Online.'

Power Bi For Mobile


Power BI has applications for Android, Windows, and iOS smartphones, and
you can connect to your Power BI account (free or Pro) and consume the
created or shared relations (Pro accounts only). They can be found in the
official store of each platform (https://powerbi.microsoft.com/mobile/). With
them, you can have quick access to reports, receive comparison notifications,
update reports, share annotations with others, and typically use filters and
pages.
Annotations can be made on the graphs, and you can create callsigns with
symbols, use the free brush, and add annotations with text.

Optimizing Reports For The Application


As explained in the chapter on Power BI Service, there are two types of data
collection: reports and panels. In the Power BI application, it is possible to
visualize both, but the panel tends to a better visualization because it
automatically organizes the visuals on top of each other, while the report
displays exactly the layout developed in Power BI Desktop (horizontal). And
while fully functional, its visibility can get too small for smaller screens.

Power BI And Excel


One of the most used software in the world is Excel. And the reason for this
is quite clear: its resources and flexibility are extraordinary. Many analyses
are performed in Excel, and if structured correctly, we encourage their use for
the purposes that the software was created. We see a real movement of many
analyses that were previously performed in Excel now being transferred to
Power BI. We evaluate that this change occurs naturally since the language of
the two software is similar, and their integration is and has been increasingly
consolidated.
Power BI is a business intelligence software with all the layers that the BI
process needs. Precisely because of its objective of usability, it has its
business intelligence stages very well defined and with the flexibility in the
necessary measure. Excel, on the other hand, is a spreadsheet. Its flexibility is
one of the highest, depending a lot on its user. Both can be used to analyze
data, but there are differences in productivity, storage, availability,
management, and sharing.
Chapter One:
Review Of Getting Started
With Microsoft Power BI

One of the great virtues of Power BI is the learning curve, which allows you
to transform data into information almost immediately and perform very
complex analyzes if you learn to master the tool.
This chapter is aimed at people who are faced for the first time with the blank
Power BI canvas and overwhelmed by its many options that need a guide to
get started.
The text is divided into four sections with practical guidance, and at the end
of its reading, you will know how to connect Power BI with the data sources,
transform the data and create a display panel.
On the Internet, there is more content on data visualization with Power BI
than on the transformation and cleaning of these. For this reason, I have
found it useful that the data transformation section is the most extensive and
detailed.

Basic Theoretical Concepts

ETL
ETL is the acronym for extraction, transformation, and load (in English:
extraction, transformation, and load), which is the process that allows us to
obtain data from multiple sources to transform and clean them and then
upload them to Power BI.
The ETL process is necessary so that the data we use to mount our graphics
are in the right conditions (suitable formats, without errors or blank fields,
etc.).

Power Bi Elements
Power Query: is the ETL tool integrated into Power BI.
Power BI Desktop: the desktop version of Power BI to mount the
reports.
Power BI in the Cloud: view, share, and modify models created
in Power BI Desktop.

Power Bi Languages
Language M: it is the programming language of Power Query, but do not
worry, the editor that includes the program allows you to do almost
everything without knowing how to program with this code.
DAX language: it is the equivalent to Excel formulas within Power BI, but
much more powerful. Even if you do not master it, it is advisable to learn the
use of formulas that are useful for improving your reports.

Measurements
In a very simplified way, we can say that the measurements are the
calculations made using the “formulas” of Power BI (DAX language), with
the advantage that once created a measure, we can use it as many times as we
want in our report.
We will see it more clearly in the example.

Explanation Of The Practical Example Of Power Bi


During the following sections, we will make a visualization panel using data
on the World population of the World Bank.
The objective is that you learn to create a display panel from scratch while
following the steps in the practical example.
At the end of the example, you will know how to do the following:
Connect data with Power BI.

From Excel files.


From a web page.

Transform and clean data with Power Query.


Rows and table headers.
Attach tables
Rename tables and columns.
Enable and disable table loading.
Remove columns
Cancel column dynamization.
Modify column formats.
Merge tables
Filter rows
Upload the transformed data to Power BI Desktop.

Create a panel with graphics.

Data Connection
There are multiple options for connecting to cloud services, databases, web
pages, etc. In this case, we will connect to an Excel file and a web page.

Connection With Excel File


To start, we will use a file that you can download the file from the World
Bank website.
Now that we have the Excel file on the computer, let's connect it with Power
BI. To do this, press the «Get data» button found in the «Start» tab, as shown
in the following image.
In the window that opens, you must select the Excel option and click on the
"Connect" button, as we show you below.
A new window will appear to search and select the file, and you will have to
search for it in the path where you have downloaded it. Once located, select it
and press the open button.
Next, you must indicate to Power BI the Excel tabs that you want to connect.
In this case, select the three available tabs and click on “Load.”
During the upload process, the progress will appear on a screen.
You will be able to verify that the upload was successful because the three
tables appear in the Power BI field selector.
Connection To A Web Page
Now that you have the data from the Excel file loaded in Power BI, let's get
what we are missing from a web page. To do this, click on the “Get data”
button on the home tab again, look for the “Web” option in the window that
opens and click on “Connect.”
In the new window that opens, enter the following Wikipedia address:
https://en.wikipedia.org/wiki/ISO_3166-1
Later I will explain why we connect to this page, and the interesting thing so
far is that you see how easy it is to import from different data sources.
After pasting the web address and clicking "Accept," a new window will
open to select the data we want to load in Power BI.
The web page is made up of multiple tables, and the one that interests us in
this exercise is what is called “Officially assigned codes [edit].”
When selected, a preview of the table will appear on the screen, and you can
press the “Load” button.
At this point, you already have the four tables loaded in Power BI, and you
are ready to perform the data transformation.

Data Transformation in Power BI


To start the transformation of the data, click on the "Edit queries" button on
the home tab, as shown in the following image.
A new window will open with the Power BI query editor, which you will use
to clean and transform the data.

Rows And Headings


First, select the "Active population" table and look at the rows.
Row 1 contains the date the Excel file was updated and is not
useful for our exercise.
Row 2 contains empty cells ("null") and is not useful for exercise
either.
Row 3 contains the table headings (country code, indicator name,
etc.), and you will need it.
From row 4, there is the data, and you will also need it.

To eliminate unnecessary rows, you must press the “Remove rows” button on
the “Start” tab (remember that we are working in the Power Query window)
and choose the option “Remove upper rows.”
In the window that will open, we must indicate that we want to delete the top
2 rows (remember that we want to delete rows 1 and 2 that did not contain
data of interest).
You will be able to observe how the first two rows of the table have
disappeared and that in the right panel, the action “Upper rows removed” has
been added.
If you make a mistake by doing something, you can delete it by clicking on
the X or edit it if you click on the gearwheel.
The next step is to correctly assign the headings, which are now in row 1, as
can be seen in the following image.

To do this, click on the “Use the first row as header” button on the “Start”
tab.
With this step, you have already achieved that the table has the correct
headings and is ready for the next transformation.
Reproduce these same steps in the “World Population” and “Urban
Population” tables before continuing with the practice.
A reminder of the steps to reproduce:
Delete the first two rows.
Use the first row as a header.

Attach Tables
The next step is to join the three tables to which you have eliminated the
unnecessary rows. All three tables must have the same number of columns,
and their names must match.
Click on the "Append queries" button on the "Start" tab and select the option
"Attach queries to create a new one."
In the pop-up window, choose the "Three or more tables" option and select
the "Active population," "World population," and "Urban population" tables
by pressing the "Add" button.
When the three selected tables are in the “Tables to append” area, click on
“OK.”
This action creates a new table that contains all the rows of the previous
tables.
Recommendation:
This function is very useful if you have an Excel file for each month of the
year because it allows you to put them all together in the same table.

Renaming Tables And Columns


To rename a table or column, double click on it. By default, the new table
that we have created is called “Append1,” and we will modify it by a name
that is easier to interpret and thus facilitates its identification when there are
many tables.
For this example, we will rename it as “World Bank Data.”

Enable And Disable Table Loading


Sometimes we will not need to load all our tables to the Power BI graphics
creation panel, and it is advisable to disable the loading of those that we will
not use to mount graphics. For this reason, we are going to disable the
“Active population,” “World population” and “Urban population” tables,
since we already have all their data in “World Bank Data.”
Press the right button on each of the tables to access the menu and uncheck
the option "Enable load."
A pop-up window will warn us of the risk of removing the tables from the
report, but you should not worry, because we will not use that data to
assemble the graphics, so you can click on “Continue.”

Delete Columns
Our table “World Bank Data contains the column “Indicator Code” that we
will not use and, therefore, we can eliminate.
Select the column and click on the "Remove" option from the pop-up menu.
Transform Columns Into Rows
The correct way to work on the Power BI model is that the same data can
only appear in one column. This rule is not met in our table, as the number of
inhabitants appears in column 1960, 1961, 1962, etc.
To transform the columns into one with the year and another with the number
of inhabitants you must select all the columns of dates (from 1960 to 2018) as
you would in Excel, holding down the “Control” key and selecting them one
by one or selecting column 1960 and holding down the “Shift” key when
clicking on column 2018.
Once all the columns have been selected, you must click on the “Cancel
dynamization of the columns” option of the button with the same name found
on the “Transform” tab.
Our table will transform the columns into rows automatically and will have
one column with the years and another with the number of inhabitants
corresponding to that year.
The next step will be to rename the columns, "Attribute" as "Year" and
"Value" as "No. of inhabitants" by double-clicking on the column name.

Modify Column Format


You will see that the year column is represented with the letters "ABC" and
the number of inhabitants with the number "1.2". This is because a text
format has been assigned by default to the first and numeric to the second.
The format can be modified by clicking on the “ABC” or “1.2” symbol,
although in this example, we will not modify them.

Merge Tables (Hypervitamine Search)


If you use the Excel VLOOKUP formula, be prepared to discover a Power
Query function that will be very useful.
In the table "World Bank Data" is the "Country Code" column that contains
the country's code, but not their name. To add the name of the country, we
will use the table “Officially assigned codes [edit]” that we have connected
from Wikipedia.
First, select the “World Bank Data” table and click on the “Merge queries”
option from the “Start” menu.
Then follow these steps:
1. Select the "Country Code" column from the "World Bank Data"
table.
2. Choose the “Officially assigned codes [edit] table from the drop-
down menu.
3. Choose the “Alpha-3 code” column of this last table, as it
corresponds to the country codes.
4. Press the "Accept" button.

After performing these actions, a new column will appear in the table with
the World Bank data, and you will have to press the button with the two
arrows.
In the pop-up menu, only the option "Common name" should be checked and
unchecked "Use the original column name as a prefix."
Once this is done, press the "Accept" button, and you will have the name of
the country in the table.

Filter Rows
Looking closely at the table, you will see that some rows do not have the
name of the country. For example, rows with code "ARB" have a country
name "null."
This is because “ARB” is not the code of a country and does not appear in the
Wikipedia table. The Excel files with the World Bank data contain subtotals,
and “ARB” is the sum of all the countries that belong to the Arab World.
As we want to work with country data, we will filter all the rows that are not.
Stop it by pressing the filter button in the "Common Name" column and
unchecking the "(null)" value.
This will hide rows that do not correspond to countries and will not appear on
the Power BI Desktop graphics display screen.

Apply The Transformations Performed In Power Query


At this point, we have completed the transformation of the data, and you can
move on to the next stage by clicking on the "Close and apply" button on the
"Start" tab.

Creating A Report With Graphics


Main Sections Of Power Bi
Power BI contains three main sections:
The visualization of the model in which we can establish, among
other things, relationships between tables.
The visualization of the data that we have transformed and
loaded from Power Query.
And finally, the reporting area where we will paint the graphics,
and that is now empty.

The options offered are very wide, and deepening them requires a lot of time,
so in this section, we will focus on the creation of graphs from the data we
have prepared previously.
Calculations With Dax (Use Calculate)
During the transformation process, we have created a column with country
data on the world population, the active population, and the urban population.
If we want to calculate the total urban population, we cannot use a formula
that adds up the entire column “Number of inhabitants,” since we would also
be adding the active population and the total population. To solve this
situation, there is the CALCULATE function, which is one of the most useful
when learning Power BI is explained in this example.
To start, right-click on the “World Bank Data” table found in the “Fields”
section of Power BI Desktop and select “New measure” from the pop-up
menu.
You will notice that the formula bar has been enabled to write the DAX
function.
We will write a function that will add the number of inhabitants if the
“Indicator Name” column is equal to the “Urban population.” This will not
add the active population or the total population.
Type the following expression in the formula bar:
Urban population = CALCULATE (SUM ('World Bank Data'
[Number of inhabitants]); 'World Bank Data' [Indicator Name] =
»Urban population»)
This is what our function will do:
CALCULATE warns the system that we are going to perform a calculation
by applying a filter (we just want to add the urban population).
SUM ('World Bank Data' [Number of inhabitants]) will add the values of the
column “Number of inhabitants” in the “World Bank Data” table.
The 'World Bank Data' filter [Indicator Name] = »Urban population» forces
only the values of the urban population to be added, ignoring the rest.
When closing the last parenthesis, we finish the calculation.
You can repeat this same procedure to calculate the total population and the
active population. Here you can see the expressions you should write:
Active population = CALCULATE (SUM ('World Bank Data'
[Number of inhabitants]); 'World Bank Data' [Indicator Name] =
»Active population, total»)
Total population = CALCULATE (SUM ('World Bank Data'
[Number of inhabitants]); 'World Bank Data' [Indicator Name] =
»Population, total»)
At this point, you will have in the Power BI field selector the three measures
that we have created marked with the icon of a calculator.
Graphics
Now that we have the basic calculations, we are going to create the first
graphics in Power BI Desktop.
Click the left mouse button on the line chart icon, and an empty graphic will
appear inside the Power BI canvas.
Before continuing, be sure to select the graphic you just created and make it
wider to see it better.
The next step is to take the measurements we have created to the chart. Stop
it, and we must have selected the graph and click on the field of selection of
the measures we want to use and the year.
They will have a graphic similar to this on the screen, and you can enlarge it
by clicking on the “Focus mode” button.
The dates may appear untidy because the graph has been ordered according
to the number of inhabitants and not by year.
To order it correctly, click on the “More options” button on the graph and
choose the options sort by year and ascending order.

Dynamic Filters
The next step is to add a filter that allows you to select countries. Click on an
empty place on the canvas to make sure the graphic is not selected and then
choose the “Data segmentation” display.
The empty display will appear on the canvas, and you must select the
“Common Name” field from the “World Bank Data” table to transform it into
a country filter.
Click on different countries to see how the graph behaves. You can also
select several countries at once if you press and hold the keyboard control
key.

Add Visualizations From The Power Bi Marketplace


As the list of countries is very long, we are going to add an object that helps
us find a particular country.
Click on the button with the three points in the visualization box and select
the option “Import from Marketplace.”
Choose the "Filters" option from the pop-up window and add the "Text
Filter" object.
We already have the object in our Power BI Desktop and can use it to create a
country search engine.
Place the visual object on the canvas and add the "Common name" field as
you have done before.
Now you have a search engine where you can write directly the name of the
country you want to analyze.
With what has been learned so far, you can build a graph with similar
characteristics to the one that appears on the World Bank website.

Add Measurements To A Chart


We will enrich our panel with information that provides value for the
analysis. For this, we will create a new measure.
% Active population = DIVIDE ([Active population]; [Total
population])
Next, bring the chart of grouped columns and lines to the canvas.
Select the graph and add the year in the "Shared axis," in "Column values"
the total population and in "Line values" the% of the active population.
With this selection, you will obtain a graph in which you will be able to
observe, among other things, how the world population has been growing
continuously and how the crisis of 2008 caused a decrease in the% of the
active population.

Creating A Page In The Report


Create a new page to place the maps by clicking on the button with the +
symbol at the bottom of Power BI.
To create a map that shows us the population by countries, we will inform the
Power BI of the field that contains the names of the countries.
First, double-click on the "Common Name" field and change the name to
"Country" to make more sense.

Transform The Data Type


Select the country field and choose the "Country or region" option from the
drop-down menu that appears when you click on the "Data category" button
of the "Modeling" tab, as shown in the following image.

MAPS
Now take the visual object "Choropletic map Map" to the canvas.
Then place the country in the field "Location" and% of the urban population
in the field "Information on tools."
Then create a filter with the year field as you did before with the name of the
countries.
You should have a structure similar to the one in the following image.

Finally, we will format the map, selecting it and clicking on the roll of the
visualizations section (remember to select the map, or you will be formatting
the filter of years).
Left-click on the symbol with three vertical dots in the “Data colors” menu
and click on the “Conditional formatting” button.
In the pop-up window, configure the following fields:
Format by: Color scale.
This way we will make the colors of the countries vary according to the
number of inhabitants.
Depending on the field:% Urban population
Minimum: Lowest value à white

The country with the least urban population will appear on the map in white.
Default format: Specific color to black.

Thus we will see in black the countries that do not have data in our Power BI
table, and we will be able to detect possible errors.
Maximum: Highest value to red

The country with the most urban population will appear in red.
You can now click on “Accept.”
To test the graph, select the year 2017, and you will see that there is little
color contrast that facilitates the interpretation of the map.
To achieve greater visual contrast, press the conditional format found in
“Data colors” again.
In the format window, check the box "Divergent," and the color scale will be
modified by adding the yellow color.
Pressing on the control key and moving the mouse wheel, you can zoom in
the map to enlarge specific areas.
Power BI is a very powerful tool with countless options, and this book
intends to be a guide so you can get started in application management.
The consultancy Gartner carries out a classification of the main analytics and
business intelligence providers every year, and Microsoft has been leading it
for several years, so you can rest assured that all the effort you dedicate to
learning to manage Microsoft Power BI will be well spent.
Chapter Two:
Introduction to Power Pivot

Power Pivot is a technology that allows complex information to be processed


and analyzed very efficiently and quickly. Its main feature and the one that
gives it enormous speed is that it is an "In-Memory" technology, that is to
say, it has all the data in memory with high compression, to decrease the
space it takes up and increase the speed of analysis. These data models are
based on tables and relationships.
It has three "flavors" or presentations:
1. Power Pivot for Excel: is an add-in for Excel that contains all
this technology and allows you to manage these models from
new menus integrated into Excel itself. Its use is oriented to the
Personal BI.
2. Power Pivot for SharePoint: Allows you to manage Power
Pivot worksheets on a SharePoint server. Both the data
processing and the display are managed on this server. Its use is
oriented to the departmental BI.
3. SQL Server Analysis Services Tabular Model (SSAS): these
are "In-Memory" databases managed by Analysis Services
through its analytical engine, a service-oriented to servers and
their administration by qualified IT personnel. Its objective is to
have centralized corporate information and to serve all users in
the company simultaneously with very fast response times.
Supports larger storage volumes, management is optimized for
simultaneous use by many users. Finally, it should be noted that
it allows for the automation and scheduling of the loading of
information from the data sources to the model. Its use is
oriented to Corporate BI.

At this point, we will focus on the Excel add-in, which allows business users
to create their own analytical models and populate them with information
from a variety of data sources, independent of the IT department. In addition,
a model created in Excel can be shared in SharePoint or imported from SSAS
(with the help of qualified from the IT department), reusing everything that
the business user has developed in Excel.
Power Pivot for Excel is an add-in for Excel that allows us to integrate and
structure in tables the information from various data sources, and this
information is stored in the files ". xlsx" with a high degree of compression,
and at the moment they are opened they are read and loaded completely into
memory, which allows for a speed of calculation not seen until now in Excel,
as well as the possibility of storing large quantities of rows, many millions of
rows, thus overcoming the limitations (approximately 1 million rows) and
slow speeds that we have when there are a large number of rows in traditional
Excel sheets.
To give you an idea of the high compression that can be achieved, let's take
an example with real data, made by SolidQ. We have a model with four
boards:
Clients 18,848 rows 29
columns
Date 2,191 rows 19
columns
Products 606 rows 36
columns
Sales 6,341,790 26
rows columns
It occupies a size of only 26.3 MB. Note that the compression may be lower,
as it depends on the redundancy of values in each column, and in this case,
the redundancy is quite high.
In addition, it includes a powerful formula language called DAX (Data
Analysis Expressions) that greatly increases the analytical calculation
capacity and response speed.
Whether you are a mid-level Excel user and are getting your company data
by exporting reports and queries from your applications and/or by copy and
paste operations. And if you are an advanced user who discovers and
struggles every day with the VBA language to try to obtain analytical
solutions with some dynamism and without having to do tedious and
repetitive manual tasks to obtain updated data from your company and
transform it for analysis, Power Pivot is the tool you need to make your life
easier, spending less time on tedious tasks and more time analyzing your
information and making better decisions.
In short, more storage, easier access to external data, greatly increased
calculation speed and a new formula language with much more computing
power. Power Pivot is the new end-user-oriented information storage and
analysis tool that is fully integrated with Excel. As you can see in the
following image, its interface is a new menu in the Excel ribbon.

Power Pivot Ribbon in Excel


The Power Pivot add-in is not enabled by default in Excel 2013. To enable it,
you must follow a series of steps that are summarized in the following image:
Steps to Enable Power Pivot in Excel
One of the main elements is the "Manage" option that gives access to a new
window with all the necessary elements for its management. In the following
image, you can see this window.
Power Pivot Management Window
Note at the bottom left, where it indicates that there are 6,341,790 records in
that table, something impossible in a traditional Excel sheet.
All the information, both from Power Pivot and traditional Excel, is stored in
the same file ". xlsx". Note that Excel's autosave feature does not apply to the
Power Pivot window, so you will need to save changes manually to avoid
losing them in the event of an unexpected shutdown.
Finally, we will place Power Pivot along with the rest of Power BI for Excel
components in the following image, to continue working on the
understanding from a global perspective. Note that we have circled its
location in red:

Excel Power BI Components - Power Pivot


Power Pivot is the core of the Power BI for Excel components, without it, the
existence of the rest of the components does not make sense since all the
other tools need it as a starting point or destination:
1. Power Query: reads data from sources, transforms it and stores
it in
2. Power Pivot.
3. Power View: is a tool to visualize information stored in
4. Power Pivot and on servers with SQL Server Analysis Services
5. Power Map: is a tool to visualize and analyze geolocated
information in different types of maps, from information stored
in Power Pivot and servers with SQL Server Analysis Services.

Create Analysis Models with Power Pivot


From this moment on, already focused on Power Pivot for Excel, we are
going to get to know all the details necessary for the creation of analytical
models.
Power Pivot has the peculiarity, with respect to other similar tools on the
market, that we do not create as such and from scratch a structure of tables
and columns, with their data types and characteristics from a specific editor
for this purpose. For the reader to understand what kind of tools I am
referring to, I am going to put a Microsoft Access screen where the
characteristics of each table in the database, and the columns that make it up,
are defined visually:

Table design in Microsoft Access


At Power Pivot, we have two ways of generating these storage structures:
Using Power Query, a tool that we have studied previously,
which allows us to extract data from the sources, apply a series
of transformations to them and save them at the destination.
Well, when we indicate that the process uses Power Pivot as a
destination, what happens is that a storage structure is created, as
we have defined it in Power Query, and once created, it imports
the data selected in that process.
Using the options for "Get external data," you provide
Power Pivot (we haven't studied them yet, they will be studied later)
Once these structures have been created, we can access them by opening the
Power Pivot administration window. To do this, we click on the "Manage"
option, which is located on the left side of the "POWERPIVOT" menu, from
which we have access to all the options it provides.

Power Pivot Management Window. Data view


We will now study each of these "ribbon" menus and each of the groups of
options and choices that make up the ribbon.

Home Menu

Ribbon, 'Home' menu


Group of options 'Clipboard': these are options related to obtaining data from
the clipboard. It will be studied later.
Group of options 'Get External Data': these are options related to obtaining
data from various sources from the Power Pivot itself, without using Power
Query. It will be studied later.
Group of options 'Refresh': these are options related to the maintenance of
data of the model, it allows to update the data of the whole model (option
Refresh All) or only of the selected table (option Refresh). Completely
removes the content and re-extracts it from the source, transforms it, and
loads it: no incremental loading, only full loads.
Group of options 'PivotTable': allows us to create dynamic tables and/or
dynamic graphics connected to the model with a single click, opening the
Excel window again and showing us the tables and graphics ready to make
queries about the model. It is simply an option that improves usability and
avoids us having to do all of the above step by step.
Group of options 'Formatting': these are options relating to the consultation
of the origin of data.
Data Type: allows to change the data type that has been assigned
to each column. It is very important to apply the right data types,
it is good practice, and it helps to optimize storage and response
times. The types of data available are:
Text
Date
Decimal Number
Whole Number
Currency
TRUE/FALSE

Format: allows you to choose from a series of formats that will


depend on the type of data in that column. For numerical data
types, you can choose from the following formats:

General
Decimal Number
Whole Number
Currency
TRUE/FALSE

For data types Date, Date/Time, and Time you can choose from a variety of
formats, more or less extensive, to represent that date/time.
Currency symbol assignment. This and the following icons
behave in the same way as in traditional Excel sheets.
Display as a percentage, note that it multiplies the value stored in
Power Pivot by 100.
Format: format with a thousand separator.

The number of decimals is increased or decreased.

Let's go a little deeper into the types of data. Each column is assigned a data
type, which by default is automatically assigned according to the data type of
each column of the origin, but you should review it manually, to improve it if
possible, and reassign a more appropriate data type if you consider it
appropriate and, of course, if it is compatible and allows you to store the
values obtained from the origin. By this, I mean that, for example, if you
have a column with customer names, you can't turn it into a type of numerical
data. These data type changes have to be done manually in Power Pivot once
the table and its columns have been created after the first import of the data
(which is when the data types are assigned).
You should take into account the following aspects in terms of data types and
format:
The type of data affects storage, while the format only affects the
display. You cannot assign data types that do not allow you to
store the values that the data in that column has.
Do not assign inconsistent formats for the chosen data type,
although in some cases, this is allowed. It doesn't make sense to
have a type of data
Integer' and in format to assign two decimals (although always
worth ".00" is confusing).
The format 'Currency' does not make conversions: 142.84?

Group of options 'Sort and Filter': these are options related to sorting and
filtering of the data.
A-Z: Sort in ascending order by the selected column.
Z-A: Sort down the column by choosing
Clear Sort: removes any sorting that we have enabled with the
previous options.
Clear All Filters: eliminates the established filters, leaving all
the rows of the table visible.

Sort by Column: allows sorting the data of a column by the


values of another different column. Although at first sight, it may
seem very strange, it is actually very useful, let's see an example
of use: we have a column with the name of the month, in
ascending order, so the first month would be April and the
second would be August (alphabetical order of the names of the
months), but we need the chronological order and the first month
to be January, the second February, and so on. How do we solve
it? So we should have a column 'MonthName' with the names of
the months and another 'Month' with the numbers of the months
from 1 to 12; then we use this option and tell you to sort the
'MonthName' column by the values in the 'Month' column.Find'
option: allows you to search the contents of the model tables. It is
equivalent to that option in Excel.

Group of options 'Calculations': these are options that allow us


to create calculated fields quickly and KPIs. We will study them
in part, dedicated to DAX.
Group of options 'View': gives access to the different display
options:
Data View shows the data view (see figure above showing
Power Pivot Management Window).
Diagram View: shows the diagram view (you can see it in the
following image). It shows the tables and relations in the form of
a diagram. This is also where the Hierarchies are managed
through the icon at the top left of each table (remember that it
only appears when this table is selected).
Show Hidden: shows or hides the columns we have marked as
"hidden in client tools." These columns are those we need
internally, usually for calculations, and establishing relationships,
but they do not contribute anything to the user during the
analysis, but on the contrary, introduce "noise" as they are
columns that he does not know and will not use.
Calculation Area: shows or hides the "calculation area," which
is that grid at the bottom where we define the fields calculated by
DAX (we will study this area later).

Creation of Hierarchies
To create a hierarchy you must be in the diagram view and click on the
specific table you want to create the hierarchy on, and you will see that it is
marked in a different color and that two icons appear at the top, to the right of
the table name, you must click on the icon, then you must assign a name to
this hierarchy and drag columns from the same table to create the different
levels we want it to have. Note that a hierarchy cannot use columns that
belong to another table than the one you created.

Menu 'Design'
Group of options 'Columns': they are options related to the treatment of the
columns of a table in the Power Pivot Management window.
Add: allows you to add calculated columns to a table. This
option will be seen in detail when we study the DAX part.
Delete: it allows you to delete columns from a table.
Freeze: allows fixing columns, so that they remain visible when
scrolling horizontally. It does not affect at all how users will see
it in the pivot tables, and it only affects the display of the table in
the Power Pivot Management window.
Width: allows you to adjust the width of the column in pixels. It
only affects the display of the table in the Power Pivot
Management window.

Group of options 'Calculations': these are options related to the execution of


calculations using DAX expressions.
Insert Function: applies to the formula bar, it helps us when
writing DAX expressions, allowing us to use a search form about
the available functions.
Calculation Options: Allows calculations to be performed
automatically, i.e., every time you enter or change a DAX
expression, the values are recalculated. The advantage is that you
have the result immediately, but the more DAX expressions you
have in the model, the slower any change is made (it recalculates
all of them, not just the one you have modified). Therefore, from
here, you can change the option to 'Mode Manual calculation,' so
the calculations will only be made when you decide, that is,
when you press the option on that same button, called 'Calculate
now.' It is common practice to remove the 'Calculation automatic'
while we are designing the models, thus achieving shorter
waiting times when writing DAX.

Group of options 'Relationships': these are options related to the management


of relationships between tables.
Create Relationship: a relationship is established based on a
column in a table that is related to another column in another
table. Both have to be the same type of data. This is the form that
allows us to create a relationship.
Manage Relationships: allows you to create, modify, or delete
relationships.

You can also create relationships from the 'Diagram View' by clicking on the
source column of the relationship and dragging and dropping on the target
column of the relationship, as shown in the image:

Releasing the mouse will create the relationship between these columns in
both tables.
Relations - besides being between columns of different tables and having the
same type of data, we must coherently create them. For example, even if the
product code is numerical and the supplier code is also numerical, there is no
point in establishing a relationship between the two (even if the tool allows
me to), and we would get totally false and inconsistent analytical data.
Therefore, when establishing relationships, we are going to do so based on
the relationships defined in our documentation of the model, which is where
it is already studied in detail and set down in writing what relationships there
should be between the tables of the model and through which columns they
are to be carried out, all of this applying the good modeling practices studied.
Here we will merely do the operational part of physically creating them in
Power Pivot based on the documentation.
Next, we are going to mention a series of limitations that we have when
creating these relationships, and that partly affect the design of the model,
although if we follow the good modeling practices studied, we will be given
this casuistry in fewer occasions:
Only one column can be used for each table involved in the
relationship. Although this aspect is reflected in the form, where
you can only select one column, we want to highlight it here
because other tools allow several columns from each table to be
involved in the relationship.
There can only be one active relationship between two tables.
For example, if I have a sales table with three dates (sale date,
shipment date, and collection date) I will have to establish a
relationship for each of these columns with the table of the
dimension 'Date,' but only one of them can be active, leaving the
other two as inactive. An active relationship is the one Power
Pivot uses by default to obtain information from two related
tables. If we need to use an inactive relationship, we will have to
do it using DAX expressions in which the inactive relationship to
be used is expressly indicated.
It only allows for one-to-one or one-to-many relationships.
Relationships between two columns in the same table are not
allowed (self-referenced relationships).
Circular relations are not allowed, that is, if table1 is related to
table2 and table2 to table3, table3 cannot be related again to
table1.

Option 'Table Properties': allows you to edit the table properties. As we


explained before, there is no designer for this, but the structure of the table
comes from the result of obtaining and transforming data from Power Query
or from the options to 'obtain external data' included in Power Pivot. If we
have used Power Query, in the form, you cannot make any modifications to
the process made with Power Query, but you have to go to Power Query and
make the appropriate changes. If the process was done with any of the
options in the menu 'Get External Data' of Power Pivot, from here, we would
have access to consult and modify it.
Option 'Mark as Date Table': allows you to select which is the Date table.
This table corresponds to the Date dimension, which we studied in detail
previously. With this option, we must assign this table and mark which
column has the data type Date. From that moment on, the time intelligence
functions that are part of the DAX language are enabled. Basically, in Power
Pivot, at the model creation level, you only have to make this assignment. The
bulk of the work is to include in the dimensional model a 'Date' dimension
that compiles all the time treatment needs of each business and, later, to
include the calculations through DAX expressions that help to enrich the
analysis.
Group of options 'Edit': these are options to redo and undo.
Undo: undo.
Redo: redo.

'Advanced' Menu

Ribbon, 'Advanced' menu


Group of options 'Perspectives': these are options relating to the management
of perspectives. Perspectives are subsets of model elements that allow for
simplified navigation. Let's suppose that we have a sales model with diverse
information related to the stores, but not all of it provides value for the
analysis that our sales team is going to carry out, although it is useful for
other departments.
Therefore we can make a personalized view that only shows the selected
elements that the commercials need, avoiding them to have a hard time
finding what they need among a lot of information that they will never use. In
the following image, you can see that the perspective called 'Commercial,'
where instead of having access to all the data of the stores, only the fields
will be offered: Category – SubCategory - SalesTerritoryCountry,
SalesTerritoryGroup, SalesTerritoryRegion:
Selection of fields from a Perspective
Create and Manage: allows you to create and manage
perspectives.
Select: allows you to select one of the existing perspectives.
When you select a perspective, you only see the fields that are
marked in it.
Show implicit Calculated Fields: shows or hides the calculated
implicit fields. These fields are those that are created when you
drag a numerical column into the value zone of a pivot table or
pivot chart, using the summation aggregation function by default.
From their first use, they appear in the grid of the administration
window automatically. The appearance of Implicit Calculated
Fields can be avoided to a great extent by applying a good
practice that consists of creating all the calculated fields that we
need and assigning them the appropriate format, and then
marking the columns from which they are calculated as not
visible in client tools (as they are not visible we will not be able
to use them and, therefore, no implicit calculated fields will be
created from them).
Summarize By: indicates the aggregation function (sum, min,
max, ...) that you will use by default when you create a field
calculated implicitly by that column.
Default Field Set: it is the default set of fields that will be shown
in the client tools when we directly select a table of the model,
besides it will do it in the order that they appear in the box on the
right side of the form. If we don't define this set of fields, it will
show all the fields in that table, in the same order as they appear
in it.
Table Behavior: Allows you to define certain advanced
visualization options in client tools. For example, we can
configure the behavior of some features of this table when we
use it in Power View.

As a summary we show the way we have walked so far with what we have
seen on Power Pivot, to give you an idea of the road we still have to walk,
and that we will cover it in the section dedicated to the DAX Language:

Evolution and learning process of Power Pivot and DAX


All these advanced options, to understand in detail all their possibilities, need
to be defined and then check their behavior in the client tools, mainly pivot
tables, dynamic graphics, and Power View.
Here is a summary of the steps we recommend you follow to create an
analysis model with Power Pivot:
1. To have the logical design of the dimensional model to be
created. It is very important to have applied the studied good
practices, and it will avoid many problems, as well as
unnecessary complexities in the DAX expressions that will be
made later.
2. Use Power Query and/or Power Pivot's own data collection tools
to extract the data from the sources, transform it according to the
established model and save it in Power Pivot.
3. Use the design options offered by Power Pivot, applying the
good design practices studied, to improve the model, i.e.:

Assign suitable data types and define formats that


improve the display.
Manage the relationships between tables (based on the
model documentation)
Create hierarchies (based on what is defined in the model
documentation).
Make adequate time treatment (Date Table).

4. Enrich the model with DAX, creating calculated columns,


calculated fields (measurements), and KPIs.

So far we have studied how to perform most of the process, we know how to
create dimensional models and make the logical design, we know how to
perform ETL processes (extraction, transformation, and loading) using Power
Query and make the appropriate improvements to the model.
We still have to obtain external data from the Power Pivot itself and know the
DAX language to enrich the model. These points will be the ones we see
below.

Uploading Data to Power Pivot


At this point, the reader will wonder why I have a menu available to obtain
external data within the Power Pivot itself if I have Power Query?
The truth is that it is a totally logical question and that we have also asked
ourselves, the main reason we found is that when Power Pivot came out in
2010, there was no Power Query (which appeared in 2014). Therefore the
tool itself incorporated the possibility of obtaining external data from
different sources.
Nowadays, there are a lot of Excel files that have used these options in them,
and on the other hand, many users that have not installed Power Query, either
because of ignorance (you have to download and install it separately) or to
avoid new learning.
Therefore, at the moment, and this is a personal opinion: it is complicated to
eliminate these options, although we believe that in the future they will be
eliminated and they will be aligning everything in the same place because
basically, the functionalities available in this menu are a subset of those that
are available in Power Query; with some small exceptions, there are some
data sources (like Informix and some other) that are in Power Pivot and not in
Power Query.
If you already know Power Query, have experience with the tool, and have it
installed on the computers you work with, you do not need to use any of
these features from Power Pivot. However, if you decide to use them, with
the knowledge acquired about Power Query, there won't even be a learning
curve, just click on the menu options and follow the instructions, you won't
have any problem understanding what the tool will ask you for. The only
thing you will find is that there will be fewer steps and fewer options in the
process of obtaining data, which will limit you, and you will not have as
much flexibility as to when you use Power Query.
There will always be occasions, in both Power Pivot and Power Query, when
you need to rely on IT staff to provide you with the connection data to the
corporate servers.
Although we have commented that its use is optional, we will be looking at
the options available.
Ribbon, 'Home' menu, 'Clipboard,' and 'Get External Data' option groups.
Group of options 'Clipboard': allows you to paste data tables from
The 'clipboard' is stored as a table inside the Power Pivot. It is an option that
is available, and that may seem useful and comfortable for you to use, but I
advise you not to use it because it has more disadvantages than advantages.
Once the table has been created, you have no chance to make changes to it (I
remind you that this is a feature of Power Pivot), the way to update it is by
refreshing it with the data that is currently in origin. But there is an exception,
which is precisely when they come from the clipboard since the clipboard is
only stored in RAM, and therefore, there is no link to the origin once the
table has been created. If you want to update the table, you must copy the
data back to the clipboard and use one of the following options:
Paste: creates a new table from the data in the clipboard; in it, we
can only choose its name and if the first row contains headers or
not. Later we can make improvements just like on any other table
(change column names, data types, assign formats, etc.)
Paste Append: paste the data, but adding it and keeping the data
that was already in the table. It only works on boards that were
created by pasting from the clipboard.
Paste Replace: Paste the data, leaving only the data, and
removing all the data that was previously in the table. It only
works on boards that were created by pasting from the clipboard.
Copy: allows you to copy the selected cells to the clipboard. It
works like in Excel, or like in any other application that allows
copying to the clipboard.
Group of options 'Get External Data':
From Database: it has a drop-down menu with the following
options:

From SQL Server: allows obtaining data from


Microsoft SQL Server.
From Access - allows you to obtain data from Microsoft
Access.
From Analysis Services or PowerPivot: allows you to
obtain data from SQL Server Analysis Services (SSAS)
or from SharePoint PowerPivot models. It is important to
remember that data stored in the PowerPivot cannot be
obtained from another Excel file.

From Data Service: has a drop-down menu with the following


options:

From Windows Azure Marketplace: allows obtaining


data from Microsoft SQL Server.
Suggest Related Data: Suggests related data sources
that exist in the Azure Marketplace.
From OData Data Feed: allows obtaining data stored in
Open Data sources.

From Other Sources: a form appears with a variety of sources,


including relational databases, Analysis Services databases,
'Data Feeds,' text files, etc. This includes all previously viewed
sources and additional ones.

Existing Connections: shows a list of connections that we have


already created on our computer so that we can reuse them
without having to enter all the data necessary for the connection
again. This data is stored in files with the extension ".odc."
Chapter Three:
Introduction to DAX

Where Are We On The Road?


At this point, before tackling a subject, which is certainly the one with the
highest degree of complexity and at the same time the one that contributes the
most value to our business analysis, we would like to take a little break from
the evolution of the learning that we are doing daily, getaway like a bird and
take an overview of the road we have traveled and the one we have yet to
travel. To do this, we will review the development cycle of a Personal BI
solution:
We start by identifying a Business Process and documenting it. From there,
we design the Dimensional Model that will allow us to answer the business
questions. As this model is empty (it still does not contain information), we
must design an ETL (Extraction, Transformation, and Loading) process that
incorporates the information into the model. From this point on, and
depending on the tool we are using (in our case, Power Pivot), we must make
the improvements we consider appropriate to the model.
We have already studied and practiced everything mentioned above with
different real case studies. So we have two more phases to discover: Enrich
the information through the DAX expression language and Perform the
Visualization layer. Once put in context, we will focus on Power Pivot, and
we will also see the road we have traveled and what remains to be done.
With what we have seen so far, we have made the dimensional model, which
is the basis of our entire solution, we have created the ETL process (either
with Power Query or Power Pivot) that has allowed us to load the
information in our storage in Power Pivot, we have been able to improve the
model (data types, relationships, hierarchies, etc.) and it is time to enrich the
model through DAX.

What is DAX?
DAX (Data Analysis Expressions) is a language of expressions that we can
find inside Power Pivot, and it is based on formulas that allow defining
personalized calculations. It consists of a library of functions and operators
that can be combined to generate formulas and expressions. It is characterized
by its simplicity of syntax and its similarity to Excel formulas and has even
inherited many functions with the same name and functionality (except for
small variations in a few exceptions).

DAX Syntax
Excel's formulas are oriented to calculations based on cells and ranges of
these, for example, in cell A21, we can write the following expression:
=SUM(C1:G1)
We also have a new syntax, incorporated in the latest versions of Excel, that
applies in the case that we have formatted a set of cells as a table, which
allows us to reference columns in the table using the format "
[@ColumnName]." Note that in tables, you can use both the traditional cell-
based syntax and the new column-based syntax.
Why are we talking about these two syntaxes here? So to facilitate the
introduction to the DAX syntax, which is more similar to the syntax we just
saw, based on tables, although with some peculiarities:
It is only allowed to reference columns in tables, and there is no
cell concept.
It can be applied to calculated columns, calculated fields
(measurements), and KPIs.
In the case of calculated fields (measurements), the syntax
includes the name of the new field.
KPIs do not allow the use of table columns or calculated
columns, and they only allow the use of calculated fields
(measurements).

Calculated fields are the new name given to what used to be called
Measurements as of the 2012 version. It is simply a name change; the
concept, functionality, and features remain the same. Here we will use the
new name and in parentheses the old one, as you should know both, and you
will find a lot of documentation on the internet using the term "Measures."
In DAX: Calculated fields = Measures
Where are the DAX formulas written? Within the Power Pivot window,
although it is located in a different place and with certain nuances in the
syntax, depending on whether it is a calculated column or a calculated field
(measurement).
The Syntax for Calculated Columns
It is similar to sets of cells formatted as tables:
= "Expression."
= FUNCTION ("Expression1" ; "Expression2" ; ... )
To refer in any expression to the columns of a table, we will use the format
'Table' [Column], and follow the following rules:
Single quotes " ' " are optional when indicating the table, they are
only mandatory if the table name contains spaces or special
characters:

Customers' table, Customers

If the table column used in the calculated column expression


belongs to that same table, it is optional to enter the table name:

'Sales Table' [SalesAmount], Sales [SalesAmount],


[SalesAmount]

Brackets are mandatory. It is the form that identifies that we are


referring to a column in the table.

'Sales Table' [SalesAmount], Sales [SalesAmount],


[SalesAmount]

The input of the calculated column expressions is done in a text box that is
right at the top of the table, very similar to where you enter formulas in
Excel. Once the expression has been entered, to change the name of the
calculated column we right-click on it and choose the option "Change name
of column" (this is the way to do it, since the name of the calculated column
is not part of the DAX expression).
When we are writing an expression for a calculated column, we always get a
contextual help that makes the task easier.

The Syntax for Calculated Fields (Measurements)


Calculated field := "Expression."
Calculated field := FUNCTION("Expression1" ; "Expression2" ; ... )
The same rules as above are used for the calculated columns, except that in
this case, the name of the calculated field (measurement) does form part of
the DAX expression and is indicated on the left side of the " := " symbols.
The process of entering calculated fields consists of positioning yourself in
any free cell of the area of the calculated fields (the grid at the bottom of the
table), clicking on the DAX expression area or the "F2" key, writing the
DAX expression and pressing the "Enter" key.
Once a calculated column or a calculated field (measurement) is created, it is
available to be used in any DAX expression we create. In fact, we
recommend that whenever possible, you reuse them and avoid rewriting that
part of the expression.
Whether you are using Excel in English or another language, only the
original English function names will be valid. For example, we will always
write SUM(... AVERAGE(..., etc. Translations such as SUM(...,
AVERAGE(..., etc.) will not be valid.

Calculated Columns
A Calculated Column is a column that is added to an existing Power Pivot
table, using a DAX expression that defines it. The value of the expression
used is calculated for each row of the table at the same time it is created (at
model design time) and then updated when the source data is updated (by
pressing the "Refresh" button).
You can create calculated columns based on other calculated fields
(measurements) and other calculated columns.
The calculated columns are added to the right of the columns we have
extracted from the data source and automatically assigned the names
CalculatedColumn1, CalculatedColumn2, and so on. Although you can
rearrange the order of the columns by clicking on them and dragging them to
the desired position, you can also rename any calculated column by right-
clicking on it and choosing the option "Rename column."
Its values are stored on disk and in memory in the same way as any
other column in the table. Technically they are known as "materialized" or
"persistent." They are designed to be static.
The calculated columns can be used later in Excel:
Segmenters (Slicers)
Filters
Rows
Columns
Values

Let's look at some examples of use:


Calculate the year (or any other date-related calculation) in a new
column=YEAR ([Date])
Concatenate the serial number and
invoice= [Serial ]&"#"[Invoice]
Calculate the Margin= [NetPrice] - [PriceCost]
Get a column from another table=RELATED (Province
[Provincial])

It's one more technique to denormalize


When we drag a column into the value area, something happens internally
that we must understand, really what Power Pivot does is to create an
"Implicit Calculated Field," this happens whenever we drag a column of a
table, whether it is calculated or not, to the value area.
An Implicit Calculated Field is one that does not originally exist but is
automatically created when you drag a column into the value area. From then
on it exists as one more field which by default is assigned the aggregation
function SUM and its default name is "sum of
Calculated_Column_Name". For example, if you have the SalesAmount
column and drag it into the value area for the first time, the calculated field
"Sum of SalesAmount" will be created automatically.
An Explicit Calculated Field is one that we create in design time in Power
Pivot in the grid designed for it. Next, we will study in detail the calculated
fields (measurements).
At this point, we ask ourselves the following question that has several
answers, with its pros and cons: Where should I perform the calculations,
with SQL when asking for information from the source, with Power Query,
with calculated columns?
With SQL, we have two disadvantages, we need to know SQL language (it is
evident), and in addition, the information is calculated in origin consuming
resources of the server and traveling by the network once calculated. We do
not recommend it in this case.
With Power Query, it is calculated during the execution of the data update
process, it is done already at the destination, in the computer where it is
running, and the column is stored like any other column in the source (we are
not really able to distinguish when we are looking at the column information
in Power Pivot if a column exists in the source or is calculated with Power
Query. This is a good alternative, leaving all that calculation logic in Power
Query, it has the advantage that if I need certain columns only for the
calculation I can use them in the process and they don't have to get to the
model in Power Pivot.
Using calculated columns, the DAX calculations are quite efficient, but on
the other hand, it forces me to bring the columns involved in the calculation
into the model and thus take up unnecessary space. What we can do is hide
them from the user so that he does not see them.

Calculated Fields (Measurements)


Calculated Fields, also known as Measures in previous versions, are the
calculations used for information analysis.
They are created when you write a DAX Provincement after you select a cell
in the calculation area (this process has been seen in detail above).
Their values are not stored on disk (as is the case with the calculated
columns) but are calculated by the engine when it receives the queries.
Thanks to them, we will have almost infinite computing power. No, I'm not
exaggerating. To make you aware from the beginning of the importance and
scope of this incorporation, I am going to quote one of the greatest gurus in
the field, Bill Jelen (Mr. Excel):
"The Calculated Fields (Measurements) is the best thing that has happened to
Excel in the last 20 years."
We may find that formulas are added and can be used in a dynamic table or
graph, and so they are, but what is really relevant is that they offer
unprecedented calculation power and flexibility.
If you have already used the pivot tables and you know the formulas that can
be created in them, the new message is: "you will stop using them," it is no
longer necessary, you have DAX that does everything those formulas and
many other things. If you have not used this feature, it is not a problem, it is
not well known, and you will not need it from now on either.
Use of Calculated Columns vs. Calculated Fields (Measurements)
We consider it a fundamental question to know when to write a calculated
column, and when a calculated (measured) field should be written. Although
there is no single answer, we will give you a series of guidelines to help you
in your decision. We will show you what to use in the following cases:
Use Calculated Columns when only Values from the Row where it is
going to be Represented are Involved in the Calculation
If for each row of the table, we have the number of units sold and the total
amount of the row, but not the net unit price, and we want to calculate it.
Another common example is when we have a date, and we want to extract
from its new columns with the year, month, quarter, day of the week, etc.
Use Calculated Columns if you Need to Use them in slicers, Filter Area,
Rows or Columns
As we have seen above, calculated fields (measurements) can only be used in
the value area (there is no way to place them in another area), while
calculated columns can be used in addition to the value area, in segmenters
(slicers), filter area, rows or columns. We don't always have this need, and
calculated columns have less flexibility than calculated fields, so think
carefully when making your decision whether you really need to use it
beyond the value area.
Use Calculated Fields (Measurements) In All Other Cases
Calculated fields (measurements) are especially useful and flexible for
performing calculations that affect sets of rows. For example, knowing the
active customers (those we have sold to them over some time)
The next step is to get to know some fundamental concepts and the functions
that make up the DAX language, to practice with them, and to show
examples of use.

DAX Functions
We are going to start with the study of some of the basic and most common
DAX functions, and then go into more detail and additional concepts that we
need to be clear about to obtain the best analytical result.

Legacy Excel Functions


Let's start with the legacy Excel functions. If you see the name of a function
that you already know from Excel, you can use it directly, since, in Power
Pivot, it will have the same behavior and parameters that you have in
traditional sheets. There will only be very few exceptions that we will see
when the time comes to study each function in depth. Another difference,
already mentioned above, is that there will be no translation but only the
function with its English name.
The following image shows a list of these functions:
Legacy Excel functions

Aggregation Functions
There is another group of functions, the Aggregation Functions, which
come from the relationship of functions inherited from Excel and will make it
easier for us to begin to understand the differences between traditional Excel
and Power Pivot.
Aggregations allow you to contract, summarize, or group data. They are in
charge of calculating a column from the maximum level of detail of its rows,
affecting in principle all of them unless we indicate some kind of filter or
descriptive breakdown.
Let's see an example, and if we want to know the total sales of the company,
we will create a column calculated using the SUM() function.
So far, nothing new, we have already seen this function in previous examples,
and it gives us the sum of all the values in the column "[SalesAmount]."
Let's now see what we have achieved by writing such a simple function for
visualization and use in a pivot table. Note that we have also applied to
format so that it always shows two decimals and the thousands of separators
(how to do this was studied earlier).
If we create a pivot table connected to our model in Power Pivot and drag
"TotalSales" to the value area, it shows us the result of adding "
[SalesAmount]" for all the rows of the table and already formatted.
Now we break it down into a row for each store, and we break it down again
with a column for each year.
And finally, we added a filter to have only the sales of "single" customers
(Marital Status=Single):
How many DAX formulas have you had to perform to obtain all this
information regarding the company's sales amount?
JUST ONE!!! And keeping the same value in the
But, if you had used the SUM function in traditional Excel, how many times
would you have had to change the cell ranges of the parameter that passes to
that function to get that result? It's not even worth counting them, obviously
one for each change.
That is where one of the elements that give that computing power and
flexibility to perform analysis resides. But this is not the only element; later
on, we will go deeper and understand why this behavior is so simple after
creating a calculated (measured) field in DAX.
We will now explain the different types of aggregations that exist and the
functions in each of them:
Additives: They add without restrictions.

Functions: SUM, COUNT, COUNTROWS,


AVERAGE

Semi-additives: They only add-in part, let's see an example: we


need to know the total number of different customers who buy in
our stores, we know that in January there have been 200
customers, in February there have been 225 customers and in
March 210; on the other hand, if what we want to know is the
total number of different customers who buy in our stores in the
first quarter, we cannot add it up as it is, because there will be
customers who have bought from us during the three months of
this quarter and others who have not, therefore it will be a
number between 225 and 635.

Functions: DISTINCTCOUNT

Non-additive: Cannot add.

Functions: MIN, MAX

Customized: we decide through various DAX expressions how


they should act. For example, if we want to calculate a balance
sheet, there will be accounts that add and accounts that subtract.

Functions: there are no specific ones; we will have to


create more complex DAX expressions that solve each
need individually.

The following table shows the syntax of these functions and a brief
description. For more details, you can see the product's help.

Add up all the rows in a


SUM(<Column>) column.
= SUM([SalesAmount])
Count the number of rows in
a column that has numerical
COUNT(<Column>) data or dates.
= COUNT([SalesAmount])
Count the number of rows in
COUNTROWS(<Table>) a table.
= COUNTROWS('Client')
= COUNTROWS(
RELATEDTABLE(
Sales' ))
It returns the average of all
the numbers in a column.
AVERAGE(<Column>)
=
AVERAGE([SalesAmount])
Count the number of rows
with different values in a
column.
DISTINCTCOUNT(<Column>)
=
DISTINCTCOUNT(Sales
[Ticket])
Returns the smallest
numerical value in a column
MIN(<Column>) that has numerical data or
dates.
= MIN(Sales [StoreSK])
Returns the largest numerical
value in a column that has
MAX(<Column>) numerical data or dates.
= MAX(Sales [StoreSK])

Navigation Function Between Tables through Relationships


These functions allow us to navigate and obtain column values from various
tables in the model as long as there are relationships between them.
The following table shows the syntax of these functions and a brief
description. For more details, you can see the product's help.

It returns a related value from another table


column following the M->1 relationship.
Example: add a column calculated with the "
RELATED(<Column>)
[Population]" to the "Store" table (Many
Stores -> 1 Population):
=RELATED(Geography(Population))
It returns a table in a context specified by the
filters indicated, following the relation 1->M.
RELATED(<Table>) Example: add a column with the number of
customers to the table "Geography":
=
COUNTROWS(RELATEDTABLE('Client'))

The RELATED function can be used, for example, to un-normalized,


creating calculated columns that allow columns from several related tables of
the origin to be added to a single table.
We will come back to the RELATED function later, as it is used in
conjunction with other functions, and we need to understand what contexts
are and how they work.
Chapter Four:
DAX in Practice

Understanding the Contexts


Previously we have seen that with a very simple DAX expression, such as the
calculated field (measurement).
It has allowed us to analyze in a dynamic table, the total sales, the sales by
store and year, the sales to single customers by store and year, ..., and thus we
could have continued showing dozens of reports based on that calculated
field.
But you will also sometimes find that the DAX expression you perform does
not return the value you expect, much of the blame lies with the contexts.
Therefore, we are going to study them next, since it is essential to know them
and how they behave to understand any DAX function.
Contexts allow for dynamic analysis, where the results of expression vary
according to the selections made in the row, column, and filter areas. We
must know them and use them effectively, both avoid getting the wrong
results and to generate efficient expressions.
We have three types of contexts:
Row Context
Query Context
Filter Context

Row Context
It applies to the elements in the row in question, the "current row." It is used,
among others, in the calculated columns. It covers the row being calculated
and the rows of other tables related to that row.
It behaves like the Excel formulas applied inside a table, automatically
referring to values in the same row. If the table is related to others, you can
access any value in those tables that are related to the current row. To access
these related tables, we have the RELATED function explained above.
There are other types of cases for which DAX has a series of functions that
iterate, in a kind of internal loop, the calculations on a table. For the time
being, it is sufficient to understand the above and to lay down a good
foundation.

Query Context
It evaluates a dataset for a specific cell. It refers to a subset of data that is
implicitly retrieved for formula and allows elements to be added to the filter,
row, and column areas.
When you place a calculated field or a column with numerical values in the
value area of a pivot table, the Power Pivot engine examines the column and
row headers, data segments, and report filters to determine the context. Power
Pivot then performs the necessary calculations to fill each cell in the pivot
table. The data set that is retrieved is the context of the query for each cell.
For a calculated field (measurement), it is the one defined by the row and
column, plus the filters applied from segmenters (slicers) and filter areas.
Let's look at a simplified sales example, with a very reduced number of rows
and columns to understand it better. To analyze the sales, we have put in
rows the dates, in values the calculated field "Sum of the amount" (implicit
calculated field), and we have added two segmenters, one for Customer and
another for Product.
In the table, you will see the cells read by the Power Pivot engine to obtain
the value that appears calculated in the dynamic table on the right (light blue
and white).

Filter Context
It is applied to the row and query contexts to generate exceptions and allow
us to vary the evaluated cells based on our needs. That is, it allows you to
reduce or extend the row context (Row context) and query context (Query
context) using additional filters applied in the DAX functions
There are many cases in which we must apply additional filter contexts, but
to understand this we are going to make a simple example in which we are
going to calculate the sales ratio of each client concerning the total sales of
the company, for this, we are going to define the following calculated fields:
TotalImport:=SUM([Amount])
TotalCompanyImport:=CALCULATE([TotalImport];ALL(Sales2))
RatioSales:=DIVIDE([TotalImport]; [TotalCompanyImport])
Note that "TotalImportEnterprise" is always 656. Later on, we will study the
CALCULATE and ALL functions, as well as other functions that allow us to
perform filter contexts.
As you can see, we have applied the good practices of creating fields
calculated with simple calculations and reusing them. It is preferable to do
this with the three calculated fields shown above than with the following
expression:
RatioSales:=DIVIDE(SUM([Amount]);
CALCULATE([TotalAmount];ALL(Sales2)) )
Both for the simplicity of understanding them, and for their subsequent reuse,
if we do it as we initially proposed, we will be able to reuse the calculated
fields "TotalImport" and "TotalImportEnterprise" in any other calculation we
need to do, and if there were any error just correct it there would be
automatically corrected all the calculated fields that include them.

DAX Functions
Once we have laid the foundations, we can learn any DAX function and
apply it correctly. Here are some frequently used ones, which are also often
used in combination with other existing functions.

Aggregation Functions Ending in "X


We have several aggregation functions ending in "X," such as SUMX,
COUNTX, AVERAGEX, MINX, MAXX, etc. These functions iterate row
by row on the table. We pass to it as the first parameter and do the indicated
operation as the second parameter, to finally apply the indicated aggregation
function to the result.
Let's look at something that seems very simple to use a priori, which is also
an expression that we can use in the calculated columns (remember, row
context), but which is not allowed to be used in the calculated fields
(measurements).
In the following table, we have "Quantity" and "SalesAmount," but not
"NetPrice," this is not a problem is a simple division to which we will also
apply rounding to four digits.
If we later need to know the total sum of "NetPrice" we can create the next
calculated field:
TotalNetPrice:=SUM([NetPrice])
Now we put ourselves in the situation that we need to make that calculation
in a calculated field (measurement), dispense with the calculated column and
save that disk space and memory; therefore, we go to the grid and create it:
NetXPrice:=ROUND([SalesAmount]/[Quantity];4)
But we came up against the mistake:
Semantic Error: The value of ImportSale cannot be determined
Well, what we really want is a calculated field that gives us the sum, so we
include the SUM function as follows:
TotalNetPrice:=
SUM(ROUND([SalesAmount]/[Quantity];4))
And again we find a mistake, which is different now:
Semantic Error: The SUM function only accepts a column reference as an
argument.
Can't we really make a calculated field that adds up the result of an
operation? Well, we can, but not with the SUM function, for that we must use
the SUMX function.
TotalNetPrice:=SUMX('Sales';
ROUND([AmountSales]/[Quantity];4))
Be very careful about making incorrect calculations, which we tend to do
when we start in the DAX language. Let's see the next calculated field:
TotalMalPrice:=
ROUND(SUM([AmountSales])/SUM([Quantity]); 4)
This second case, what it does is, first add "SalesAmount" for all the rows,
then add "Amount" for all the rows and finally divide both results.
Let us now handle the result of the three calculations on the pivot table; the
calculation error made in the last case is abysmal.
This is an extreme case, but you should keep in mind that as we make more
sophisticated calculated fields (measurements), you may get grand totals and
subtotals that do not equal the sum or average of their detail. In these cases,
the aggregation functions ending in "X" will help you.
The following table shows the syntax of these functions and a brief
description. For more details, you can see the product's help.
SUMX(<Table>; Returns the sum of an expression
<Expression>) evaluated by each row of a table.
COUNTX(<Table>; Returns the number of rows that
<Expression>) meet the evaluated expression.
AVERAGEX(<Table>; Calculates the average of an
<Expression>) expression
evaluated by each row in the table
MINX(<Table>; Evaluates one expression per row of
<Expression>) the
table and returns the smallest
numerical value.
MAXX(<Table>; It evaluates one expression for each
<Expression>) row in the table and returns the
highest numerical value.

ALL() and ALLEXCEPT() Functions


The ALL function is used to remove filters from the context. It has two
syntaxes:
ALL(<Table>)
ALL(<Column1>;<Column1>;...;<Column1>)
You cannot combine both options. If a table is indicated, remove all filters
from the specified table. If one or more columns are indicated, remove the
filters from the specified columns, keeping the filters applied for the rest of
the table columns.
This function is not used alone but is used as a parameter for other functions
to change the set of results on which other calculations will be performed.
The ALLEXCEPT function is the opposite in terms of context filters to be
removed, i.e., it keeps the context filters applied to the specified table or
columns and removes all others. It also has two syntaxes:
ALLEXCEPT(<Table>)
ALLEXCEPT(<Column1>;<Column1>;...;<Column1>)
And on it applies everything explained for the ALL function.
Let's see an example of when to use one or the other since, in many cases, it
is more a matter of writing less. If we have a table with 15 columns and we
need to apply ALL on 14 of them, it is more practical to use ALLEXCEPT
on that one column I do not want you to apply ALL on. The difference would
be in the behavior it would have if a new column was included in the table, in
the first case ALL would continue applying on the 14 columns indicated as
parameters and would not apply now on 2 of them, while in the second case
ALLEXCEPT would make it apply on 15 columns (the new one would be
included) and would not apply on the only column we include as a parameter.
FILTER() Function
The FILTER function allows us to make a filter on a table. Its syntax is:
FILTER(<Table>;<Filter>)
<Table>: is the table to be filtered. Note that it can either be a table
directly or a Provincement that returns a table as a result.
<Filter>: It is a Boolean expression, that is, the result of evaluating it
has to be True or False. For example: [AmountSale] > 0,
[Product]="P2", ...
This function is not used alone but is used as a parameter for other functions
to change the set of results on which calculations will be performed.
The FILTER function can be used as a parameter in functions such as
CALCULATE, COUNTROWS, SUMX, etc.
If you know the SQL language, you should know that it has certain
similarities with the WHERE condition.
Let's see an example of use:
FILTER(Sales2;[Product]="P2")
Later on, we will see additional examples using FILTER as a parameter for
other functions that we will study.

CALCULATE() Function
The CALCULATE function evaluates an expression in a context that has
been modified by the filters passed to it as parameters. Its syntax is:
CALCULATE(<Expression>;<Filter1>;<Filter2>;...;<FilterN>)
All the "Filter" parameters applied for work as if they were within a Y()
(AND()) function, that is, the expression will only apply to the rows that
comply with all the filters.
As this definition can tell you little at this time, let's see with other words
more understandable for any Excel user. CALCULATE is like the SUM.SI()
function, but its power and flexibility has been increased almost
inexhaustibly. But what does this really mean? So the function
CALCULATE instead of applying only to "ADD" applies to any DAX
expression we pass to it as the first parameter, and instead of the condition
"YES," it applies to all the filters we pass to it as a parameter. Remember that
the concept of the filter is used only to select a part of the selected values, but
it is a switch to filter context, so you can select several rows that is higher
than the filtered ones at a given time.
We are going to show a very basic example by emulating the function
SUM.SI(), which although not very useful, will help us to understand better
the function CALCULATE:
SumImportP2:=CALCULATE(SUM([Amount]);
Sales2[Product]="P2")
SumImportP2:=CALCULATE(SUM([Amount]); FILTER(Sales2;
[Product]="P2"))
The two expressions above are equivalent. We have used an addition
expression and applied a filter so that it only adds up the amounts of the
product "P2".
Let's take up the example we saw earlier when we explained the Filter
Context, and now we will be able to understand it in detail:
TotalImport:=SUM([Amount])
TotalImportCompany:
=CALCULATE([TotalImport];ALL(Sales2))
We have used an addition expression and applied a filter context, so that
instead of applying the filters defined by the user in the pivot table, always
apply to all the rows of the table 'Sales2', since the function ALL() here
means "return all the rows of the table sales2 without filtering".
Next, we will explain the keys to the operation of CALCULATE, to do this,
we must understand how the filters behave:
The "Filter" parameters change the context of the pivot table, by changing it
to filter context:
If the filter argument acts on a field that "Already" is in the pivot
table, it overrides that context and activates the filter context.
If the filter argument acts on a field that "No" is being used in the
pivot table, it adds it to the filter context.

Let's look at a third example of the use of the CALCULATE function. In this
case, something that has a certain complexity and poor performance in
relational database systems, but here it is done very easily and very well. We
need to know the accumulated sales from the beginning of time to a given
date; for this, we use the following expression DAX:
Accumulated Sales:=CALCULATE([TotalSales];
FILTER(ALL(Date); Date[DateSK] <= MAX(Sales[DateSK]) ) )
Time Intelligence Functions
Most of today's analytical systems incorporate several advanced time
management features. In this case, Power Pivot and DAX will not be less,
also incorporate them. This set of functions allows us to manipulate periods,
which is a very common requirement in BI.
There is a simple but important requirement that we must take into account,
to apply them, we need to have a column whose data type is "Date."
The time functions allow us:
Get specific dates.
Get a set of dates.
Evaluate an expression over a specified period

There's a group that returns on a particular day, some of these


are: FIRSTDATE(DateColumn)
LASTDATE(DateColumn)
FIRSTNONBLANK(DateColumn, Expression)
LASTNONBLANK(DateColumn, Expression) S
TARTOFMONTH(DateColumn)
ENDOFMONTH(DateColumn) Etc.

We are not going to study them one by one since they are functions that
either by their name or because they exist in Excel, are very simple to consult
in the help and start using them.
There's another group that returns a set of dates, some of which are
DATEADD(DateColumn, Interval number, interval)
DATESBETWEEN(DateColumn, StartDate, EndDate)
DATESINPERIOD(DateColumn, Interval number, interval)
PARALLELPERIOD(DateColumn, Interval number, interval)
Etc.

Here is an example that will help us understand the usefulness of this type of
function. It is very common that when we are working with a period, we want
to see the result that was obtained in the same period of the previous year, for
this, one of the functions that we can use is PARALLELPERIOD:
TotalSales:=SUM([AmountSales])
SalesPreviousYear:=CALCULATE([TotalSales];
PARALLELPERIOD(Date[Date];-1;year))
SalesPreviousQuarter:=CALCULATE([TotalSales];
PARALLELPERIOD(Date[Date];-1;quarter))

And finally, we'll see a third group that evaluates an expression over some
time:
TOTALYTD(Expression, DateColumn, Filter) -- Year
TOTALQTD(Expression, DateColumn, Filter) -- Quarter
TOTALMTD(Expression, DateColumn, Filter) – Month Etc.
Let's see an example of the use of TOTALYTD and TOTALQTD, which
allows us to make accumulated sales within the current year, initializing to
zero automatically for each year.
TotalSales:=SUM([AmountSales])
TotalCurrentYear:=TOTALYTD([TotalSales]; Date[Date])
In the following image, you can see the result obtained:

Practical Example of DAX


Here are some examples which allow us to define an analysis report of the
average ticket in our company.
These are the calculations we have used:
TotalSales:=SUM(Sales [AmountSales]) T
otalQuantity:=SUM([Amount])
NoOperations:=COUNTROWS(Sales [Ticket]))
AverageTicket(Amount):=DIVIDE([TotalSales]; [NoOperations])
Average Ticket(Quantity):=DIVIDE([TotalAmount];
[No.Operations])
Accumulated Sales:=CALCULATE([TotalSales];
FILTER(ALL(Date); Date[Date] <= MAX(Date[Date]))
As you can understand, it is not enough to do the calculations in DAX. Once
we get to this point, we have to be able to show them with the greatest
possible visual impact. We'll go deeper into these visualization techniques
later on, knowing the possibilities of the tools at our disposal and showing
multiple examples of use.

Using DAX Studio and Excel as Power BI Measurement


Verification Tools
If we have previously worked on the development of data models using
Power Pivot or SSAS Tabular when we have to do this same task, but from
Power BI, we will surely notice the lack of an important feature such as the
possibility of reviewing the results of the measures that we create in the
model from an Excel pivot table.
Take as an example; the data model based on the Population Register
outlined in chapter 7 on the design of a population data model of this book.
This chapter set out the creation of a set of measures for the model, which
allowed us to carry out the population analysis by the absolute number of
inhabitants and through a series of structure indicators. For the example that
concerns us at the moment, let us keep the Total Population measure and the
structure indicators by Age, assuming that we have not yet added them to the
model.
Total Population =
COUNTROWS ( PopulationCensus )
Youth Population =
CALCULATE ( [Total Population], Age [AgeID]> = 0 && Age
[AgeID] <= 14 )

Adult Population =
CALCULATE ( [Total Population], Age [AgeID]> = 15 && Age
[AgeID] <= 64 )

Major Population =
CALCULATE ( [Total Population], Age [AgeID]> = 65 )
Let's start by adding the Total Population and Young Population measures.
Then, using the means offered by Power BI, if we wanted to verify the
validity of the measurements, we would use Visual Card and Multi-row card
controls, to observe the total values, or Table or Matrix controls, to analyze
the numbers disaggregated by the elements of some of the search tables of the
model.
However, this procedure will seem somewhat cumbersome to carry out if we
already have experience in the development of multidimensional cubes or
tabular models, in which, simply by opening Excel and connecting to the
model, we already have a dynamic table with which to check the measures
we have created.
For this reason, we propose a technique explained by Matt Allington in his
blog, where in addition to Power BI, the use of Excel and DAX Studio is
required, working all the elements in a coordinated way to achieve our goal.

DAX Studio: A Really Useful Tool


If the reader usually works with tabular models, whether from SSAS Tabular,
Power Pivot or Power BI, this utility can’t be missing in your toolbox, and
not only by the technique that we will explain below, but by a large number
of features it offers, and that will surely make your work a little easier.
First, we will download DAX Studio from the link available on its website
and proceed to install it on our machine.
Then we will open the Power BI file on which we are developing our data
model, and in which we have already added the measures PopulationTotal
and PopulationYoungBoys.
Next, we will run DAX Studio, which, as a first step, will ask us to connect to
a valid data source. In our case, having already opened a Power BI file, DAX
Studio will detect this situation, offering to connect with it.
Regarding the other connection modes, if it is an SSAS Tabular data source,
it is very evident, since we only have to enter the server and instance name.
Finally, the connection against a Power Pivot model is made directly in the
Excel file that contains the model, from the Add-ons tab, by clicking on the
DAX Studio option.

Power BI and the SSAS Service


Returning to the current scenario, Power BI acts as an SSAS server, which
we can check from the Windows Task Manager.
This service is connected to DAX Studio to access the contents of the data
model, which allows us, among other features, to execute DAX queries,
obtain information about the execution times of the queries, execute dynamic
administration views (DMV - Dynamic Management Views), and a very
important fact: the address of connection to the service, which is shown in the
lower right part of the window.
The next step will be to open Excel and establish a connection against the
Analysis Services data source represented by the Power BI file, entering in
the window of the data connection wizard the address of the service obtained
from DAX Studio.
Accepting the rest of the steps in this wizard will result in a dynamic table,
connected to the Power BI model, from which it will be easier to review your
measurements.
Let us now continue with the development of the model by adding the two
measures of structure indicators pending to include: Adult Population and
Major Population.
Now we will return to Excel and select the Update option, located in the Data
options group, PivotTable Tools tab | Analyze, which will produce an update
of the contents of the pivot table, incorporating the new measures to it.
Reconnect with the Data Model in a New Work Session
It is important to mention that, after finishing our work session, closing
Power BI, DAX Studio, and Excel, when reopening Power BI, a new address
will be generated for the SSAS service, which we can verify when running
DAX Studio. Due to this, if we try to validate the measures of the model
using the same Excel file with which we had previously worked, we will get
an error.
Accepting this warning window will open a connection window in which we
can re-enter the new address. After confirming this and the next step, we will
reconnect successfully from Excel, and the pivot table will be operational
again.
Get Model Measurements from DAX Studio
Another small but useful trick of DAX Studio lies in the possibility of
obtaining a list of the measures that make up our model, with diverse
information among which is its source code. For this, in the query panel, we
will write the following sentence.
SELECT * FROM $ SYSTEM. MDSCHEMA_MEASURES
We can also drag and drop this dynamic management view from the DMV
tab located in the left pane of the DAX Studio window.
Then we will click on the Run option (or press F5), obtaining in the results
panel all the information related to the model measurements.
The MDSCHEMA_MEASURES view returns a large number of columns, of
which we may only need some very specific ones, such as the name of the
measure and the expression used to create it. Also, we also obtain a row
corresponding to the default measure of the model, which we can exclude
using the MEASURE_AGGREGATOR column. Therefore, we can refine the
previous query as follows.
SELECT
MEASURE_NAME, EXPRESSION
FROM $ SYSTEM. MDSCHEMA_MEASURES
WHERE MEASURE_AGGREGATOR = 0
The Power BI model that we are using for our example consists of a single
table of data or measurements, but if we develop more complex models, in
which several measurement tables intervene, it is advisable to add the
MEASUREGROUP_NAME column to the previous query, which we reports
the table name to which the measure belongs.

or weekly basis. This saves a lot of time and manual effort.


Chapter Five:

Power BI and Power Query


(M Language)

Since its entry into the arena of business intelligence tools, Power BI has
rapidly climbed positions within this segment of data analysis and decision-
making systems development, to position itself as one of the most interesting
options that They exist today thanks to a numerous set of qualities, among
which a powerful capacity for graphical representation of the resident
information in the data model, as well as the integration into the Power Query
product, the extraction, transformation and loading engine (ETL) also
included in Excel.
Precisely, the data mentioned above cleaning and debugging processes
represent one of the main pillars of the phases that make up the development
of an information system, so having a powerful and versatile tool to perform
these operations is essential. Power Query, thanks to its rich user interface,
which allows us to carry out the most varied operations of transformation and
adaptation of the source data, gives Power BI a great power in the preparation
of the data that we will later model using Power Pivot (DAX), to convert
them into accessible information through dashboards, reports, etc.
In the following figure, we can see a broad graphical representation of the
different phases that constitute the development of an information system
using Power BI.
And if this were not enough, where we cannot reach the operations available
in the user interface, Power Query also offers us the possibility to schedule
tasks through M, its formula language, which considerably expands the range
of options at our disposal.

The Role of BI Self-Service in the Development of a


DataWarehouse
The term self-service BI is usually associated with the ability of certain users
of a DataWarehouse to connect to the system, obtain a subset of their
information and analyze it independently to the main system, creating a
smaller BI structure focused on certain aspects of the main.
These are users with an advanced profile and great knowledge of the nature
of the data handled by the system, which, together with the appropriate tools,
can analyze the information with a different degree of precision than is
normally required by the bulk of end-users.
This type of user frequently works with the developers of the DataWarehouse
responsible for the design and creation of databases, cubes (multidimensional
or tabular), dashboards, etc., since it provides very valuable information for
the proper optimization of processes involved in its creation, that is why
having quality self-service BI tools such as Power BI helps to improve the
final result of the information system.

Power Query much more than Self-Service BI


Since its emergence in the BI market, Power Pivot, Power View, and
ultimately, Power Query, all add-ins of Excel, have been presented as self-
service tools BI, intended for advanced users mentioned above. However, the
evolution and improvement in performance of this entire suite of add-ons,
and the subsequent appearance of Power BI as an integrator of all of them
(Power Pivot analytical engine, Power View display engine, and Power
Query transformation engine) in a only product, they turn them not only into
software for information systems analysts but also very useful tools for the
developers of such systems.
The objective will be to approach the development of a Power BI model,
focusing mainly on the extraction, transformation, and loading (ETL)
operations that we will carry out through Power Query, but also paying
attention to the important volume of data that we can handle through this
application.
It is not about explaining Power Query in all its details but about making an
introduction to it and M, its programming language, addressing some of the
most common techniques in data processing, which serve the reader as an
initiation, at the same time as we observe the management capacity you have
working with datasets of several million records.
It is assumed that the reader has Power BI installed on your machine to
follow the examples described; however, in the following link, it is possible
to download the installer.

Population Register. The Source Data Source


As a source of the model that we are going to build, we will use imaginary
data on the imaginary population registered in the Register of inhabitants of
the Cities of a country.
The said registry is formed by the information related to the residents of the
populations that make up the national territory, sent by the different cities to
the authority, which offers an anonymous version of this information to the
citizens through the so-called microdata files.
Each of these files, available in the Statistics of the Continuous Register,
contains, in plain text format, information on the population registered in the
country on January 1 of each year, where each row of the file represents an
individual.
As we have just said, these data are adequately anonymized to comply with
the data protection regulations, and among them, we can obtain the place of
residence and birth by Province, city, and country, as well as the age, sex and
size of the city by the number of inhabitants.
Also complying with the requirements of the authority regarding the use of
these files, we must inform the reader that the degree of accuracy of the
information elaborated from these files does not depend on the INE, but in
this case, the processes and operations carried out with Power BI (Power
Query) as software used to perform its operation.
For the example that we are going to develop, we will use the file
corresponding to the statistics data as of January 1, 2016 (for example, 46
million records.)
Once we have accessed the download page, we will click on the “Go” button
to obtain the micro_2016.txt text file with the population data. We will also
click on the link Registration design and valid values of the variables, which
will provide us with the file Design and values of the variables of the
Census_2016.xlsx Microdata File, containing the guide of the population file
registration design, as well as the data to feed the search tables or catalogs
that we will use in the model: list of Provinces, municipalities, countries, etc.
From now on, we will refer to this file in an abbreviated form as an Excel
source or Excel source file. Due to space issues, both files are downloaded
compressed in zip format, and subsequent decompression is necessary.

Population File Record Design


As we have advanced previously, each row of the population file contains a
string of digits with the data of an individual. In the following example, we
see a random sample of one of these rows.
030141010021080840009
To extract each of the particles that identify the different properties of the
person, we will use as a guide the Design sheet of the source Excel file,
which shows us the meaning and positions that correspond to it within the
total string of digits.
Using these indications, the following figure shows a brief scheme of the
distribution of the values for the next process that we will implement with
Power Query, to segment them so that they make sense in the subsequent
modeling phase.

Data Import with Power BI


We finally arrived at the moment to start the fieldwork. First, we will run
Power BI and select the Get Data option from the External Data group, which
will show a list of the most common types of data sources, from which we
will choose Text / CSV.
Next, a dialog box will open in which we will navigate to the path in which
we have deposited the population data file micro_2016.txt. After selecting it,
Power BI will display a preview of its first rows.
Next, we will click on Edit, and with that, Power BI will give way to the
Power Query engine, represented by the query editor window or Query
Editor, which will contain a query with the data of the file that we just
incorporated.

Query Editor.
The Power Query Development Environment
Query Editor will be our main window of work throughout, and it is
recommended that we familiarize ourselves with the elements.
You want Container panel of the queries used in the data transformation
operations, which will later be used as a basis in the construction of the
model from the Power BI designers. The term Query (query) serves the
Query Editor to identify mainly tables, lists of values, or other types of
objects that store data in a structured way. The work to be developed in this
here will be focused mainly on the management of tables, so we will use both
terms, query, and table to refer to the same type of object: a structure of data
organized in rows and columns.
Data. This area shows the content of the query currently selected in the
Queries panel.
Applied Steps Each of the operations we carry out on a query represents a
step in the set of transformations performed, being registered with a name in
this block of the Query Settings panel. This allows us to place ourselves in
any of the steps to check the status of the query at that precise moment,
modify it, delete it, etc., as if it were a macro recorder.
Formula Bar. Expression in M language corresponding to the currently
selected step. If this element is not visible, we will activate it by checking the
Form Bar box of the Layout group on the View tab.
Operations menu It is an impressive toolbox where we will find all kinds of
debugging, cleaning, transformation, etc. We need to apply to the data. Let us
also keep in mind that if we do not find the solution we are looking for, the
possibility of entering our own code in M language is always available.

Modifying the Default Names


The file just imported generates a query called micro_2016, which contains a
column named Column1, both automatically assigned in the import
operation.
Although we can use these default names in the following transformation
tasks, we will change them to others that are more meaningful for the rest of
the operations to be performed, since Power Query assigns names to all the
elements of the transformation procedures that your engine needs have
identified. Therefore it is a good practice that in those on which we have to
perform some special manipulation, such as its use in a formula, we assign
custom descriptors.
In the case that currently concerns us, we will right-click both the name of the
query and the column, selecting the Rename option and modifying their
names respectively by PopulationCensus and Individual (by pressing F2, we
will also achieve the same result). PopulationCensus will represent the future
table of data of the model that we are going to develop.

Optimization of Data Load Times


At this point, we can update the work developed so far in the Query Editor
window on the Power BI data model by clicking on the Close & Apply menu
option, located in the Close group.
In our case, this operation may entail a significant process time penalty due to
the high volume of data contained in PopulationCensus, since by default, all
queries of the Query Editor are loaded into memory for later use in the data
model of Power BI
As an alternative to be able to work with the data without actually loading it,
we will right-click on the query and select the Properties option to open its
properties window. Once located in it, we will uncheck the Enable load to
report box and accept the changes; In this way, we maintain a reference to the
data in its location of origin without incorporating them until it is necessary,
thus reducing the process times. This article by Reza Rad on performance
issues in Power BI provides additional information about this particular.
After executing the Close & Apply option, the Query Editor window will
close, and we will return to the main Power BI window, where we will click
on the File | Save to save the work developed so far in a file that we will call
PopulationCensus.pbix.

Creation of Columns from the Source Data


Preparation of the Data Table
The next task that we will deal with will be the division into columns of the
identification data of each individual from the existing column in the
PopulationCensus table, following the guidelines of the Design sheet of the
source Excel file.
We will start with the Province's code of residence of the person, which
corresponds to the first two digits of the Individual column.
First, we will click on the header of the Individual column. Next, in the Add
Column menu tab, From the Text group, we will select the Extract option to
obtain a substring of the column, choosing Range as the type of extraction.
As a result of this action, a dialog box will be opened wherein the Starting
Index parameter we will enter 0. This parameter represents the index of the
position from which the extraction of the substring will begin. On the other
hand, in the Number of Characters parameter, we will enter 2 as the number
of characters to obtain.
Accepting this dialogue will create a new column with the Province's code of
residence of the individual, to which we will change the name to
ProvinceResidantID.
The reason for using 0 to indicate the starting position of the extraction is
because Power Query works with zero-based indexes, which means that the
index number or position of the first element is 0, the index of the second is 1
and so on. The following figure shows schematically the operation that we
just performed.
If, for example, we wanted to obtain, from the string in the previous figure, a
substring of 7 characters starting at position 12, the values to be used would
be 11 for the index of the extraction start, and 7 for the number of characters
to recover. Then we show the execution scheme for this operation again.
The function of the M language that internally executes the Extract-Range
menu option is Text.Range, whose use we will discuss in later examples. In
the following block of code, we see the extraction of the previous substrings,
but using this function just mentioned.
Text.Range ([Individual], 0.2)
Text.Range ([Individual], 12.7)
Taking into account the considerations that we have just explained, for those
operations related to the manipulation of character strings, it will be
necessary to subtract 1 from the positions of the string with which we need to
work, to make them coincide with the index that Power Query internally uses
in Text processing functions.

Value Column Based on a Condition


The municipality code of residence is the next column that we are going to
add to the table, finding its value located in positions 3, 4, and 5 of the
Individual column.
Additionally, we must bear in mind that for those municipalities with a
population of fewer than 10,000 inhabitants, this value is bleached (empty
chain) due to data protection issues. Since, as we will see later, the way to
identify a municipality is based on the union of Province codes plus
municipality, for cases where the latter is not available, we will use a code
that does not previously exist as 999, more appropriate in this circumstance
that an empty chain, since it will provide more consistency to the data in the
phase of creation of the post-transformation model that we are currently
carrying out with Power Query.
Reviewing in the Query Editor window the menu options of the Add Column
tab, we will notice the existence of the Conditional Column option, through
which we can create a column based on one or more conditions. However,
among the available operators, none allows us to extract a substring by
positions.

This leads us to look for the solution in the Custom Column option, also
located in the Add Column menu tab, which, as the name implies, enables the
creation of a custom column by entering an expression written in M
language.
if Text.Length (Text.Trim (Text.Range ([Individual], 2,3))) = 0 then
"999"
else
Text.Range ([Individual], 2,3)
In the previous block of code, we use the decision structure if… then… else
and functions belonging to the Text category to check if there is value in the
3-character substring that starts at index 2. Note that in a case like the current
one, where we perform several functions in a nested way, the order of
evaluation of the same begins with the one that is located in the innermost
position continuing outwards, as explained below.
First, we extract the substring using the Text.Range function, then we
eliminate the blank spaces that could be with the Text.Trim function, and
check the resulting length with the Text.Length function; if this is 0 (empty
string) it is one of the bleached municipalities, so we return the 999 string as
a result (the double-quote character is used as a string delimiter); otherwise, it
is a municipality with value, and we return the substring corresponding to its
code through Text.Range.

For the remaining columns to be created, we will continue to use the Custom
Column menu option, since in all cases, we will need to extract a substring
from the Individual column.
Attention to Upper and Lower Case in M
Now that we have begun to write M code, we must be cautious when creating
our expressions, due to the distinction between upper and lower case letters
that this language makes between its elements, such as reserved words,
function names, etc.
If for example, we try to create a new column with the following expression.
TEXT.Range ([Individual], 2, 3)
Having written the name of the TEXT function category in capital letters
instead of Text, which would be the correct form, we would get the error we
see in the following figure.

How do I find the most appropriate function for each moment? The answer is
inside
M is a language composed of functions, which organized into categories
(Table, Text, Number, List, etc.) offer a wide spectrum of possibilities for
handling tables, lists, character strings, etc.
But in the face of such an offer, we need some type of documentation to find
the one that best suits our requirements in each situation.
As resources on the Internet, we have the official Microsoft reference page,
from which we can download a document with the language specifications.
For the functions, there is also a page where they are grouped by category,
and we can also find many sites dedicated not only to Power Query, but also
to Power BI, Power Pivot and other Microsoft BI technologies, of which in
the end some featured links are provided.
However, all of the above resources are based on our availability of an
Internet connection, but what happens if, under certain circumstances, we
cannot connect to the Network?
This situation should not worry us since from the Power Query itself, and we
can access information about the functions of the M language through a small
trick.
First, we will create a new query using the New Source | Blank Query,
located in the Home menu, New Query group.
A new query with the default name Query1 will be created. In the formula
bar, we will write the following expression.
= #shared
After pressing Enter, a result set consisting of records (Record objects)
containing the language functions, as well as types, constant values, etc. will
be generated. To be able to handle this list more comfortably, we will click
on the Into Table menu option of the Convert group, belonging to the Record
Tools | Convert, to convert it into a table type query.
Once the table is obtained, we can find information about the functions by
applying a filter on the Name column. For example, if we want to see only
the functions of the Text category, we will click on the filter/order button of
that column, we will enter the Text value. (including the point to narrow the
search better), and we will click, OK.
As a result, the table will show the names of the filtered functions. We can
reopen this filter box and apply it for ascending order.
But if the aid remained only in a list of functions, this utility would be
impractical. We are going to look for in this list one of the functions that we
have previously used: Text.Range, and in the Value column, we will click but
not on the Function value but in an empty space within that box. A panel will
open at the bottom of the window with detailed information about the
selected function: signature (parameters and return with their corresponding
types), description of the operation performed, and examples of use.
If we click again, this time on the Function value, the information on the
function will be expanded, covering the entire window and opening the user
interaction dialog box so that we can evaluate its operation.

We can also use other filter variants, such as the search for functions that
contain a specific substring within their name. First of all, we will remove the
last steps created in the Applied Steps panel until we remain in Converted to
Table. Deleting a step is very simple, just select it and press Delete or click
on the delete icon next to its name.
Then we will open the filter box again, and in the Text Filters option, we will
select Contains, entering the ToText value in the filter box. After accepting
this dialog box, we will obtain it. As a result, all the functions whose name
contains the introduced particle.

Once we finish consulting the documentation using these techniques, we can


select the Query1 table in the Queries pane and delete it by pressing the
Delete key.

Column to Identify the Sex of the Individual


The digit located in position 6 of the Individual column identifies the sex of
the person, the value being 1 for men and 6 for women. We will transfer this
value to the new column SexID, where in addition to the Text.Range function
we will use Number to from text, to convert the result to a type of numerical
data.
Number.FromText (Text.Range ([Individual], 5.1))
Data Types in Power Query. Choose Between Any or a Specific Type
When creating the SexID column in the previous section, despite having used
the Number.FromText function to convert its content to a number, the data
type of the generated column is Any (any or generic type) instead of Whole
Number (number integer) as was our intention, which explicitly obliges us to
change the data type of the column by clicking on its name, and then, in the
Home menu, Transform group, Data Type option, select the Whole Number
value.
Whenever we are faced with a situation of these characteristics, in which
Power Query has assigned the default Any type to a column, but we know
what is the appropriate type of data that it should have, the recommendation
is that we change its type to which it really corresponds, so that operations
with it can be carried out with greater precision and reliability.
To quickly know the type of data that a column has, we will look at the icon
located on the left side of its title.
Another technique that we can also use to change the type of data is to click
on the icon in the column header and choose the new type in the list that
appears.
From here, in those operations that involve the creation of a column, we will
specify next to its name the type of data that should have

Place of Birth. Province


The next column, which will have the name Province BirthBirth (Text), is
obtained from positions 7 and 8 of the Individual column, and represents, as
its name indicates, the Province of birth of the person. For the population
born outside the country, value 66 will be used, and in the case of those born
in former American territories, code 53 is used.
ProvinceBirthID
=====================

Text.Range ([Individual], 6.2

Place of Birth. City or Country


The municipality or country of birth is obtained from positions 9, 10, and 11,
moving to the column CityPaisBirthID (Text). For people who were not born
in the country, the value will correspond to the code of the country of birth.
As was the case with the place of residence, in municipalities with fewer than
10,000 inhabitants, this value is bleached for data protection, so that for these
cases, we will use code 999.
Municipality Country Birth ID
=====================

if Text.Length (Text.Trim (Text.Range ([Individual], 8.3))) = 0 then


"999"
else
Text.Range ([Individual], 8.3)

Nationality
The nationality code data, which we will transfer to a column with the name
NationalityID (Text), is in positions 12, 13, and 14.
Nationality ID
=====================

Text.Range ([Individual], 11.3)

Age
The age of the individual will be transferred to a column called AgeID
(Whole Number) obtained from positions 15, 16, and 17.
Age ID
=====================

Text.Range ([Individual], 14,3)

Municipality Size According to Inhabitants


And we finish with the creation of the columns that indicate the size of the
municipality of residence and birth according to its number of inhabitants:
TamMunicipleResidantID (Text) and TamMunicipalBirthID (Text). Both
have a length of 2 digits and are respectively in positions 18 and 19 as well as
in 20 and 21.
For reasons of statistical confidentiality, in municipalities with less than
10,000 inhabitants, if for a Province, there is only one municipality in a
population section, it has been added to the next or previous section,
maintaining the code of the latter.
As was the case with the Province of birth, for column
TamMunicipalBirthID, in those people born abroad, code 66 is assigned,
while those born in former American territories are coded with the value 53.
The following code block shows the expressions to use to build these
columns.
TamMunicipalityResidenceID
======================
Text.Range ([Individual], 17,2)

TamMunnoverBirthID
=======================

Text.Range ([Individual], 19,2)

Composition of the Place of Residence Identifier


CityResidantID is not a column that can be used autonomously to select the
place of residence of the individual. The most palpable sample of this is in
the fact that if we review the CMUN sheet of the source Excel file, code 004,
for example, corresponds to municipalities in 5 different Provinces, so to
refer uniquely to one locality, we need both codes: Province and
municipality.
For this reason, we will create a new column called Resident Place (Text), in
which we will concatenate the values of ProvinceResidantID and
CityResidantID. This will allow us to later build a query with an identifier of
the same characteristics, which we will use as a search table when
implementing the data model in Power BI.
PlaceResidenceID
================

[ProvinceResidantID] & [MunicipalityResidantID]

Composition of the Birthplace Identifier


Suppose that in the phase of creating the data model, we want to design the
information of the place of birth as a hierarchy formed by the country,
Province, and municipality levels. One way to solve this problem would be
the creation, in the current table, of a new column that acts as an identifier,
which we will call Birth PlaceID (Text), formed by three different codes
corresponding to the levels just mentioned. The way to compose this
identifier will vary depending on whether the individual was born in the
country or abroad, data that we will find out by consulting the column
ProvinceBirthID.
If the value of ProvinceBirthID is 66, it is a foreigner, which means that the
column MunicipalityPaisBirthID contains the code of the country of birth
instead of a municipality. Of course, in this case, we lack the municipality
code, so we assign the value 999 to indicate that it is an unknown or
unavailable location.
[Municipality CountryBirthID] & [ProvinceBirthID] & "999"
If the value of ProvinceBirthID is not 66, we will begin to construct the
identifier with the value 101, which corresponds to the country code of USA,
for example, followed by ProvinceBirthID and CityPaisBirthID.
"108" & [ProvinceBirthID] & [MunicipalityPaisBirthID]
The entire expression to create the column is shown in the following block of
code.
if [Birth ProvinceID] = "66" then
// if he was born abroad
[Municipality CountryBirthID] & [ProvinceBirthID] & "999"
else
// if he was born in the USA
"108" & [ProvinceBirthID] & [MunicipalityPaisBirthID]
After the creation of CityBirthID, we will eliminate those other columns used
as support in the preparation of this table, which we will not need to use from
now on for the development of the data model. The columns in question will
be: Individual, ProvinceResidantID, CityResidantID, ProvinceBirthID and
CityCountryBirthID.
Next, we will execute the Close & Apply menu option again in the Query
Editor, and in the Power BI window, we will save the changes in the .pbix
file.
At this point we conclude this chapter in which we have made an introduction
to Power BI from an ETL tool perspective, making use of the data
transformation operations belonging to the Power Query engine integrated in
this tool, with the aim of put together the data table for a model that we will
build with Power BI designers.
In the next chapter, we will continue with the development of this
information system, addressing the creation, also with the Query Editor, of
the search tables, which once related to the data table, allow users to perform
their analysis tasks through the application of filters and the creation of
metrics.
Chapter Six:
Data Model Using Power Query

In the last chapter on the development of an information system based on the


Population Register, we explained the steps to follow to create the data table
of an analysis model using the Power Query tools (language M) integrated
with Power BI. The next stage in the development of this model is to create
the lookup tables, a task for which we will also use the Query Editor. The
source Excel file described in the previous delivery will be this time the
primary source of data for the new tables that we will study in this chapter.
Once these search tables have been created, we will have all the elements to
build the analytical model: relationships, measures, reports, dashboards, etc.
through the designers of Power BI, this aspect will be addressed in an
upcoming chapter.

Nationality. Import from Excel


We will start by importing the data located on the NACI sheet of the source
Excel file, which corresponds to the nationality of the individual. From the
main Power BI window, in the Home menu tab, External data group, Get
Data | Excel, we will select the source Excel file.
Next, the Navigator window will offer us the possibility of choosing one or
several sheets of this file. After selecting NACI, we will click on Edit, thus
passing the data of the sheet as a new query to the Queries pane of the Query
Editor window.

Nationality. Set Column Headings from the First Row of the Query
After changing the name of the query for Nationality in the Queries panel, we
have to replace the current column titles (Column1 and Column2) with names
that adequately describe their content.
One possibility is to reuse existing names in the Excel sheet from which we
have imported this data. These names are currently in the third row of the
table, so we will remove the first two rows (which do not contain valid
information) using the menu option Remove Rows | Remove Top Rows, from
the Reduce Rows group, Home tab, which will show a dialog box in which
we will enter the number of rows to delete.
As a next step, we will transfer the values of the first row of the table to the
column titles, using the Use First Row as Headers option, of the Transform
group, Home menu tab.
We have explained this technique of assigning names to the headings of a
table simply for demonstration purposes so that the reader knows the
existence of this possibility. However, we will not reuse the column titles of
the source Excel file, but we will assign new names explicitly; so in this
table, we will change the names of the columns by NationalityID (Text) and
Nationality (Text), by right-clicking on each title and selecting the Rename
option.
This table also contains a significant amount of empty records at the end,
which we will delete using the menu option. Remove Rows | Remove Blank
Rows, from the Reduce Rows group, Home tab.

Creating the Sex Table from Dynamic Records


In the steps carried out to build the PopulationCensus table, we saw that the
values used to identify the sex of the individual are 1 for men and 6 for
women, so the base query for the search table of these data, being very
simple, we will create it dynamically through an expression in M language.
First, we will select the menu option New Source | Blank Query, from the
New Query group, Home tab, to create an empty query in which we will
write the following block of code.
= Table.FromRecords (
{
[SexID = 1, Sex = "Man"],
[SexID = 6, Sex = "Woman"]
}
)
Let us analyze each of the parts of the previous expression: first, to define a
record in M, we must enclose in square brackets the field names that
compose it next to their values, using the format shown in the following
figure.
Next, the records that will be part of the table will be included, separated by
commas, in a list (List object). The key characters are those used in M to
define a list of elements.
Finally, we will use the FromRecords function of the Table category, to
which we will pass as a parameter the list we just created, obtaining a table as
a result.
Once the table is created, we will change its default name to Sex; for the
SexID and Sex columns, we will assign as data type Whole Number and
Text, respectively.

Place of Residence. Query Combination (Merge Queries)


During the creation stage from the data table, we explained that the residence
of the individual is established from the combination of the province and
municipality codes; These values are found in the CPRO and CMUN sheets
of the Excel source, so to assemble the table of the place of residence we will
first have to import these sheets into Power Query, just as we did before with
the nationality table, changing the name of the CPRO table by
ProvinceResidence, and the columns CPRO and Province of Residence by
ProvinceResidenceID (Text) and ProvinceResidence (Text). Regarding the
CMUN table, we will do the same name change operation for
MunicipalityResidence, and the columns CPRO, CMUN, and NAME for
ProvinceResidenceID (Text), MunicipalityResidenceID (Text) and
MunicipalityResidence (Text).
Next, in the Queries panel, we will click on ProvinceResidence, and we will
delete the first three rows with the menu option Remove Rows | Remove Top
Rows. For the MunicipalityResidence query, we will delete the first five
rows.
Reviewing the contents of these tables, we will appreciate that in
MunicipalityResidence we have almost everything necessary; at the moment
a column with the name of the province is missing, an issue that we will
solve by crossing with ProvinceResidence, to transfer the data of the column
of the same name.
The first requirement for a crossing of these characteristics is to be positioned
in the table to which we are going to add data, so in the Queries panel we will
click on MunicipalityResidence, and then we will select the Merge Queries
menu option, from the Combine group, on the Home tab.

Then the Merge window will open, which in its upper part shows the origin
table of the crossing: MunicipalityResidence. We will also have to select the
ProvinceResidence table at the bottom, and in both the crossing and union
field, which has the same name in the two tables: ProvinceResidenceID. The
type of crossing or Join Kind, which in this case is Left Outer, indicates that
for the operation, all the rows of the first table, MunicipalityResidence, and
those rows of the second, ProvinceResidence, in which there is a match will
be used. The last element of this window is an informational message with
the number of rows between which there has been a match, and which in this
example has been for all rows.
The consequence of this union operation when accepting the Merge window
will be the aggregation, in the MunicipalityResidence table, of an additional
column with the name NewColumn, containing the value Table in its cells. If
we click on an empty area of any of these cells, the record obtained from the
ProvinceResidence table, the result of the crossing operation, will be
displayed at the bottom of the data area.
However, we have not yet transferred any data between the tables. Now that
we have established a relationship between them thanks to the Merge Queries
option, we must select what data from the ProvinceResidence table we want
to take to MunicipalityResidence; what we will achieve by clicking on the
icon next to the header of the NewColumn column, selecting the Expand
option (default) and checking only the box in the ProvinceResidence
column.
When you click OK, the selected action (Expand) expands the
ProvinceResidence table to which each cell in the NewColumn column
points, and as a result, brings the MunicipalityResidence a column with the
name NewColumn.ProvinceResidence containing the names of the provinces.
After changing the name of the new column to ProvinceResidence, we will
move its position until it is located next to ProvinceResidenceID. We will use
the Move | Left, from the Any Column group, on the Transform menu tab.
We will have to execute this option a couple of times until the column is
placed in the desired position.
Place of residence. Creation of the code for bleached municipalities and
union of consultations
When generating the code of the place of residence in the PopulationCensus
table, we saw that for the municipalities with less than 10,000 inhabitants, the
municipality code is not provided due to data protection issues. This had led
us to decide to use the code 999 for such cases, which means that, for
example, for province 08 (Barcelona), the code of the place of residence will
be 08999.
The MunicipalityResidence table that we have just created would currently
lack all this set of records that we do know about the province, but we do not
know the municipality, and that is necessary for the measures that we are
going to implement in the modeling phase to correctly perform their
calculations. Then we explain a technique that will help us solve this
problem.
In the ProvinceResidence table, we will add two new columns:
MunicipalityResidenceID (Text) and MunicipalityResidence (Text),
containing respectively the code 999 and the literal Not available.
Next, we will position ourselves in the MunicipalityResidence table and
select the Append Queries menu option, from the Combine group, Home tab.
In the Append window, we will select the ProvinceResidence table, and when
you click OK, the records of the latter will be added to
MunicipalityResidence, completing the code combinations necessary for this
table.

Place of Residence. Column for the Table Identifier


We will finish the creation of this table by adding a new column that
represents its identifier, to which we will give the name PlaceResidenceID
(Text), composed of the union of the columns ProvinceResidenceID and
MunicipalityResidenceID.
Once created, we will place this column in the first position of the table using
the menu option Move | To Beginning, from the Any Column group, on the
Transform tab.

Age. Creation of Numerical Intervals Using Lists


The table with the age of the individuals will contain the values in the range
of 0 to 99 years; for those with 100 years or more, the value 999 will be used
for data protection reasons.
The M language allows us to generate a sequence of numbers using the
Numbers function of the List category, passing as parameters the initial value
and the number of numbers to be created.
= List.Numbers (0,100)
However, this is not enough, since we also have to add the number 999 to
these values. To solve this problem, we will use the Combine function, also
of the List category, which receives as a parameter an object of type List
containing a combination of lists this function will return as a single list.
In this way, in addition to the list with the range 0-99, we will create another
composed only by the number 999, which we will also pass to combine.
= List.Combine (
{
List.Numbers (0,100),
{999}
}
)
The previous block of code will be included in a new empty query (New
Source | Blank Query menu option, from the New Query group, Home tab),
which will create a unique list by adding it to the Queries panel.
In the next step, we will convert the list into a table with the To Table menu
option, from the Convert group, located on the List Tools | Transform.
In the To Table window that opens next, we will accept the default values.
Once the table is created, we will change its name to Age and the name of the
column to AgeID (Whole Number). Next, we will add a new column with the
name Age (Text) from the values of AgeID, but converted to character, using
the following expression.
Number.text ([AgeID])
An aspect widely used in work with demographic data consists of analyzing
the population's age in ten-year, five-year, or other range intervals. For this
example we will define the following intervals: 0, 1-4, 5-14, 15-24, 25-34,
35-44, 45-54, 55-64, 65-74, 75-84, 85 and more years.
The way to implement these intervals in the age table will be through the
incorporation of a new column, which we will call Decennial Age (Text), in
which we will include the following block of code, where based on the
interval in which the age is placed, We will assign the corresponding literal.
if [AgeID] = 0 then
"0"
else
if [AgeID]> = 1 and [AgeID] <= 4 then
"1-4"
else
if [AgeID]> = 5 and [AgeID] <= 14 then
"5-14"
else
if [AgeID]> = 15 and [AgeID] <= 24 then
"15-24"
else
if [AgeID]> = 25 and [AgeID] <= 34 then
"25-34"
else
if [AgeID]> = 35 and [AgeID] <= 44 then
"35-44"
else
if [AgeID]> = 45 and [AgeID] <= 54 then
"45-54"
else
if [AgeID]> = 55 and [AgeID] <= 64 then
"55-64"
else
if [AgeID]> = 65 and [AgeID] <= 74 then
"65-74"
else
if [AgeID]> = 75 and [AgeID] <= 84 then
"75-84"
else
if [AgeID]> = 85 then
"85+"
else
""

Size of the Municipality of Residence


Our next operation will be to create the table with which we can classify
individuals according to the size by inhabitants of the municipality in which
they reside.
To do this, we will import the TAMU sheet from the source Excel file. Once
the data has been incorporated into Power Query, we will remove the last
column of the table, which is empty, using the menu option Remove
Columns, from the Manage Columns group, Home tab.

Next, we will change the name of the table to TamMunicipalityResidence,


and the column names to TamMunicipalityResidenceID (Text) and
TamMunicipalityResidenceOrigin (Text), eliminating the first three and last
four rows using the Remove Top Rows and Remove Bottom Rows
suboptions respectively, depending on the Remove Rows menu option.
Since the objective of this table will be to inform whether the municipality is
Provincial capital, and otherwise, the range of inhabitants it has, the
descriptors obtained from the Excel file may be excessively long and
repetitive. For this reason, we will try to summarize them, so that we simply
show the literal “Province Capital” when it is a Provincial capital city or the
range of inhabitants in the rest of the cases.
We will create a new column with the name TamMunicipleResidence (Text)
using the following block of code.
if Text.Contains ([TamMunicipleResidenceOrigen], "province") then
"Province capital."
else
if Text.Contains ([TamMunicipalResidenceOrigin], "hasta")
then
"Up to 100."
else
if Text.Contains ([TamMunicipalResidenceOrigin], "de")
then
Text.RemoveRange ([TamMunicipleResidenceOrigin],
0,24)
else
Text.RemoveRange ([TamMunicipleResidenceOrigin], 0.21)
The technique used in the previous code is to check the value of the
TamMunicipalityResidenceOrigin column using the Text.It contains a
function, which returns true or false, depending on whether or not, within the
text passed as the first parameter, the character string of the second
parameter. In cases where the word "province" exists, we will know that it is
a Provincial capital city and we will return the literal "Province Capital"; If it
contains the word "up to" it will be a municipality with a maximum of 100
inhabitants, and we will return "Up to 100".
For the rest of the occurrences, we are only interested in taking the text
fragment that indicates the range of inhabitants, eliminating the rest with the
Text.RemoveRange function, which is responsible for eliminating, in the text
of the first parameter, a substring whose start index we indicate in the second
parameter, while its length is specified in the third parameter. In these values,
the amount of text to be deleted will depend on the existence of the "de"
particle in the value of the column.
Regarding the size by inhabitants of the municipality of birth (sheet ALSO of
the Excel source file), the creation of your query is equal to the process just
described, so we will avoid repeating it here.

Place of Birth. Data Distribution by Country, Province, and Municipality


As we had explained in the previous chapter, the table with the information
of the place of birth that we will build next will have a structure that will
allow us, during the design of the data model, to create a hierarchy based on
the levels of country, province, and municipality.
First, we will import the CPRON and CMUNN sheets from the source Excel
file, which in the Queries panel, we will change their name to Province of
Birth and Municipality of Country of Birth, respectively.
Placing ourselves in the Province of Birth table, we will rename its columns
by Province Birth Birth (Text) and Birth Province (Text); then, we will delete
the first three rows.
Then we will position ourselves in the MunicipalityCountryBirth table, where
we will remove its empty columns, and then, from the Queries panel, we will
right-click on this same table, selecting the Duplicate option. We will change
the name to the new duplicate table by Country.
We will deal with this table a little later, now we will return to
MunicipalityCountryBirth, and first, we will delete the last three columns,
corresponding to the country data, using the Remove Columns menu option
Continuing with the delete operations, then we will use the menu sub-options
dependent on Remove Rows to delete the first eight rows, as well as those
rows with null values. We will also change the default names of the columns
to ProvinceBirthID (Text), MunicipalityBirthID (Text), and
MunicipalityBirth (Text).

Place of Birth. Completing Provinces Information


As it happened during the preparation of the table of the municipality of
residence, the MunicipalityCountryBirth table has the province code but not
the names, so we will make a combination (Merge Queries menu option) with
the ProvinceBirth table, to transfer from this Last column with the province
names to the table of municipalities. We will not repeat the steps on how to
make a combination of tables since this operation was described earlier
during the preparation of the tables relating to the place of residence. Once
the crossing is finished, and the positions of the columns are organized.
As indicated in the source Excel file, information on births in municipalities
with less than 10,000 inhabitants is bleached for data protection, which
means that for these cases, we will know the province of birth but not the
municipality. The technique that we will use to incorporate these data in the
MunicipalityCountryBirth table will be the same as that previously used for
the MunicipalityResidence table.
First, we will add two new columns to the ProvinceBirth table:
MunicipalityBirthID (Text) and MunicipalityBirth (Text), containing
respectively the values 999 and Not available.
Then, using the Append Queries menu option, we will add to the
MunicipalityCountry table the content of the ProvinceBirth table. As a result,
MunicipalityCountryBirth will now contain all possible combinations of
province and municipality, including those of bleached municipalities (not
available) because they have a population of fewer than 10,000 inhabitants.

Place of Birth. Completing Country Information


The next step will be to create two new columns: CountryBirthID (Text) and
CountryBirth (Text), to host the country data. Currently, the table only has
information on provinces and municipalities in the USA, so the values of the
two new columns will be country code 108 (see the reader for the Nationality
table) and the literal USA, respectively. After rearranging the columns in a
more logical order (country - province - municipality).
Now it is necessary to add the data of the rest of the countries, so we will
place ourselves in the CountryBirth table to prepare its structure and contents
so that we can combine it with MunicipalityCountryBirth.
The columns of the CountryBirth table that we need to work with are the last
3, which correspond to the province code 66, indicative of being born abroad,
as well as the country code and name.
As an alternative way to delete columns, we will select the columns that
contain the data we need, and we will execute the Remove Columns |
Remove Other Columns from the Manage Columns group, Home menu tab;
thus deleting the columns of the table that we had not selected.
This table contains a large number of empty records (null, blank, etc.) that we
will delete with the Remove Rows | Remove Blank Rows, used on other
occasions throughout for similar situations. After this deletion, we will also
delete the first two rows, to keep only the data of the countries.
The next step will be to change the name of the columns by Province Birth
Birth (Text), Country Birth ID (Text), and Country Birth (Text).
Now we must match the structure of this table with the
MunicipalityCountryBirth table, adding the columns ProvinceBirth (Text),
MunicipalityBirthID (Text), and MunicipalityBirth (Text). Since the
CountryBirth table contains only the data for the population born abroad, we
do not have, of course, data on province or municipality, so we will assign
values to these new columns according to this situation: 999 for
NacimientoID Municipality and the literal Not available for ProvinceBirth
and MunicipalityBirth.
Next, we will add the records of this table to MunicipalityCountryBirth
through the menu option Append Queries, obtaining. As a result of all
combinations of codes that will allow us to locate the population
geographically.

Place of Birth. Deletion (filter) of Invalid Rows


After adding this data, we need to remove from the MunicipalityCountryBirth
table the row that contains the foreign value in the ProvinceBirth field, since
it corresponds to a non-existent case in the PopulationCensus data table:
individual born in the country but classified as a foreigner by province.
The operation that we are going to carry out to achieve this objective will not
consist, however, in the deletion of a row, but we will apply a filter on the
table, which excludes the record in question; for what we will click on the
filtering icon in the Birth Province column, selecting the Text Filters | Does
Not Equal. In the Filter Rows window shown below, we will enter the foreign
value and accept; this will apply the filter, excluding said row from the rest of
the rows of the MunicipalityCityBirth table.

Place of Birth. Column Creation with a Table Identifier


As the last task, we will add a column that will act as the identifier of the
table, which we will call Birth PlaceID (Text). This column will be formed
by the concatenation of the CountryBirthID, ProvinceBirthID, and
MunicipalityBirthID columns; Once created, we will place it as the first
column of the table.
[CountryBirthID] & [ProvinceBirthID] & [MunicipalityBirthID]

Disable Loading Auxiliary Tables


At this point, we can conclude the process of creating the tables that will be
part of the data model. However, we will not need to use in the modeling
process all the tables that the Query Editor currently contains, so we will
disable their loading to achieve a cleaner design of the model and optimize
the processing of your data.
Located in the Queries panel, to disable the loading of a table, we will right-
click on it, unchecking the Enable load option box. The tables on which we
will carry out this operation are ProvinceResidence, ProvinceBirth, and
CountryBirth.
On the other hand, we will re-enable data loading for the PopulationCensus
table, since we had previously disabled it during the preparation phase of the
model search tables, also for performance reasons.
In this and the previous chapter, we have addressed the creation of the search
tables or lookup tables of an analysis system built using Power Query ETL
tools integrated into Power BI. In the next chapter, we will discuss those
aspects of the information system that concern the design of the data model:
relationships between tables, creation of hierarchies, measures, etc., as a
previous step to the visual representation of the information contained in the
system.
Chapter Seven:

Power Pivot Engine To Design


A Population Data Model

In the past two chapters ( chapter 5 - chapter 6 ), Query Editor was the Power
BI tool that completely occupied our attention, showing us how to build the
tables of a model from the functionalities of extraction, transformation, and
load (ETL) that it has.
Once the creation of the tables is finished, in this section we will continue our
task of developing the data model, using on this occasion the Power BI
designers most directly related to the Power Pivot engine: Data and
Relationships, responsible for the development of measures, hierarchies and
relationships between the tables of the model. We will also pass briefly
through the Designer Report, just to check the values of the measurements
generated in the data table.

Data Designer Introduction


Finished the work of preparing tables from the Query Editor we will place in
the Data designer, which among other operations, we will use to create the
measures of the model through expressions written in DAX, the query
language of the Power Pivot engine integrated in Power BI, as well as to
format the values of the columns and create hierarchies in the tables.
The following figure shows an overview of this designer, with a central area
dedicated to the display of the selected table in the Fields pane on the right,
and the main work options in the Modeling menu tab.

Data Designer Population Count Measure


As we have already indicated, from this designer we will create the main
measure of the model, to which we will give the name of Total Population (to
simplify, we will avoid the use of tilde and other special characters in the
names of the measures), and whose objective will be to make a count of the
individuals that make up the Register of inhabitants that we are analyzing.
To do this, we will select the PopulationCensus table and click on the New
Measure menu option, from the Calculations group, Modeling tab, which will
position us in the formula bar of the table, where we will write the following
DAX expression.
Total Population = COUNTROWS (PopulationCensus)
As we have already guessed, in the previous expression, the COUNTROWS
function is responsible for counting the rows of the PopulationCensus table
that we pass as a parameter, to obtain the total number of inhabitants.
Then we will format the measure by adding a thousand separator characters,
which we will select in the Modeling menu tab, Formatting group, Thousands
separator option.

Report Designer Elementary Operations in the Use of Controls


To check the operation of the measure that we have just created, we will
move to the Designer Report, whose purpose is to build a graphic
representation of the information in the data model, through the visual objects
contained in its palette of controls.
As a general rule, the steps used to add a control with a minimum of
functionality to the Report designer are basically the following:
1) Select the control in the palette of the Visualizations panel.
2) The previous action places a copy of the control in the design area.
3) Select from the fields of the Fields panel the measure (s) that we want
to represent graphically, and place it in the properties of the Fields
section of the control.
4) Depending on the power and visual richness of the control, use some
of the properties of the Format section to improve its appearance.

Report Designer Results Display


In this first approach to the Power BI report designer, we are not going to
create a very complex or elaborate presentation, and we just need to verify
that the data table count is correct through visual control.
For the demonstration, we will use the Card control, whose operation consists
of a simple visualization of the value of a measurement.

Once the control is selected in the Visualizations panel, we will click on the
PopulationCensus table of the Fields panel to display its elements (fields,
measurements, hierarchies) and check the box of the Total Population
measure, which will automatically go to the Fields property of the control,
belonging to the section of the same name, within the Visualizations panel.
As a result, the control will display the measurement value using an
abbreviated numerical format.
To show the value of the measurement with the complete number format, we
will click on the Format section of the Visualizations pane, and within the
Data label section, we will change the value of the Display units property
from Auto to None.

Measurement Control Test


To ensure that the number of individuals is correct, we will return to the
Query Editor by clicking on the Edit Queries menu option, External data
group, Home tab. Once there, in the PopulationCensus table, we will select
the Count Rows menu option, from the Table group, Transform tab, which
will also count the records in the table, returning the same value (without
formatting) as the measurement used in the Report designer.
Once this verification is finished, we will delete the counting operation from
the Applied Steps list in the Query Settings panel, and close the Query Editor
window, applying the changes to return to the report designer.

Tables Need Relationships


The fact that the previous rapid test of verification of the value of the measure
has given the expected value does not mean, at all, that the model preparation
work has been completed. As evidence of this, if we add a control to the
designer of the Report panel, in which in addition to the Total Population
measure, fields from any other table of the model intervene, the results will
not be as desired.
As an example, we are going to add a new page to the pbix file we are
working with, by clicking on the New Page button at the bottom of the Power
BI window. On this page, we will add a Stacked column chart control, to
measure the number of inhabitants per age group, showing the representation
of each section in a column. Once the control is placed in the design zone, we
will select the Total Population measure, which will be assigned to the Value
property of the Fields section. In the Age table, we will choose the Decennial
Age field, which will be assigned to the Axis property; As a result, the
control should show the columns corresponding to each age range with
different sizes, thus reflecting the number of existing people by range.
However, this is not the behavior obtained, since the control shows all the
columns with the same size, without correctly reflecting the population for
each age group, which is a symptom of some type of lack in the model
configuration sections.
The origin of this problem lies in the lack of relationships between the data
table and the model search since without a relationship between the
Population and Age tables, the Power Pivot engine does not know the amount
of population that should be assigned to each age group, and therefore, the
control is not drawn correctly.

Relationships Designer. Relationship Creation


To solve the problem posed in the previous section, we will locate ourselves
in the Relationships designer, who, as indicated by his name, has the purpose
of establishing the relationships between both types of table of the model:
data and search, so that the visual representation of the data from a Power BI
report, correctly reflect the information that you want to transmit to the user.
Within the work area of this designer, we see an outline of the tables that
make up the data model. If, due to their quantity, they were not all insight, we
can adjust their size by clicking on the Fit to screen button or the Zoom
controls, located at the bottom.
We can also drag the tables to place them more properly, according to the
relationships we need to create.
Next, we will proceed to create the relationship between PopulationCensus
and Age, for which we will select the column AgeID in the PopulationCensus
table, and drag it to the column of the same name in the Age table,
establishing the relationship with a cardinality of many to one.
If we double click on the line that represents the relationship, the Edit
relationship window will open, through which we can see its characteristics.
Upon returning to the Report Designer, the Stacked column chart control will
now reflect the information properly, although the order of the age ranges
will not be totally correct, which we will solve in the next installment
dedicated to the development of reports with the Designer Report.
The list will show the rest of the relationships that we must establish between
the PopulationCensus table and the other tables, so that the controls that we
incorporate into our reports, dashboards, etc., adequately show the
calculations of the model metrics.
Alternatively, we can also manage the model relationships from the Manage
Relationships window, accessible from the menu option of the same name,
located on the Home tab, Relationships group.

Data Designer Hierarchy Creation


A hierarchy is an element, which, once defined in a table of the model, will
allow us to analyze its information through levels, which represent various
categories of related data within that table. As an example, we will create a
hierarchy based on the MunicipalityCountryBirth table, which will consist of
three levels: country, province, and municipality.
In the first place, we will place ourselves in the Data designer, and in the
Fields panel, we will display the list of fields of the
MunicipalityCountryBirth table. Then we will right-click on the Country
Birth field, choosing the New hierarchy option.
This action will create a hierarchy with the default name Country Hierarchy.
As a next step, we will successively drag the ProvinceBirth and
MunicipalityBirth fields until they are released within the name of the
hierarchy, now being composed of the three levels mentioned above.
Finally, we will change the name of both the hierarchy
(CountryProvinceMunicipality) and its levels (Country, Province, and
Municipality), by right-clicking on each element and choosing the Rename
option.

Demographic Structure Indicators


In addition to the measurements performed by the count of individuals, the
demographic analysis employs a series of additional indicators, whose
purpose is to reflect the distribution of the population through the variables of
sex and age; they are called Demographic Structure Indicators.
Starting from three large age groups, with intervals 0-14, 15-64 and 65+ (65
years and over), the structure indicators measure aspects such as the
proportion of a certain group over the total population; the relationship of the
groups of elderly or young people with respect to adults; and the reason
between old and young.
The demographic change processes experienced in certain populations (low
fertility, high life expectancy, etc.) have caused that, in addition to the
traditional grouping indicated in the previous paragraph, some organizations
such as Eurostat use a second grouping based on intervals 0- 19, 20-59 and
60+ (60 and older). The following figure shows these two types of age
groups.
Demographic Structure Indicators
We will begin by creating the three measures that represent the number of
inhabitants for each age group (young, adults and older). As we did
previously with the Total Population measurement, we will return to the
PopulationCensus table of the Fields pane, and select the New Measure menu
option, to create the measures Young Population, Adult Population and
Major Population, whose source code we see below.
Youth Population = CALCULATE (
[Total population],
Age [AgeID]> = 0 && Age [AgeID] <= 14
)

Adult Population = CALCULATE (


[Total population],
Age [AgeID]> = 15 && Age [AgeID] <= 64
)

Major Population = CALCULATE (


[Total population],
Age [AgeID]> = 65
)
The CALCULATE function, used to create these measures, evaluates the last
expression as the first parameter (Total Population measurement of the
PopulationCensus table) by modifying its original evaluation context by
using filter expressions (selection of intervals on the AgeID column of the
Age table with DAX operators ) located in the second and subsequent
parameters.
Following the recommendation of the reference sheet available in
PowerPivotPro, when writing the code of a measure within which we have to
refer to another previously created measure, for that existing measure, we
will only use its name without first putting the name of the table.
To check the values that we have just created, we will return to the Report
Designer, and on a new page, we will add a Multi-row card control, which
will facilitate the simultaneous visualization of several measures by including
them in their Fields property.
Demographic Structure Indicators. Proportions over the Total Population
This type of indicator calculates the percentage that represents each age
group (youth, adults, and the elderly) with respect to the total population, so
we will have to create three measures, one for each group. To obtain it, we
will use the DIVIDE function, as we see in the following block of code,
where the measure of the corresponding population group acts as the
numerator and the total population as the denominator.
Young Proportion = DIVIDE ([Young Population], [Total
Population])
ProportionAdultos = DIVIDE ([Adult Population], [Total
Population])
Major Proportion = DIVIDE ([Major Population], [Total Population])
Additionally, we will format each of these measures as a percentage with two
decimals.
And we will also use a Multi-row card control to visualize its values.
Demographic structure indicators. Dependency Indices
These are indicators that establish a relationship between the groups of young
and / or older population (numerator) with respect to the adult group
(denominator), so we will use the following expressions to calculate them.
Youth Dependency Index = DIVIDE ([Youth Population], [Adult
Population])
Major Dependency Index = DIVIDE ([Major Population], [Adult
Population])

Demographic Structure Indicators. Aging Rates


And we finish the calculation of indicators with this measure, which allows
us to observe the aging process of the population through the ratio between
the population of elderly and young people using the following formula.
Aging Index =
DIVIDE ([Older Population], [Young People])
And with the creation of demographic indicators, we finalize this chapter, in
which we have shown the role that Data and Relationships designers play in
the process of developing an information system with Power BI, specifically
in the section on creating the model of data, through the elaboration of the
metrics, relationships, and hierarchies.
Conclusion

In the past, companies were stuck with tables, spreadsheets, and static charts.
Today, the use of joint and connector tools makes it possible to use and
generate data more intelligently. Flexibility and personalization of data
storage allow you to analyze and guide decisions in companies and
corporations.
Data pinned to offline spreadsheets does not allow correct and fast sharing.
We know that business data and information has increased. On the other
hand, the speed at which companies need to make decisions also increases.
Using the right tools for the data processing task increases the speed for
processing, manipulation, and understanding. Saving time is one of the main
benefits. Regardless of the area of business, corporations and new businesses
need to adopt more dynamic and powerful analytics tools.
Large, medium and small businesses must choose this path urgently.
Information cannot be lost and the company cannot waste time. Microsoft's
Power Bi program is critical to new endeavors.
All the best companies want to download and use this tool that connects and
expands access for the workforce. The tool has four elements and enables you
to turn a huge amount of data into optimized views.
This information can be absorbed and understood in moments. Being
dynamic, they adapt to any need, which improves the decision-making
process. The company will change its organizational and administrative
culture. We can say that this tool is the present and future of enterprise data
organization, allowing to overcome the old difficulties of the past.
Some companies may not see an advantage in being Microsoft, a very
traditional brand that has already launched outdated services like MSN and
Outlook, but the company has adopted a policy of launching more specific
products for different situations.
The company is updating itself in the market and strives to make significant
changes never before seen in the company. Following the launch of
innovative products, Power Bi is part of this new trend. The company
listened to end-users, and they identified what they thought was best and did
not develop the program based solely on what they understood.
We know the company is a leader in operating systems, personal and
corporate program development. After all, who has never used Office?
Despite its large portfolio, and being a superpower, the company needed to
innovate in other sectors, such as management and information management.
Although new, Power Bi is inherited from SQL Server Analysis Services.
The SSAS team developed the foundation for the new software from Power
Pivot (the data modeling engine), one of Excel's first extensions. Most current
Microsoft software can integrate with this joint tool depending on the skill of
the user.
In this book, we seek to present the main features and applications of the
functions of this tool that has grown a lot in the data and information
management market. Data sharing and simplicity are the best reasons for
companies to invest in this tool that makes it possible to optimize data and
Excel connections.
Today, companies are looking for time savings, flexibility, and real-time data
refresh as a way to unify the efforts of businesses and corporations. It is
worth researching, installing, and studying this tool and its four interface and
application elements.
References

https://powerbi.microsoft.com/en-us/blog/
https://exceleratorbi.com.au/blog/
https://datachant.com/
https://www.academia.edu/36243555/Analyzing_Data_with_Power_BI.pdf
https://www.powerpivotpro.com/wp-
content/uploads/2015/10/PowerPivotPro-Reference-Card.pdf
https://yodalearning.com/tutorials/power-bi-dax-basics-power-bi-dax-
function-list/
http://www.powerpivot-info.com/public_files/cheat-sheet/powerpivot-dax-
functions-long.pdf
http://projanco.com/Library/The%20Definitive%20Guide%20to%20DAX-
Business%20intelligence%20with%20Microsoft%20Excel,%20SQL%20Server%20Analy
Power BI

Simple and Effective Strategies to Learn the


Functions of Power BI and Power Query

DANIEL JONES
Power BI:
A Disruptive Reporting Platform

Introduction to Power BI
Power BI is a cloud-based analytics service that provides a unified view of
the mission-critical business data. It’s Software as a Service (SaaS) offered
by Microsoft in the reporting and visualization domain. It offers three basics
components, which are:
Power BI ( Online Service)
Power BI Desktop
Power BI Mobile

Here you will see the basics of Power BI and a critical feature termed as
Natural Language Query. Before you understand each of these components
separately, let’s have a look at the Architecture of Power BI. The architecture
will explain how Power BI components are related to each other. If not, I am
here to throw more light on it. Let’s understand the sequence as:
Create Reports using Power BI Desktop (On-Premise): Power
BI desktop is a report authoring and designing tool that can be
installed on your machine. You can use this tool to connect to
more than 60 data sources and create a data model for further
creating your reports.
Publish Reports to Power BI online service (On-Cloud): Once
you create the reports, you need to show it to the world. But
how? That’s where the Power BI online service comes into the
picture. The reports created using Power BI desktop can be
published to Power BI online ( https://powerbi.microsft.com ).
For publishing the reports, you need to sign in to the online
service using your official ID only.
Consumer Reports on various devices: Once published, the
reports can be shared with the world. The shared reports can be
viewed on desktop browsers and even through the Power BI
Mobile App.

Now, you have a fair idea about the Power BI architecture. Let us explore the
three Power BI components separately.

Power BI Online Service


Power BI helps you to stay informed about the progress of your business and
keep you up to date with the business-critical information. With Power BI
dashboards, you can keep an eye on the health of your business. The
dashboards display the tiles that you can click to view the detailed reports
for exploring more details. You can connect to multiple datasets to bring all
the necessary data together in one place.
Did you notice the highlighted keywords in the above section? Yes, you are
right; the Dashboard, Report, and Dataset are the major components of
Power BI service. Let’s understand them in detail.
Dataset
A dataset is a collection of relevant data coming from a data source or
multiple data sources. One dataset is also used to create multiple reports and
dashboards.
Datasets can be created in two ways. It can be created by connecting to data
sources using the Power BI Desktop tool. Alternatively, you can go to Power
BI online and use the Get Data feature to connect to data sources for creating
datasets.
Dataset is the most important building block for developing reports and
dashboards. When you publish the reports Power BI Desktop to Power BI
online service, the dataset also gets published to make reports intuitive and
responsive.
Report
A report is a form of visualizing data into single or multiple pages like charts,
graphs, trees, images, and pie charts. All these visualizations are created
using a singular dataset. All the reports can be generated from scratch, or you
can also import them with the help of dashboards shared among the team
members. You can also import the reports when you connect to online third-
party software such as Microsoft Excel, Salesforce, Power BI Desktop,
content packages, and backend databases.
A report can be viewed and interacted in two different modes: Reading View
and Editing View. The owners, co-owners, and users who are granted
permission can view the reports in the Editing view. Others can view the
reports in the form of a Reading view only; they can interact with reports but
can’t modify them.
A report can only be created using a single dataset. However, it can be pinned
to multiple dashboards.
Dashboard
The dashboard is a canvas than contains single or multiple tiles and widgets.
These tile and widgets show the visualizations. And the visualizations are
nothing but reports. So, the dashboards display reports and other components.
Dashboards can be created or shared by users among the group that has
access to the shared content. Dashboards can also pin the reports coming
from different sources like SSRS, Salesforce, etc.

Power BI Desktop
Power BI Desktop is a report designing and authoring tool with advance data
shaping and modeling capabilities that helps you to get your data ready for
analysis in a short span of time.
Through Power BI Desktop, you can connect to more than 60 data sources
and then make a data model using the Query Editor. Once the data model is
built, you can develop your reports on it. After you create reports, you need
to share them with peers. There are two ways the reports can be shared. One,
the reports can be sent to peers in the form of a file with the extension .pbix,
which is the default file extension for Power BI project files. Alternatively,
you can publish your reports to Power BI online service and then share it
with your peers. For sharing online, all your peers must have authorized
access to the Power BI online service.
Power BI Mobile
Power BI mobile is a very useful and important part of Power BI. If you want
to keep track of your data while you're on the move, you can use one of
Power BI's mobile applications for iOS, Android, and Windows devices. You
can view all your reports, data, and all analytics on your mobile screen.
You need to install Power BI Mobile App on your mobile device or Tab.
Once the app is installed, you can log in to the app using the credentials that
you use for Power BI Online service. After logging in, the app takes you to
the dashboards that were created by you or shared by your peers. This way,
you are always connected to your business.
Power BI Mobile app allows you to set the alerts to notify you whenever
there is a data modification at the source of data. This app is suitable for users
who are always on the move.
You can open any of the dashboards by tapping on them. Within a dashboard,
you can tap on a dashboard tile to focus on it in a larger view, as shown in the
following figure.

You can also annotate any insights that you discover by tapping the Annotate
button in the top right corner. This allows you to draw on a focused tile to
highlight particular areas of interest. The annotation tools are found along the
bottom of the screen.
Share your annotated tile by tapping the Share link in the top right-hand
corner. Tap the Report link in the top right-hand corner to view the report for
a tile. This will display the same visualizations that you would see in a web
browser or Power BI Desktop. Also, it will include the ability to interact with
the report by tapping on bars, drilling down, or using slicers.
Please Note: The details/demonstration of Power BI Mobile is out of the
scope of this chapter.
Now you are aware of multiple components of Power BI and ready to move
on with more digging into details. However, we would like to stop here and
think about why we are calling Power BI as a disruptive reporting platform.
Yes, it is disruptive, and it’s challenging the other tools that are available in
the market. I would discuss a very significant feature of Power BI that is
making it different from others. This feature is called Q&A or Natural
Language Query.

Manage Data Sources in Power BI Desktop


Power BI, a product of Microsoft, is self-service business intelligence. It
provides highly interactive visualizations, where a user can create reports and
dashboards by themselves. Power BI Desktop is an application that can be
installed and run on your desktop. In Power BI Desktop, you can create data
models or reports and can share them with others on the Power BI Service.
It provides a cloud-based Services –known as Power Bi Services, along with
Power BI Desktop interface.
The Power BI service provides fast and easy access to data, supporting inputs
from most of the data sources, and the data can be analyzed and visualized by
anyone.

Benefits of Power BI
1. Accessibility: Data is more accessible in Power BI. Power BI can
connect to a huge number of Microsoft as well as non-Microsoft
solutions.
2. Implementation: It’s very easy to implement power BI.
3. Robust access control and Security: Row Level Security is the
feature of Power BI, which makes it different than others. It
allows a team to grant and rescind access on a very controlled
level.
4. Drag and Drop functionality: Through familiar drag and drop
functionality, an end-user can create his/her own report easily—
Drill Down Functionality.

Import and Manage Data Sources in Power BI Desktop


Here you will understand the various ways to manage your data sources in
your Power BI desktop. Let’s go through the steps to import a data source
first.
Import Data Source to Power BI Desktop
To Import a data source into your Power BI Desktop, follow the below steps:
1. From the ‘Home’ ribbon, select ‘Get data’ or click on the down
arrow next to ‘Get Data.’
2. The drop Down will show some frequently used data sources along
with an option ‘More’ at the bottom.
3. Click on the ‘More’ will give the ‘Get Data’ menu. The ‘Get data’
menu can be brought up by clicking on the ‘Get Data’ button in the
Home ribbon.
4. The data sources have been categorized, as shown in the left pane of
the above snapshot.
5. The required data source can be selected just by selecting the proper
category and data source name. The data source ‘Oracle database’
has been selected which comes under ‘Database.’
6. By selecting the button ‘Connect,’ a pop up will appear, which will
have a label where the Server name to be put.
7. After putting the server name / global database name as per the
above snapshot, the window will appear once ‘ok’ is clicked.
8. Put the credentials in the Username and Password boxes as shown
above and click ‘Connect.’ Once the data source is connected, a
window will appear where you need to select the required
table/tables.
9. After selecting the required tables, click on the ‘Load’ button.

Manage Data Source


These steps will show you how to manage the data sources that you have
already connected to your Power BI Desktop.
1. From the ‘File’ drop-down, select ‘Options and Settings’ ->
‘Data Source Settings.’
2. The ‘Data Source Settings’ window will display all the Data
sources as below:

Data sources in the current file: this will have the list of all data sources
which have been connected in the current file.
Global permissions: this will have the list of all data sources which have
been connected previously in all the files.
Change Source
The below steps will show you how to change the source/ sources. Please
note that the ‘Change Source’ option is available only for the current file.
1. After selecting the source name, which you want to change for
the current file, Once you click on the ‘Change Source’ button at
the bottom left corner of the window.
2. Replace the old Source name ( System Identifier ) with the new
one and click on the ‘OK’ button.
3. If the new source which has been added is not connected
previously in your Power BI Desktop, then after replacing the
new source following the steps mentioned above, once you click
on the refresh button ( Home ribbon), a pop up window will
appear. Because you are connecting this particular data source
for the first time in your Power BI Desktop, you need to give the
credentials there.

Edit Permissions
In case of situations where:
1. password has been modified for a particular user or
2. (2) User needs to be changed to connect to a particular source.

The below steps can be followed:


1. In the ‘Data Source Settings’ window ( shown above), select the
particular data source, and hit the ‘Edit Permissions’ button.
2. The ‘Edit’ button there in the Edit permission window will allow
you to change/modify the credentials for the current data source.

Clear Permissions
The credentials to connect to a data source can be removed following the
below steps:
In the ‘Data Source Settings’ window, select the particular data source and hit
the ‘Clear Permissions’ button.
From the drop-down of ‘Clear Permissions’ button, you can choose:
(1) Clear Permissions: credentials will be removed only for the selected data
source
(2) Clear all permissions: credentials will be removed for all the data sources.

Q&A (Natural Language Query)


Do you know that you can ask questions from your data, not only using
programming queries but even through the natural language? Yes, natural
means a natural language that you often use while talking about data. Let’s
understand with an example. You often ask, “What is your total sale for
June?” or “Which product is the top seller?” and so on. Now imagine you are
typing such statements, and as an answer, you are getting the stunning
visualizations showing the sought information.
Let’s understand this concept by following examples.
The preceding figures are showing the results of two very generic questions,
what is the total profit? And what is the total sale? As a result, you get two
widgets showing the sought information.
You can use the Q&A feature to find more about your data using the
intuitive, NLP capabilities and get the answers back with the help of graphs
and charts. Please note that Q&A is different from a search engine capability.
Q&A only provides results about the data in Power BI.
How to use Power BI Q&A
Q&A feature is available on Power BI online service and Power BI Mobile.
But not on Power BI desktop. The Q&A question box is a text box where you
can easily type your question with the help of NLP. Q&A can recognize the
typed words and can figure out the dataset to be used to find answers to your
questions. Q&A is also capable of forming your question with the help of
auto-prediction, textual aids, and restatement.
Step 1. Click inside the question box. Now, the Q&A will show a dropdown
with helpful suggestions even before you type anything in the question box.
The dropdown list would display the following:
All the questions which are used in creating the tiles already
present in the dashboard.
The name of the tables present inside the dataset underlying it.

You can type your question and keep on refining it to reach to specific
answer that you want an answer for. Alternatively, you can also use the name
of the table that can help you to form a completely new question.
Step 2. Select from the displayed dropdown, or you can also start typing the
question of your own choice of question.
Step 3. While you are typing a question, Power BI Q&A selects the most
suitable visualization to show your answer; and this visualization would
change dynamically as you refine the question, as shown in the following
figures.
The question here is: total units of 2020 by month
The question here is modified to total units of 2020 by month by
manufacturer
Step 4. While you type your question, the Q&A feature searches for an
answer in any dataset, which is having a tile placed in its dashboard. If each
tile is from the Sales and Marketing Sample, the answer is going to come
from Sales and Marketing Sample. If there are tiles from Sales and
Marketing Sample and Other Dataset, then the Q&A feature will look for the
best answer present in both these datasets.
Please note: You need to be cautious if only one tile is present in the Sales
and Marketing Sample, and by chance, you are removing it from the
dashboard, the Q&A feature will not be having any access to Sales and
Marketing Sample.
Step 5. Once you are satisfied with the overall result, you can now pin the
visualization to any dashboard with the help of a pin icon present at the top
right corner. If you have not created the dashboard yourself, or it has been
shared with you from any other member, you are not allowed to pin the
visualization.
Step 6. You can also tell Power BI Q&A functionality the type of
visualization you want to view. If you noticed, the preceding graph is a bar
chart. If you want a line chart, you just need to add word line after your
query, and you will get the visualization changed to a line chart.
Strategies to Learn
Power BI Functions

Introduction
Here you will see the information about Power Bi architecture and how to
create, publish, and schedule a Power BI dashboard, how to create
parameters, and also limitations of Power BI.

Power BI Architecture
Data Sources: In power BI data sources can be broadly classified into two
types cloud data sources and On-premise data sources.
Cloud data sources: Azure SQL Database, Azure SQL Data
Warehouse, Azure Blob Storage, Excel files in OneDrive, Online
Services as Facebook, Mail Chimp, Salesforce, Google
Analytics.
On-Premise Data sources: premise data sources can be further
classified into two types as On-premise databases and On-
premise files.

On-premise databases: Oracle, My SQL, Teradata, SAP HANA, SQL


Server Analysis Services(SSAS), Sybase, IBM DB2.
On-premise files: Excel, CSV, XML, Text files.
Power BI Authoring PC: This authoring machine should have two
components installed they are:
Power BI Desktop: It is a windows application which can be
downloaded from Microsoft’s Power BI portal. By using this
application, you can design interactive reports and dashboards.
Report files can be saved on local disk with .pbix extension. The
reports and datasets can be shared in the Power BI portal.
Power BI Personal Gateway: Needs to be installed separately
on authoring PC along with Power BI Desktop and is a bridge
providing quick and secure transfer of data in between the Power
BI portal and on-premises data sources. Available only with
Power BI Pro Subscription. Azure Service Bus provides security
for the data transferred between the gateway and the Power Bi
Portal, providing a secure channel between your computer and
the Power Bi service. This secure channel means that there is no
need for you to open any ports in the computer firewall.

Power BI Portal: It is where users publish their datasets and reports, create
dashboards and content packs, and share data with team members of their
organization. Users can sign in to the portal using their organization account.
Each user will have a personal workspace in the portal named My
Workspace, which comprises dashboards, reports, and datasets published by
the user.
End Users: Dashboards can be shared via email with multiple stakeholders.
Power BI offers a free mobile app for IOS, Android, and Windows devices.
Reports and dashboards automatically adjust their sizes to fit the screen of the
device, so users need not worry about creating mobile versions of the work.
Users can interact with reports and dashboards through filters, slicers,
drilling, etc.

Creating, Publishing and Scheduling a Dashboard


Creating a Dashboard
Importing data source
AdventureWorks database needs to be imported from the
Microsoft SQL Server. Click on get data icon in the home bar.
Go to the database and select the SQL Server database and click
on connect.

Now mention the server name and click on ok.


Select the AdventureWorks database and check the boxes for the
tables that need to be imported and click on load.
After importing tables will be shown in the fields pane.
Click on the edit queries icon in the home bar to view the data
for all the tables.
A new edit queries window will open, which will show data for
all tables where a lot of transformations can be done on the data
using the edit Queries window. Click on close and apply after
changes have been applied.

Designing the Dashboard


Below are the requirements that should be achieved while designing a
dashboard
Requirement-1: To display overall total sales of the company.
Requriment-2: To create drill down on SalesTerritoryGroup>
SalesTerritoryCountry> SalesTerritoryRegion and compare total sales.
Requirement-3: To show sales for product subcategories in the selected
product category for both internet and reseller sales.
Requriment-4: Locate countries and their respective sales on a geographical
map.
Requirement-5: Create a filter on the sales territory group.
Now let us understand each requirement one by one.
Requirement-1: To display the overall total sales of the company.
To fulfill this requirement, card visualization can be used.
Drag and drop the card visualization from the visualization pane.
Right-click on fact internet sales and select a new measure.
In the measure window, type the name of the measure
as TotalSalesbyDAX.
Type in the DAX query as:

TotalSalesbyDAX = SUM(FactInternetSales[SalesAmount]) +
SUM(FactResellerSales[SalesAmount])
Now drag the measure into value field of the card. And do some
formatting by using the format pane of card visualization.

Requriment-2: To create drill down on SalesTerritoryGroup>


SalesTerritoryCountry> SalesTerritoryRegion and compare total
sales.
To fulfill the requirement, a bar chart can be used.
Select the Bar chart from the visualization panel.
Expand the table DimSalesTerritory and select the
SalesTerritoryGroup column and drop it on the Axis section of
the Fields pane.
To create the hierarchy, drag the SalesTerritoryCountry column
and drop it below SalesTerritoryGroup in the Axis section.
Also, drag the SalesTerritoryRegion column and drop it below
SalesTerritoryCountry. This creates the hierarchy.
In the value section, drag the measure TotalSalesbyDAX.
Now some formatting is required for the bar chart, so maximize
the chart by clicking on the icon.
Go to format pane and enable the data label property now the
vales will appear and change the font color, size, background
color of data labels.
As hierarchy got created, data can be drill down
from SalesTerritoryGroup>
SalesTerritoryCountry> SalesTerritoryRegion. Right-click on the
bar and click on drill down or use the drill down arrows, which
are appearing at the top right corner.
On drilling down Europe, total sales with respect to countries in
Europe are shown.
And this creates drill down on SalesTerritoryGroup>
SalesTerritoryCountry> SalesTerritoryRegion and compares total
sales.

Requirement 3: To show sales for the product subcategories in the selected


product category for both internet and reseller sales.
Steps to Create a treemap for Internet Sales
To fulfill this requirement, a treemap can be used.
Select a treemap from the visualization panel.
To build the hierarchy and enable drill-down, drag, and drop.
EnglishProductCategoryName
and EnglishProductSubCategoryName columns from
DimProductCategory and DimProductSubCategory tables,
respectively, on group section of the Fields pane.
Drag and drop SalesAmount column from FactInternetSales table
in the Value section.
In this tree, chart drill-down is created from.

EnglishProductCategoryName> EnglishProductSubCategoryName so right-


click on bikes and do drill down the sales for different subcategories of bikes
can be seen.
Steps to Create a treemap for Reseller Sales
Repeat the steps 1-2, as mentioned in the above chart.
Select the SalesAmount column from the FactResellerSales
table instead of the FactInternetSales table while following the
third step.

This creates treemaps that show the sales made through the internet and
reseller in various product categories.

Requirement 4: Locate countries and their respective sales on a geographical


map.

Steps to Create a Map Visualization


✓ To fulfill this requirement, map visualization can be used.
Select Map from Visualization pane.
To enable the drill-down feature on Map drag and
drop SalesTerritoryGroup and SalesTerritoryCountry columns
from the DimSalesTerritory table in the location section of Fields
pane.
In the size section, drag the measure TotalSalesbyDAX.
Formatting can be done by changing the bubble colors using the
data color option and increase the bubble size by using the
bubble option.
As the drill-down feature is enabled from SalesTerritoryGroup>
SalesTerritoryCountry. On drilling down, European sales made
by the individual country in Europe can be seen.

Requirement 5: Create a filter on the sales territory group.


Steps to Add a Slicer
To fulfill this requirement, the slicer can be used.
Select slicer from the Visualizations pane.
Select the DimSalesTerritory table and drag and drop the column
SalesTerritoryGroup on to Field section. This adds the data of
the SalesTerritoryGroup column in the slicer.
Go to format pane of the slicer to enable multi selection to
disable the single select in selection controls. If the select all
option is required, it can be enabled. And select either list or
dropdown of slicer by clicking down arrow at the top left corner.
Slicer on SalesTerritoryGroup is created.
Done with all the requirements of creating a dashboard.

Publishing a Dashboard
Click on the publish icon, which is on the top right corner.
A sign-in dialogue box will appear where the Power Bi account
email id needs to be entered.
Give a password and click on sign in.
Select my workspace.
A dialogue box will appear, saying that the report is published.
Click on the report name; it will navigate to the Power BI portal.
Now the report in the portal will appear. Click on the icon pin
live page to create a dashboard for the report.
Give the name of the dashboard and click on pin live.
The dashboard view can be switched between the web view and
phone view.

Scheduling a Dashboard
Click on subscribe to receive the email.
A dialogue box will appear, saying that an email will be sent
whenever the data is updated. Click on save and close.
Now data refresh for AdventureWorks needs to be scheduled. Go
to AdventureWorks and select a scheduled refresh.
Install power bi personal gateway if the data source is on-premise
and mention the gateway connections and enter the credentials of
the data source.
Data refresh can be done daily or weekly and set time zone and
mention at what time the data needs to be refreshed if there is a
failure in data refresh a notification mail will be sent. Click on
apply.
As a data refresh is scheduled whenever the refresh happens, the
subscription will trigger an email to us.

Creating Parameters in Power BI


Requirement: Create parameter on sales territory group
Go to edit queries in the home bar.
Go to DimSalesTerritory table right-click on column
SalesTerritoryGroup and select add as a new query.
Now the column SalesTerritoryGroup will be considered as a
new table. Right-click on the column and select remove
duplicates as you need distinct SalesTerritoryGroup.
Now SalesTerritoryGroup Query needs to be passed as
parameter.
Click on manage parameters.
A parameter dialogue box will appear where the name,
description, and data type of parameter need to be mentioned. If
the suggested value option is any value, only one value can be
passed if it is a list of values multiple values can be passed in the
current scenario query should be passed as parameter. A select
query is suggested values, and in query option select
SalesTerritoryGroup_query and the current value, you can
mention any among the list of values.

In the current scenario, Europe is taken.


Click on Ok. Europe will appear as the current value.
This parameter needs to be applied to the table
DimSalesTerritory table. Go to DimSalesTerritory table click on
down arrow of SalesTerritoryGroup column select text filters
click on equals.
Filter rows dialogue box will appear—select parameter.
Now automatically, the parameter will be mapped. Click on OK.
Now the query data will be filtered on Europe as Europe is
mentioned default parameter.
Click on close and apply it to the query editor. Export the report
to Power BI templet. The report will be saved in .pbit format.
When the templet file is opened, it prompts for the Sales
Territory Group where the value should be selected. North
America is selected as a filter and click on load then all the data
related to North America will be loaded in the report.
Data related to North America is loaded.
The difference between .pbit and .pbix files is that a .pbix file
will have the data for all the queries, but a .pbit file has only
schemas initially. It doesn’t have any data, and data will be
loaded only after selecting the parameter; this is the reason .pbit
file has less size when compared to .pbix.

Calling Oracle Package Function in Power BI


Packages that have functions and cursors can be created in oracle, and when
that particular package and function is called, it gives the data. In power BI w
oracle packages can be called, which will load the data.

Requirement: create an oracle package on the customer table when ‘M’ is


passed as an input value. It should show the male customers details as output,
and if ‘F’ is passed, it should show the female customers details as output.
The package code looks like below:
CREATE OR REPLACE
PACKAGE customer
AS
CURSOR c_tr_customer (p_gender string default null)
is
select * from "customer" where "Gender"=(p_gender);
TYPE customer_type IS TABLE OF c_tr_customer%ROWTYPE;
FUNCTION Fn_customer (p_gender string default null) RETURN
customer_type PIPELINED ;
END customer
;
/

CREATE OR REPLACE
PACKAGE BODY customer as
FUNCTION Fn_customer (p_gender string default null) RETURN
customer_type pipelined AS
v_c_tr_type customer_type;
v_count PLS_INTEGER := 0;
BEGIN
FOR r IN c_tr_customer(p_gender)
LOOP
v_c_tr_type := customer_type(r);
PIPE ROW(r);
v_count := v_count + 1;
END LOOP;
RETURN ;

END Fn_customer;
END customer;
/
When package function is called by passing ‘M’ as input, male
customer details were shown as output.
Click on get data in Power BI go to databases select oracle
database and click on connect. Give the server name and write
the query in the SQL statement.
‘M’ is passed as input male customer details will be loaded.

This is how you can call oracle packages in power BI.

Limitations in Power BI
In Power BI, the size of the table does not increase or decrease
relatively along with the data, and when data is more scroll bar
should be used to scroll down, and when the data is less, the
empty space will pop up in the table.
.Pbit file can’t be uploaded in the Power BI portal you can only
upload .Pbix files where the .Pbit file prompts for a parameter so
you cannot upload reports with parameters in the portal.
There is no visibility property in Power BI, like in SSRS, to hide
the visualization depending on the condition given.
Conditional formatting can’t be applied to fields when the data
type is other than integers. The conditional formatting pane has
only employee key, so conditional formatting can be applied
only in numerical fields.
Dashboards and reports can only be shared with users who have
the same email domains or email domains listed with Office 365
tenant.
Microsoft Power BI is still in the early days. The tool will be
getting updates every month by considering the requests from the
users.
Scheduling of reports in power BI portal is not as flexible as
Scheduling SSRS reports using share point.
Power BI Desktop
Functionalities

In this chapter, you will understand the basic and detailed concepts of Power
BI Desktop implementation with clear examples. Also, you will see the
advantage of Power BI Desktop in data visualization.

On-Premises Data Power BI Data Visualization


SQL, SSAS, Excel Desktop, Mobile, Browser

Power BI Desktop Introduction


Microsoft provides Power BI as a free service for business analytics,
providing fully interactive visualizations, allowing end-users to create
dashboards and reports by themselves without depending on anyone.
Power BI Desktop is a free desktop application that provides report creation
& generation, modeling, and advanced query features, which helps you to
create reports, data models, and collaborating with team members by sharing
your work with each other.
You can share the work in two ways:
1) Power BI desktop file (.pbix/.pbit): Share the file to the user; if the
user wants to see your report, they need to install Power BI desktop
in their system.
.pbix- (Power BI Desktop File) Report with static output.
.pbit- (Power BI Desktop Template) Report should accept the
changes dynamically and display the output based on the input
parameters.
2) Power BI service: Publishing the PBI desktop file directly to Power
BI Service, so that users can see the report and interact with it from
the web browser. You need a license to connect the Power BI service.
Starting Power BI Desktop
1. The first step is to launch the Power BI Desktop.
2. Connect the SQL Server objects to get the data loaded into PBI
Desktop.
3. If you are the admin of the server, then connect the SQL Server
using “localhost\SQLEXPRESS” in my Local Server Instance.
4. If you want to connect the Generic server with Username and
password, then connect the SQL Server by providing the
Username and Password.

Data Connectivity Modes


Import
It will import all the selected tables/columns into the Power BI Desktop.
Whenever a user wants to create/interact with a visualization, the ‘Import’
won’t pull the latest data from DB; if you want to see any changes to the
underlying data, then you need to do a refresh every time in Power BI
desktop.
See the detailed example mentioned below by loading the “TrendData” table.

Column_name Type
WorkYear Int
Workweek Nvarchar
USA Int
SNO Int
File Name = Trend.pbix
Slicer Tool will act as a filter tool. You have two-year values (2019 & 2020).
In the example, I selected the value 2019 from the slicer tool, which is
coming from Query1 Dataset. So, the designed report will also show only
2019 year values information.
Add a new value to the Trend Data table to see whether it is reflecting in the
Power BI Report or not.
SQL> Insert into [dbo].[TrendData] values(2019, 'SNO4', 140, 138, 123, 251,
106)
Close the Power BI Desktop file Trend.pbix and open again; you won’t see
the newly inserted ‘WW07’ values in the Power BI Desktop until you do a
“Refresh.”
Direct Query
It won’t copy/import any data to the Power BI Desktop.
Whenever a user wants to create/interact with a visualization, ‘Direct Query’
queries, only the underlying data from the DB. Meaning always you will
view the current data.
File Name = Trend_Direct.pbix
SQL> Insert into [dbo].[TrendData] values(2020, 'SNO5', 145, 213, 126, 174,
148)
Close the Power BI Desktop file Trend_Direct.pbix and open again, you can
see the newly inserted ‘WW07’ 2018 values in the Power BI Desktop without
a Refresh because Direct Query will always give us the current data from DB.
1. Suppose instead of pulling data from a single table; if you want
to join with some other table to get the result set, then you need
to right-click on the Dataset ‘Query1’ and select the ‘Edit Query’
option highlighted in the screen.
2. Double click on the Source option highlighted on the screen.
3. Database server connection popup will open, and you can modify
the query by joining with other tables and put the statement again
in the ‘SQL Statement’ window highlighted on the screen.

Note: While modifying the query statement, think you have already designed
the Power BI Desktop with some attributes, make sure that the same attribute
names must come again along with other new additional attributes (if any).
Otherwise, you will lose the design which you had already designed before.
Example: You designed the Power BI Desktop using (Work Year,
Workweek, USA, SNO) attributes while modifying the query to make sure
these attributes must come in the new query also otherwise, you will lose
design.

Pbit Template File Implementation


All the above explained the Pbix extension file would give only the static
result. Suppose if you want to see the data based on your input parameters
(Date, text, Number, etc.) in Power BI reports, you need to use the Pbit
template file.
Parameters Syntax
Date Parameter = '"& Date.ToText(Column_Name) & "'
Text Parameter = '"& ToText(Column_Name) & "'
Number Parameter =" & Number.ToText(Column_Name) &”
1. You are going to get the Missed Records status report for all the
GEOs using Pbit template file.
2. I have maintained three tables to load the missed records data
counts every weekly from 2019 to till now from the daily
transaction OLTP.
3. Now you are going to create a Self-service Analytical Power BI
report (pbit) to allow business users to leverage analytics.
4. Open the Power BI Desktop and save the file in the below-
mentioned format (*.pbit).
5. Get the data loaded from SQL Server by following the below
step.

1. Load the table data with hardcoded parameter value into Power
BI desktop.
2. Data Loaded into the Power BI Desktop with dataset name
‘Query1’.

Create Parameters
Add Parameters in the Power BI desktop to pass the dynamic parameter value
while loading the data into Power BI Desktop.
1. Right-click on the ‘Query1’ and select the ‘Edit Query’ option.
2. Select Manage Parameter drop-down and click on the ‘New
Parameter’ option.

Now, create two Parameter with the names “Year” and “Workweek.”
Year Parameter Creation.
WorkWeek Parameter Creation.

After the creation of two parameters, click on the “Close & Apply” option to
save.

Assigning Parameter Values Dynamically


Change the hardcoded Parameter values to the created Parameter names to
get only the specific data loaded into Power BI Desktop based on the I/P
Parameters.
1. Right-click on the ‘Query1’ and select the ‘Edit Query’ option.
2. Click on the drop-down arrow nearby Query Settings.
3. You will get the hardcoded value for YearName and Week.
4. Now try to replace the hardcoded values with the created
parameters (Year & WorkWeek). The tick mark(Parse) will tell
you whether your modified query is correct or not.
5. For better understanding, you can rename the ‘Query1’ dataset to
whichever name you want. “MissedRecords table loaded into
PBI with dynamic parameters.”
6. You need to follow the same procedure which you did for the 1st
table dataset ”MissedRecord” to load the 2nd table “Missed
Percentage” by passing the dynamically created parameter
values.
7. For the 3rd table, I don’t want to pass any parameters; instead, I
want to load all the data. Creating visualization for the Loaded
DataSet. Select whichever objects needed from the visualization
menu.
8. Select whichever data fields which you want the user to see in
the Power BI Report.
9. I have pulled data fields from two Dataset “MissedRecords” &
MissedPercentage” and created a tabular view of data.

Once you have completed the above steps, you can start the below ones.
1. For formatting the text and good design, click on the red circle
highlighted to see the available formatting option to alter the text
format and design format.
2. You can also change the Data Type of any attribute, for example,
click on the Missed_Record field and click on the Modeling
menu to change the data type.
3. Create a new tab to create the Missed records Trend using
Visualization in PBI.
4. As I told before, I haven’t set up any dynamic parameter value
for this Dataset MissedTrendData. Then pull all the data from
this table from SQL DB.
5. Copy the created design and paste on the same tab.
6. Click on the pasted design and select the Line graph, then your
design will change. Click on the yellow color highlighted option
to change the level of data to the lowest with an ordered format.
7. Change the Y-axis scale type to ‘Log’ to arrange the data in
proper order. Enable the ‘Data Label’ Option to see the values
for the corresponding Year & Work Week.
8. You can filter the data by using the slicer tool ‘Year Name,’ then
the report will also reflect based on the selected value. Save and
close the Power BI desktop.
9. Reopen the Power BI Desktop; it will ask for the parameter
values.

Now, data got loaded, and you can see the same tabs.
1st Tab - You set dynamic parameter values for the two datasets
“MissedRecords” & “MissedPercentage.”
2nd Tab - You loaded the “MissedTrend Data” dataset without
setting up any dynamic parameters.

For testing purposes, I have pulled Week, and YearName attributes from the
loaded “MissedRecords” dataset to verify the data loaded only for the
selected Parameters.
Publishing Power BI Desktop to the Web (Power BI Service)
1. Click on the Publish tool.
2. Sign in to Power BI Login.
3. Select Destination place where to save the Power BI report.
4. Once the above step is done, you will receive a link to your
report.
5. Click on the link to open the report in your Power BI publishing
site.

Minimum System Requirements to Run Power BI Desktop


Windows 7 / Windows Server 2008 R2, or later.
.NET Framework 4.5 or later.

Maps in Power BI Desktop


Here you will understand how to connect to the data sources, create
dashboards, availability of different kinds of visualizations, especially map
visualizations and their usage in Power BI Desktop. Now let us get started.
Creating a Dashboard
Open Power BI Desktop, it will show the home screen.
Then click on Get Data, it shows the following screen showing a wide range
of source connections.
Select the required option. Here I am selecting the Excel. Click on connect
and browse the path where the file is located. Select the sheet which you want
to load and use. Click on Edit if you need to change the dataset like adding a
calculated column, deleting the unwanted column, etc. else click on Load.
Then it will load the data. To check the data loaded, click on the icon Data on
the top left side on the screen.
Now you will develop dashboards using map visualizations available.
Note: If the visualization is not available in the list available, you can
download and import it by clicking on the three dots (. . .)
Dashboard Using Map
For this, click on the empty or white screen then click on Map under the
visualizations tab.
Then check the country and sales columns available under the
Country_vs_Sales dataset. Maximize the map.
Now you will try to include other visualizations like a bar chart, a pie chart
for a better understanding. For this also, click on the empty white screen
available, then click on the desired visualization, then drag the fields to the
desired appropriate values or check the columns.
And then, by clicking on any of the countries, you can filter only for that
particular country value throughout the dashboard.
Suppose I clicked on the value New Zealand, then the total dashboard will
highlight the details of New Zealand only.
Give the proper name to the dashboard and save the file.
Based on the requirements, you can use different visualizations on the
dashboard.
The above dashboard consists of the Visualization Map. Now you will try to
implement different kinds of maps available.
Filled Map
Now select Filled Map under Visualizations tab, then check the boxes
against country and sales columns.
You can also go for the individual coloring for each country by dragging the
country column to legend.
You can also specify the color saturation from one color to another,
depending on the values in the data.
E.g., it will display the colors from red to green, i.e., red indicate lower
values and green indicate higher values.
You can also include here one more color as the center value by setting the
value of Diverging to On. The values for the Minimum, Center, and
Maximum are taken by default. You can also explicitly mention the range of
these values according to your needs.
If you give the consecutive values to them, they display the exact colors with
no saturation.
And if consecutive values are not given to them, they display the saturated
colors.
Shape Map
You use a shape map to achieve your own desired map or when you want
only to specify particular regions of the map. For this, you can select the
maps available under it. Or if the map which you are looking for is not
available, you can create one yourself and import it. This file will be in .json
format.
.g.: You shall compare the sales among the different countries of the African
continent.
Now click on the shape map under visualizations.
If it is not available, enable Shape Map by navigating to File -> Options and
Settings.
Then go to Options -> Preview Features.
Finally, select the Shape Map, and you have to restart the Power BI Desktop
once you finalize the selection.
Now develop a map file in JSON(JavaScript Object Notation) format. (You
can get from internet of desired geographical regions). I created here the
countries of the African continent.
As soon as you enable the Shape Map, click on Shape Map control present in
the Visualizations pane. Check a few columns and go to the Format tab,
where you can see the predefined groups of countries under the Shape tab.
You can select one among the given list, or you import the map file by
clicking on the tab +Add Map.
Now it will direct to browse the file option, then select the file and import.
You are allowed to use the custom maps along with Shape Map only if their
format is in TopoJSON. If the map is not in this format, use the online
converters like Map Shaper (http://mapshaper.org) to convert it to TopoJSON
format. Generally, the JSON files downloaded from the internet should be
converted to TopoJSON format using Map Shaper.
Now the map of desired regions is visible. You can compare the sales values
among these countries by having different colors for each of the sales value
by having Sales in legend.
Power BI Real-Time Dashboard

Introduction
This chapter provides details about the process required to implement Real-
Time Dashboards using the Power BI Preview feature of Office 365. It
describes best practices for building a business intelligence (BI) environment
by using a combination of Microsoft Power BI, Microsoft Office 365(O365),
and on-premises data sources.
This chapter will help you understand designing and sharing a real-time
dashboard. It will make you aware of its functionalities and benefits as well.
It also provides you with information about how you can connect to various
data sources to fetch your data and use the same for building your
dashboards.
To start with, you should have the data, or Power BI reports that will help to
build your dashboard in some data sources like Excel Workbook, SSAS,
GitHub, etc. You should also have some basic knowledge on how to create
Power BI reports, though it is not mandatory. It will help you to learn how to
create Power BI reports and will help you to create real-time dashboards
having tiles made of visualization (like charts, map, combo charts, graphs,
etc.)

Power BI Preview
Microsoft Power BI dashboard helps you to stay up to date with the
information that is important to you. Your dashboards have tiles that lead to
the reports which you can explore on just a single click. You can bring all
your relevant data together in one place by connecting to multiple datasets.
Reasons for Creating the Dashboards
To see all the information needed to make decisions in one place
and one look.
To increase efficiency and support the decisions based on the
most important facts.
To ensure all the colleague's views and use the same information.
To help the business determine goals and strategies and monitor
the health of a business.
To allow you to identify and correct negative trends using
metrics and trends that matter a lot for business.

When you first open Power BI Preview, you'll see:


Navigation pane
Dashboard with tiles
Q&A question box
Help and feedback buttons
Dashboard title
Home button
Version

Navigation Pane
The three objects of Power BI Preview include dashboards, datasets, and
reports. You can use the Navigation pane to explore them. You can have no
data in dashboards and reports, but that is not useful until you have the data
with you. So for creating dashboards, you need to have data.
Datasets
You need to have data for dashboards, and for getting that, you can use
datasets to connect to various data sources. After gathering all your data in
one place, you can start by creating reports or dashboards. You can even
bring your already created reports using datasets.
In the navigation pane, you can find all the datasets that you have connected
to present in the heading Datasets. Each dataset listed is only having a single
data source. Let’s say that you have an Excel sheet in OneDrive, your
computer, or any of your on-premises datasets, Salesforce database, etc.
ONE dataset is useful in creating many reports, or you can say the same
dataset is used many times in different reports. You can pin as many
visualizations from your dataset to any number of the dashboard.
To connect to a Dataset, you can either click GetData from the top of
Navigation Pane or Click on next to Datasets.
In some cases,
When Power BI Preview imports a copy of the dataset, then, in
that case, the changes you make won’t affect your original
dataset since it is a copy of your dataset.
When Power BI Preview connects to your dataset like if the
workbook was imported from OneDrive for Business, then you
can refresh your dataset with the latest data from the workbook
on OneDrive.

Dashboards
A dashboard is a visualization tool that shows you the current status of
metrics, graphs, charts, KPI’s, etc. related to business on a single screen for
an enterprise. It is created by the co-workers and shared with the concerned
members in an organization to stay up to date. Dashboards consolidate tiles.
Each tile contains visualization created from the underlying data in your
datasets.
You can find your dashboard listed in Navigation Pane under Dashboards
heading.
ONE dashboard can show visualizations from many different datasets, and
the same goes for reports as well. After creating a dashboard, you can share it
within your team as well.
You can even import your dashboards from other SAAS services with the
dataset like the Get Data popup for Salesforce has an option of getting
dashboard and/or report to be created from your dataset.
Reports
The Power BI Preview report contains page(s) of visualizations. You can
create reports from scratch using the PowerBI Preview itself, or you can also
import them using datasets. Once you add a dataset, it automatically gets
added under the reports heading in Navigation Pane, but only if your data is
formatted properly, and it has visualization in Power View sheets and with
shared dashboards. For example, if you are connecting to the Microsoft Excel
workbook, which has the Power View sheets present in it, then the Power BI
Preview will automatically create a new report as per the visualization
present in those sheets. You can even create Reports based on the data you
have using Excel tool-kit like Power Query (Discover and Connects to data),
Power Pivot (Transform and models data), Power View (Create Visualization
(charts & graphs))
You can find your reports in the navigation pane listed under the Reports
heading. Each listed report has a page(s) of visualization. You have two ways
to view as well as interact with reports. They are:
Reading View: There is no need to worry using this view as you cannot
modify or update anything. All you can do is explore and browse the data and
visualization in the report, and temporarily pin any of the visualizations you
want in your dashboard. (The filters applied while interacting with your
reports also won’t be saved, and neither the pinned tiles will be saved when
you close and reopen Power BI Preview).
NOTE: To edit the report and save your changes, you have to open it in
Editing View.
Editing View: As compared to Reading View, In editing View, you can look
into your data by creating new visualizations, changing visualization type,
adding and deleting visualizations, adding and removing fields, and adding
pages from the report.
NOTE: To edit a report, you must be the owner of the report
NOTE: If a dashboard has been shared with you, then you won’t be able to
see the report in the navigation pane. You will be able to open the report
only if the report owner pinned that particular tile from the reports or
otherwise if the owner created from the Q&A, then the Q&A page opens.
ONE report can be used in multiple dashboards. Tiles selected from the
different reports can appear on the same dashboard. ONE report can be
created from only one dataset. There is an exception to this - you can use
Power BI Designer, which is capable of combining more than one dataset, to
build a report. There is also an option in GetData ‘Power BI Designer File’ to
import a copy of it and build your dashboard.

Dashboard Tiles
Dashboards are made up of tiles containing visualization. They are created
either in report Editing View or Q&A. The owner of the report pins the tiles
that appear on a dashboard.
You have now created the dashboard.
Benefits
Shows the holistic summary view for all the metrics in the
current fiscal year.
Real-time status of Product Launches launched and Hot-fix
information.
Single view to show everything that’s needed for the business.

Information on Dashboard
Product Launches: The Product Launches metrics show the Standard Product
Launches count and the Non-Standard Product Launches, count.
Quality: The Quality metrics will show the data for both Production defects
and Hot-Fixes. The Fields shown under this category are below:
No. of Production Defects
Standard Defects & Non-Standard Defects
Bad Hot-Fixes & Good Hot-Fixes

Drill-down views: Drilldown views for each of the categories are shown in
the report.
Product Launches Drilldown: You can show the Product
Launches in different dimensions. Product Launches against
Business Groups, Product launches against Launch lead, and
Product Launches against Functional Areas.
Quality Drilldown: You are showing the quality metrics in
multiple dimensions based on the need. You can show the
defects against the functional Area, Defects against launch type,
and Defects against the environment—Hot-Fixes against good or
Bad Hot-fixes, hotfixes.

Q&A Question Box


In Power BI, the Q&A uses Natural Language as a query being able to
answer a question in the form of charts, graphs, metrics, etc. in the browser
within a second. The visualizations are all dynamic and interactive. Any
change in your query will automatically alter the results accordingly. This
helps in creating the reports or getting calculations while giving presentations
instantly. You can modify the reports as per your requirement.
You can add content to your dashboards only in the form of tiles. Q&A helps
them who are new to create Power View reports from the basic level. When
you write a query in the natural language, it looks for an answer in the
dataset(s) connected to the dashboard.
When you start typing your question, you are directed to the Q&A page. As
you type your question, it gives you the options to ask the right question with
the help of IntelliSense, suggestions, and finds the best answer in the form of
visualization. Once you have the expected visualization, you can pin it to
your dashboard.
And Work Request according to the State, which gives us information on
How many work Request is closed or pending, which is very useful for
business.
Help and Feedback Buttons
The icons in the top right corner contain a Download menu containing the
direct link for downloading the resources, getting help for any problem that
you face, and providing feedback to the Power BI team. It also contains the
support link for learning all about Power BI preview in a very detailed
manner.
Dashboard Title
It’s difficult to figure out which dashboard is active, always. The dashboard
title appears in the following places:
Report Editing View
Dashboard view page
Q&A page
Report Reading View and when you open a dataset.

This is the way to know which dashboard you're pinning your visualization
into.
Home Button
To return to your dashboard, click on the home button that appears on the top
left corner of all screens in Power BI Preview. You may also return to the
navigation pane using this button.
The Retail Analysis Sample Dashboard
The first time you visit https://app.powerbi.com to open Power BI Preview,
you will find a sample dashboard, i.e., Retail Analysis Sample. Unless you
manually remove this sample, it will always be there. You will not see any
reports under Reports heading even if the sample dashboard because of the
earlier mentioned reason that it is shared with you. You will only be able to
view the report through tiles if the owner pinned the visualization from the
report. You can explore and learn from this sample until you remove it.

Functionalities of Power BI Preview


Delete a Dashboard
If you Delete or remove a dashboard, that does not mean that any reports or
datasets that are associated with it will also be deleted. You have to delete
them separately.
If you have created the dashboard on your own, then only you
will be able to delete it. Once you have shared it with someone
else, then deleting from your Power BI Preview won’t delete or
remove from their Power BI Preview.
You can remove only those dashboard which is shared with you.
This doesn’t mean that the same will be removed from other
people’s Power BI Preview.

How to Remove a Dashboard


1. Navigate to the navigation pane, then right-click on the
dashboard to delete it.
2. Click Yes. The dashboard will be removed.

You can identify a shared dashboard with you, by lock icon prefixed to the
dashboard name. To delete a dashboard, click Delete, following the same
steps as removing.
Create an Empty Dashboard
1. Click the plus sign that appears against the Dashboards heading
on the navigation pane.
2. Give a name for your new dashboard.

Your dashboard will be blank until you get some data. You can get data from
either of these options mentioned below:
Pin the answer(Visualization) from Q&A
Pin visualization from Reports

How to Pin Visualizations from Q&A


In the question box type, what you want to know about data. For example:
To make the metric ‘Bug Count’ display on your dashboard as a tile, click on
the Pin Icon. When you click it. The above-shown visualization will be
displayed as a tile in your newly created dashboard.
How to Pin Visualizations from Report
1. Open the report from which you want to pin the visualization
from in the Navigation Pane.
2. When you open the report, it opens in the reading view. You can
pin a tile from both the Reading View and Editing View. In the
reading view, you can either interact with the visualization and
filter but cannot edit the report.
3. The report you opened has one or more visualization. Click the
visualization you want to pin and click the pin icon. A Success
message will be shown in the top right corner that tells you the
visualization has been added to your dashboard.
4. Click the Home button to see the changes to your dashboard.
5. Now you can customize (rename, resize and remove) the tile in
your dashboard.

Customizing Your Tile


Rename the tile: To edit the tile title, click the pencil icon by hovering over a
dashboard tile.
Move the tile: Hold and drag your tile to a new location on the dashboard.
Resize the tile: The tiles can be re-sized to small, medium, or large. To resize
the tile, click and drag the arrow in the bottom right corner.
Delete the tile: Click this icon to delete the tile. Deleting a tile does not delete
the related report or dataset.

Share a Power BI Dashboard


Now you have the dashboard ready. As I mentioned earlier, you can share the
reports amongst co-workers. Let’s see the steps on how to do it.
You can share the Dashboards with your colleagues by simply clicking the
Share icon and specifying their email addresses.
1. Click the Share Icon after you open the dashboard that you want
to share.
2. When you click on the Share icon, a dialog box appears. Click
on Invite and enter the co-worker's email ID and the description
of the dashboard on the box below. If you want your co-workers
to share your dashboards with others, then check the option.
Allow recipients to share your dashboard. Click Share. Your
co-workers will receive an email invitation with a link to the
shared dashboard.
3. To see with whom you have shared the dashboard, click Shared
With.
4. If you want to unshare the dashboard with your co-worker, click
on Shared With and then Click on Cancel Invite corresponding
to the email address.

Power BI is a very user-friendly BI tool that helps us to create, share, and


access reports just by using a browser.

Various Data Sources


The GetData button helps you to get your own data into the dashboard, which
has various data sources available to connect to get your data and build
powerful dashboards for your business.
Various data sources are Excel Workbook, PowerBI Designer File, SQL
Server Analysis Service, Microsoft Dynamics CRM Online. Customers can
also connect to their data in SAAS services like Salesforce, Zendesk,
Marketo, SendGrid, and GitHub and Microsoft Organizational Content like
Microsoft: IT New Technology Adoption, Windows User Voice, Digital
Crimes Unit and Peoples View.
Starting with an Excel Workbook
First, you have to find the data to visualize. Select the Get Data option
present on the left side of the screen. Now you will be able to view all the
data sources.
Click on Connect to find the excel workbook by clicking on browse. When
you select One Drive (Cloud Service), then you can update the changes
automatically by configuring the Data Management Gateway.
Select the workbook that you need and click the Connect button. When you
are done connecting, you are ready to start.
You can create visualizations like charts, graphs, a Filled Map, TreeMap,
Funnel, Gauge, Cards, Combo Charts, etc. You can explore and learn from
your own.
Now select the visualization you want
Once the dashboard is saved, to see the workbook that you uploaded under
the Dashboard heading, you can return to the main Power BI Dashboard
pane.
The Power BI Q&A and connection to your workbook you uploaded into
your dashboard will appear when your dashboard opens.

Power BI Designer File


This application is a combination of Power Query, Power View, and Power
Pivot in a single application, which allows you to build your Power BI report
offline. You can later upload it to Power BI Preview to build powerful
dashboards. It’s just another option for people who do not have Microsoft
Office 2013 Add-Ins for Power BI.
You can click on the ‘Power BI Designer Preview’ option in Download to get
the application.
Once you are done with the installation load your data in Power BI Designer,
click on Get Data Ribbon (top left corner) to get your data using Power
Query and load it.
The extension for the output file is PBIX.
Limitations of Microsoft Office 2013 Power BI Add-Ins
You will not get complete control over the data model. You can add
relationships only. You will not have access to add any synonyms in the
Power BI Designer.
You cannot Sign-In in Power Query. If you already have a data model
present in your MS Excel, then you cannot use the same to create reports.
Features will be added to overcome a limitation in the future. You may even
have an option to create a dashboard offline.
SQL Server Analysis Service (SSAS)
There are two ways to connect to SQL Server Analysis Services tabular
model data:
Go to Get data, Click on SQL Server Analysis Services. Click on
Connect. Select the server and get started.
Connect to an Excel workbook that already connects to an
Analysis Services server. But if your reports are in a tabular data
model, then only you will be able to explore and edit in Power BI
Preview.

Download the App, Install it, and configured it by an administrator.


To download and install the latest Analysis Services Connector, you can click
on it from the DOWNLOAD menu.
Salesforce, Zendesk, Marketo, SendGrid, and GitHub
These are applications from which you can bring your data in Power BI.
After connecting to your accounts (by providing credentials) in each of those
applications, you will be able to import a variety of data to explore and
monitor in your Power BI dashboards.
Once you connect to these data sources, you have your data; then, you can
create a visualization, pin it to your dashboards and share it with your co-
workers.

Refresh your Data


Most of the features of the Power BI was either already available or could be
achieved by some or other means. But what was impossible until now was to
have an excel workbook in Office 365 that updates automatically and
provides you with the latest data. It matters a lot since data is changing, and
you want the data to be up to date for your reports. Data Management
Gateway does this for you.
The Data Management Gateway is a Windows service, and it needs
Windows 7 or above for its installation. You can run multiple gateways
within your organization. The gateways can help us in the following
manners:
With the installation done, the gateways get connected to a
Power BI service (existing in “the cloud”) and receive the request
for a refresh.
On getting a request, the gateways act as an intermediary
between the cloud services and on-premises data.

Most of the configuration described above exists in the Power BI Admin


Centre “in the cloud.” So all the activity relating to the gateway machine can
be monitored using “Resource Monitor” or “Task Manager.”
There are two ways to refresh your data, i.e., Schedule Refresh and Refresh
now. This feature is only available for Excel workbooks where power query
is used to connect data from sources, such as SQL (Basic), SQL Azure
(Basic), Blob store (Account Key), Table store(Account Key), HD
Insight(Account Key), Azure Marketplace (Marketplace Key), Facebook
(OAuth), Salesforce (OAuth) & Blank Query(N/A). In Brackets, you have the
Authentication Method, which will come into use as you proceed.
Important: Apart from data sources, other restrictions might impact on
Schedule Refresh option. They are:
You have to build your queries by selecting the tables or views
UI. It means you cannot enter the SQL query manually to
execute.
You have to connect to your data using Power Query. It means if
you cannot connect directly from Power pivot for your data.
When you have your data in power query, then you got to select
the ‘Load to Data Model’ option. Otherwise, if you have loaded
the data to the datasheet, then you cannot use the Schedule
Refresh option.

Steps to Refresh Schedule


Select a Dataset and Click on Open Menu.
Now you can click on Refresh Now to refresh your data right
away. Or, you can click Schedule Refresh. When you do so, you
will be directed to the page where you can schedule your refresh
to keep your data up to date.
Then you have to Edit Credentials to apply the changes. Choose
the Authentication Method as I mentioned above and enter your
Credentials and click on Apply, and your data will be updated as
per schedule.

This is just a start in Power BI; there is still much more to come. So keep on
exploring and stay up to date with the information that matters to you most.
Power BI for
Report Generation and Mail

Introduction
Power BI can be used to build reports adhering to the business requirements.
With Power BI, user can:
Connect to a variety of data sources.
Can bring in the data from these sources and transform the data
which matches the requirement or prep it for further analysis
using tools like Power Pivot or Power view.
Create custom views over the transformed data.
Perform data cleansing/modelling/integration operations.
Data can be imported from multiple log files.
Create a visualization of data using numerous graphical designs
that are already available.

You will mainly focus on connecting to the SQL database, generating


required reports along with visualizations and mailing of reports to specific
groups or individuals.

Setup
Power BI can be downloaded from the following link Power BI download.
The link also has other requirements that specify the software requirements
for installation.
1. After installation, the Power BI Desktop icon appears on the
desktop.
2. Sign in needs to be done.
3. Power BI account needs to be created if not already present.
4. After providing the correct credentials, sign-in is successful.

Getting Started with Power BI


You will consider the SQL database as your source.
There are mainly six parts to it –
Connect to the database
Data Load
Data Refresh
Report Generation using visualization
Publishing the report
Subscription and mailing of the report.

Connect to the database


Click on the ‘Get Data’ tab and a pop up showing all the data sources come
up.
Click on the ‘Database’ option, choose the SQL Server database, and click on
connect.
Provide the required SERVER (SID/database name) and QUERY in the
highlighted text box.
Then provide the credentials of the database you want to connect in the
highlighted text box.
Data Load
The user can see the data in a popup and load the data into the desired
window.
Data Refresh
Then change the source to some other environment and edit the permissions
by giving the credentials.
Report Generation Using Visualization
Select the report tab from the left. Select the objects from the right-side
‘Fields’ panel based on which the report needs to be generated.
Select the type of visualizations. One can also view the details for a particular
object from the graph, which depicts that the report is user-friendly and
interactive as well.

Publishing the Report


Once the report creation step is complete, just use the Publish button present
in the Home tab to start the process.
The data and report, including all the queries, visualizations, and other
features used are combined together in a package. All of them are then
uploaded to the Power BI service.
As soon as the upload gets completed, a dialog box will open, which
mentions that the publishing is completed. Also, there will be a link present
in the dialog box, which helps in navigating to the report directly inside your
web browser.
Report Sharing
The report can be directly shared with an individual or a certain group. Just
fill in the details (Email Id and any optional message) and then Click on the
share button.

Subscription and Mailing of the Report


1. Open the dashboard or report.
2. From the menu bar, Select SUBSCRIBE or select the envelope
icon (present on the right side).
3. The yellow slider can be used to turn the subscription on and off.
The trashcan icon can be used to delete the subscription entirely.
4. You can fill in the message details. The current mail id that you
are using is pre-populated, but you can add others to the
subscription as well.
NOTE: Email addresses in the same domain can be added.

Report Creation in Power BI Desktop with AX 2012


For creating a Power BI Desktop report with AX 2012 R2, one needs to
follow the below steps.
Before you proceed with report creation, make sure that the correct version of
Power BI Desktop is installed based on the machine’s configuration, either
32 or 64 bit.
1. First of all, go to AX -> Organization administration.
2. Then navigate to Setup -> Document management.
3. Finally, move to Document data sources. Open document data
source form.

Document data source form fetches data from three services such as Service,
Query reference, and Custom query from AX and which can be displayed in
reports at the end.
Here you will create a new document data source based on the required data
from the related query.
Now that you have added an existing query of AOT “CustTable” as Query
reference as the data source type and Customer Details as description.
Once the required query is selected and added on document data source form
as above, go to browser/internet explorer and enter the URL of the AX Odata
query service. Make sure this URL is running and displaying the XML code
associated with it. This verifies the Q data query service is running fine from
the AX perspective without any issue.
One can verify against query wise AX Odata query service URL by running
it in the browser.
Once the AX Odata query service is successfully verified on IE, the next
stage will cover report design steps in Power BI Desktop as below.
Open Power BI Desktop. Now click on Get Data option. This will open a
screen which contains various available source data file supported by Power
BI.
As you need to get data from AX using query service, you will select Odata
Feed from the list and click on connect. On the next screen, it will ask to
provide the URL of the AX Odata query service.
Once URL is entered on clicking OK, it will fetch and display all the query
service registered in the AX document data source form.
Here you will select CustTable Odata feed as a data source. In the right side
window, one can preview the data populated from the query. Once the
required query is selected, click on the Load button.
Once data is loaded, it will appear in the Power BI report designer window.
Now, based on the selected visualization-basically report format like Table,
Matrix, Pie chart, BAR Chart- you can display the data in the report. Kindly
note here you can make various field related and report format related
changes in detail as and when required.
Once data is added, you can see it with a preview page.
Also, you can publish this report on the cloud if you have azure subscription
active, which is provided at an organization level.
Below are a few other types of reports created as a sample.
Pie chart report - Currency wise Amount.
Donut Chart report – Customer group-wise amount.

Developing Power BI Reports with NAV 2016


Using the Power BI, you can develop the reports with NAV 2016 data with
pre-defined visualizations. You can easily retrieve the data from NAV and
show it in reports. Before you develop the Power BI report with NAV 2016,
you should verify the version of Power BI. Power BI version should be the
same as OS configuration like 32 or 64 bit.
Steps to Develop a Power BI report with NAV 2016:
Configure the Web service in NAV 2016.
Configure the NAV 2016 Web service in Power BI.
Creating visualization with NAV 2016 data using Web
service.

Configure the Web service in NAV 2016:


1. Open the NAV 2016, then go the below path to configure the
Web service.

Administration/IT Administration/Services
2. From here, open the Web services page. This page contains base
web services.
3. By clicking the New button in the action page, you can create
new web service with object type: Page
4. Add the below details to the page to create the Web service.

Object Type: Page


Object ID: 38
Object Name: It will populate automatically
Service Name: Any meaningful name
Published: check this flag to update OData and SOAP
URL’s
OData URL: It will update automatically
SOAP URL: It will update automatically

Configure the NAV 2016 Web service in Power BI.


1. Open the Power BI Desktop to start the configuration of the
NAV web service.
2. Select the OData Feed from the Get Data option.
3. Now enter the NAV OData web service URL in the OData Feed
and click on Ok.
4. You have to give authentication on Access an OData feed
window as shown below then click on the connect button. Here
you can give two types; one is present windows credentials or
any other alternate credentials like different users' credentials.
5. Now Power BI retrieves all the data from Item Ledger Entry
table and display them on the screen. Click Load.
6. Now Query will be added to the Power BI with all the fields
from the Item Ledger Entry table.
7. From the Query, you can select the fields to get the data in the
Power BI report. (Here I selected Item No., Location Code,
Document No., Quantity, and Document Type.
8. You can see the Power BI report with selected fields.
9. You can change the font size also. You can add the filters to the
Power BI report.
10. Now you have the final Power BI report with
NAV data after using the filters and table style.

Creating Visualization with NAV 2016 Data using Web Service:


Using Power BI, you can create pre-defined visualizations like Stacked
Column chart, Line Chart, Stacked area chart, Pie chart. Now you will create
Item quantity Location wise.

Below are the steps to create charts using NAV data


1. Firstly select any chart type from visualizations.
2. Here you have to assign fields to X-Axis, Y-Axis, and values to
be shown in the chart. Select Item No from Fields; it will move
to under Axis. Now select the Location Code, it will move under
Legend then select the quantity. (Here Axis represents X-Axis,
Legend represents Y-Axis)
3. After selecting the required fields, the chart will be shown below.
The X-Axis represents Item No., and Y-Axis represents
Quantity.
Power BI Report Using SQL Server
Create and design a Microsoft Power BI Report using data source as SQL
Server. You can use the Power BI report to manipulate the data and virtualize
in many graphical and table representations.
You need a minimum version of SQL Server is SQL Server2005 and above.
Consider the Power BI desktop is installed and configured to allow Power BI
reports in the system.
Steps to create Power BI reports using SQL Server
1. Open the Power BI desktop application and click on the sign-in
button.
2. Provide the User Id and password, which has power BI access,
and click sign in to access the Power BI desktop.
3. You will be able to see the Power BI Screen after successful
login.
4. In the Power BI desktop, click on the “Get Data” option in the
action pane and then click SQL Server from the options listed.
5. A window will pop up, enter server and database details, and
select data connectivity mode.

If you want to use existing tables as a data source, select


Import as data connectivity mode.
If you want to write your own query instead of selecting
tables, you can opt DirectQuery option as data connectivity
mode. Here you are using the Import option as data
connectivity mode.
Select data connectivity mode as per your requirement and
click on OK.

6. Once the Power BI desktop is connected to the SQL Server, it


lists all the available tables. Select tables that are required to
design reports and click on the Load button.
Now the Power BI desktop application loads the table and all
the columns within it on the right side under Fields section.
Select a graph pattern from the visualization section by
clicking on it.
Drag and drop the fields into Axis and values section. The
graph gets updated based on the fields and values selected for
the visualization.
You can add multiple graph patterns for data visualization in
your reports.
Now save the report and click on Publish.
You will get Success popup, once the report gets published to
power BI.
To check the published report, you need to sign in to Power
BI online with the same credentials used for Power BI
desktop and go to the Reports tab under “My workspaces,”
and the published report could be seen here.

You can use this application to create and design quick reports with various
gateways to get data. Directly you can access the SQL Server data into this
application to get data. Manipulate with data and get the expected result to
display in the report and design as required with the predefined graphs and
formats.

Integration of Power BI Modules with MS Excel


Components of Power BI
Power BI QnA
Sometimes the fastest way to get an answer from your data is to ask a
question using natural language. In this quickstart, we'll look at two different
ways of creating the same visualization: first, building it in a report and,
second, asking a question with Q&A. We'll use Power BI service, but the
process is almost identical using Power BI Desktop.
Query and Data Management
Having a considerable amount of Pros, Power BI still has lots of challenges
when to be implemented in small applications or accounts.
E.g.:
a) It’s still not the most powerful tool to handle the bulk data.
b) It has lots of in tool options hence making its learning a bit complex.
c) It is not a freeware and requires an Individual account cost, based on no. of
persons using it.
Solution: Well, the possible solution to attain all the great features Power BI
provides is to use the Excel embedded Power BI functions using the add-ins.
Power Bi Implementation over Excel Through Plugins
Below are the add-ons which you can use to attain the corresponding Power
Bi Desktop functions:
For instance, you can use Power Pivot Plugins to attain Power BI Sites
functionalities.
Power Query can be used to get equivalent features to Power BI Q and A and
So on,
How to Enable these Power Plugins
Now, before adding the plugin, they must be downloaded and installed:
Power Map: https://www.microsoft.com/en-in/download/details.aspx?
id=38395
Power Query: https://www.microsoft.com/en-in/download/details.aspx?
id=39379
Power Pivot : https://msdn.microsoft.com/en-
us/library/gg413462(v=sql.110).aspx
Once The Add-Ins have been installed. There are several steps to be followed
to enable the plugins over Excel 2013

Steps to Enable Plugins


1. Go to File > Options > Add-Ins.
2. In the Manage box, click COM Add-ins> Go.
3. Check the Plugins which you want to Enable and click “OK.”

Once Done, Notice that you will get a Power Pivot option over the Excel
Tabs.
If you see carefully, you now have the option of Power Pivot with features
such as
a) Pivot Chart
b) Power Map
c) Power View
d) Power Query

Tips for Using the Power BI Dashboard


Here you will understand Power-BI charts and dashboard. You will get to
know some of the tips in sorting month names and displaying data in the
geographical charts to show distribution. And it also provides an insight on
configuring schedule refresh to update chart periodically.
You intend to work on Power-BI charts and sorting month names based on
month sequence and geographically representing data to show distribution
way.
Before you perform the steps, make sure that your environment meets the
following prerequisites:
Installed Power-BI desktop in your machine
(https://powerbi.microsoft.com/en-us/desktop/ )
Have Power-BI site access to share reports

Sorting Month Name


The month name column is a string column. If you add month name to any of
the filters like “Filter” or “Bar Chart,” then the month names will be sorted
based on alphabets. But as a result, you expect month names should order by
months which comes first.

Steps to Follow
1. If you have a data column to pull data from, then create two
columns, Month and Month Name directly in Power-BI. To get
options to pull Month and Name, you must select the date
column and then click on add column tab. These operations must
perform on “Edit Queries → Edit Queries.”
2. Once you created new columns with the name “Month” and
“Month Name,” replace the “Month” column name with “Month
Number” and “Month Name” with “Month.” And close edit
queries window and apply changes.
3. Create a filtered chart for testing and add a Month column for
filtering the data.
4. Now, select the Month column from rightmost columns and
select Sorting by column as “Month Number.” This operation
performs the sorting of month column based on month number.
5. After updating the sorting, the filter chart that you created earlier
represents data in the way months come.

Showing Data in a Geographical Way


If your data is having geographical information like country, latitude, and
longitude, then a chart can be displayed with few clicks to show information
based on geographical location.
Steps to Follow
1. In Power-BI desktop application from Visualization section on
the left select “Map” chart.
2. After adding a chart to the page, you will see the properties of
the map chart below the charts. Add location property with
location related column from the data set, Size property with the
data column like sales, count, etc. Below are the sample property
values. If your data set has only longitude and latitude, then add
those properties and leave location property blank.
3. After adding the above properties, the data will be represented on
the maps based on the geographical location and the size.
4. To represent the data based on a specific column, then the
column should be added to the “Legend” property. After adding
legend property to the chart, each circle will represent data based
on legend column property.

Schedule Refreshing Data on Power BI Dashboard


Power-BI web site provides different operations to show reports on the
dashboard and sharing with different groups of users, both internal and
external organization users. And also, the most important is the data on the
dashboard to refresh periodically so that the end-users see always updated
information.
Steps to Follow
1. Connect to your power-BI site.
2. Select appropriate data set from the available data sets.
3. Click on the … on the left side of the data set, and it shows
available properties.
4. Click on “Refresh Now” if you want to do manually.
5. Click on “Schedule Refresh” to schedule the data refresh
periodically. This property allows refreshing the data based on
time zone at a time, either daily or weekly. And it required
authentication for the data sources.
6. Set credentials under “data source credentials” to access the data
source. If there are any issues in the connectivity, that error will
be listed there. To schedule an auto-refresh, there should not be
any authentication issue.
7. Click on “Schedule Refresh” and provide “Refresh frequency”
either daily or weekly. Specify “Time Zone” based on your time
zone. Provide Time only if required else can be left empty or can
be removed. By default, the time will be 12:00 AM.
8. After setting all the required properties, then click on “Apply.”
9. Now data refresh happens daily or weekly based on the setting
automatically.

So this is how you can schedule data refreshing on the Power BI dashboard
automatically on a daily or weekly basis. This saves a lot of time and manual
effort.
Dynamic Row Level
Security in Power BI

Introduction to Power BI
Power BI is self-service business intelligence. It provides highly interactive
visualizations, where a user can create reports and dashboards by themselves.
It has an interface that is very much similar to Microsoft Excel but is more
powerful in terms of reporting and dashboards.
It provides a cloud-based Services –known as Power Bi Services, along with
Power BI Desktop interface. The Initial version was unveiled in September
2014.
Power BI service provides fast and easy access to data, supporting inputs
from most of the data sources, and the data can be visualized and analyzed by
anyone.
Here we will discuss points to publish a Power BI report to Power Bi online
dashboard with Row-level security and how to embed this report to the
SharePoint site. This is an open-source Power BI Desktop and Power BI
Service online to allow to build simple to complex report to monitor the
health of the system. You can provide different facilities for the end-users to
visualize the data.

Benefits of Power BI
1. Fast Deployment, secure, and can be integrated with any existing
systems.
2. Pre Build Dashboard templates.
3. Supports both live connections, on-premise, and cloud.

Dynamic Row Level Security


Power BI automatically updates the data in real-time and providing options to
refresh the data by schedule refresh promptly and which will depend on data
sources that you are binding to the Power BI report. Real-time data options
will be available through Azure Stream Analytics, integration, and the REST
API for Power BI. With both mentioned ways, the data can be moved into
Power BI directly.
Power BI Desktop
Power BI desktop is a visual data exploration and reporting too. Using this
reporting tool, users can connect diffident data sources and can generate
reports and dashboards as a single location. Power BI desktop tool can
connect a variety of data sources like Excel, SQL, OData feed, etc. There are
already many supporting formats like charts, table which can help the user in
analyzing the data.
Power BI desktop can connect different data sources like with file (Excel and
CSV), Azure (Azure Services), Databases (SQL, and Oracle Server DB), and
also Facebook and Google analytics.
To restrict data at report or dataset level, Row Level Security (RLS) is used.
To implement dynamic RLS in Power BI, you need to follow the below steps.
1. Create a role and maintain security logic (using DAX
Expression) in the Power BI Desktop tool.
2. Create a workspace & members to it for whom RLS has to be
enabled (Optional)
3. Upload the report to Power BI services and assign users under
the security tab of the dataset.

Here you will use the data from an Excel source, which has two tables,
Sales_Products, and Country.
Sales_Product Table
Country Table
In this example, you have three users Mary (Manager of US & Canada), Dan
(Manager of UK) and John (Admin User)
You will create a report and apply dynamic security. The Manager will be
seeing only those countries which belong to him (or) her.
Steps to Implement Dynamic RLS
Import tables in Power BI and create the relationship by joining the
“Retailer_country” column from the country table with the “Retailer country”
column in Sales_Products.
This relationship is associated with the Manager Id.

Create the report as per requirement:


In example. You have created three slicers (Product Line, Retail Country &
manager) and one detailed report (table view).
Once the report is created and then you will implement security.
Step 1
Create a role and add filter condition.
To do this, go to the modeling tab. Then create a role(Manager) and add filter
condition on the respective table. In the example you have added
“Manager_ID = Username()” condition on country table.
Username() is the DAX function, which will return the username of the
person who is logged in.
By using this filter, the user who has logged in will only be able to see their
own records present in the complete dataset. Here in the example, the
Manager_Id field in Country table defined exactly like the Power BI
usernames. Sales_Products table is the replica of Retailer_Country, therefore
changing any of the tables will also reflect in the other table automatically.

Step 2:
Create an app workspace in Power BI service as Implement_RLS_Group and
add the members into it.
Log into Power BI services (using admin login), click on “Create app
workspace” under workspaces.
Then provide Name, Privacy settings, and members mentioned as below
example.
Example:
Name: Implement_RLS_Group
Members:
[email protected]– Admin (The person who creates the app workspace)
[email protected] – Member (Manager for the UK)
[email protected] – Member (Manager for US & Canada)

Step 3:
Assign users to Power BI Security.
First, save, and then publish the report under “Implement_RLS_Group” in
Power BI. Then, navigate to the “Security” tab of the dataset, which has been
published just now (In your case, the name of the dataset is Store_RLS).
Click on the “security tab,” you will see the role you created in power BI
Desktop. Add the user under that role for whom RLS should be implemented.
The users added on this page will see only those records, i.e., which are
associated with their own username. Whereas for the user who publishes
(admin), the report can see whole revenue details since he/she is the admin.

Step 4:
Test the RLS by logging into BI services using Mary or John login.
You should only see those records that belong to them.
This is how Dynamic RLS is implemented in Power BI.
Simple Row Level Security in Power BI
Power BI Row-level security can be used to limit the report access for
specified users. Also, you have Power BI filters to restrict data at the row-
level; the filters within the roles can be defined.
The security roles can be defined by following these steps:
1. Open the Power BI report and select the Modeling tab.
2. Then choose Manage Roles option from the Modeling tab.
3. Select Create.
4. You should name the role after clicking on the create button as above.
5. Choose the table in which you are going to restrict and choose a DAX
rule to apply.
6. Enter a DAX expressions - this will return true/false. E.g.: [Entity ID] =
“Value”.
7. You can select the checkmark after applying the DAX formula to
validate above the expression content box to the expression as below.
8. Choose Save.
Users can only be assigned roles through the Power BI service, not
through the Power BI desktop. However, the Desktop can be used for
creating the role.
9. After creating a role, the results of that role can be validated in Power
BI Desktop. For this, you should choose View As Roles option from
the Modeling tab as below shown below.
10. You can see and change the view roles using View as Roles dialog as
below.
11. After that, you can select the checkbox for the respective role you
have created and click on OK to apply modifications. The reports will
pull the data appropriate for that selected role only. You can select
other given user checkbox also.
You can bring the data from the below datasets to Power BI.
1. SaaS Data Sources (Software as Service): GitHub, Microsoft
Dynamics CRM, SendGrid
2. Azure Resident Systems: Azure SQL/DW
3. On-Premise systems: SQL, Tabular, Excel, PBI Desktop

Row-Level Security in Power BI


You have to create roles within the Power BI Desktop. You cannot create the
roles in the Power BI service.
When you publish this to Power BI Service, the role definition will also be
published. You can add the users in the Roles created at Power BI Service.

Steps to Define a Role in Power BI Desktop


Step 1: Import Data to Power BI Desktop
From the above web source, I have selected the data from Table(0).

Step 2:
Now select the Modeling tab and click on the Manage Roles.
I’m creating a Role Texas to enable the user to view data only in that State.
You have to create the DAX expression for the same and can validate by
clicking on the tick mark to avoid further errors.
As mentioned above, you cannot assign users within Power BI Desktop; this
can be done only at Power BI Service.
Instead, you can have dynamic security in Power BI Desktop using the
username() and lookup function as in Tabular Cube.

Step 3:
Publish this report and log onto the Power BI Service. Under the datasets,
click(…) on the Model that you have created.
Now you can add the User ID under the members of the Roles created. You
can also test the Role by clicking on Test as Role. (Now you will be able to
see the data only for Texas).
Publishing the Report
1. Select the Publish button.
2. Once Publish has done, it will show below popup for
success confirmation.
3. By using the Link in the above popup, you can open
Power BI online service.

4.

Manage Security on Model


To manage security on your data model, you should do the following steps:
1. Select the security under the dataset.
2. You can add a member to the role by giving an email address or name
of the user. This member should exist within your organization. You
cannot add Groups created within the Power BI desktop.
3. You can remove members also by clicking on X next to their names.

Embed in SharePoint Online


1. Go to My Workspace-> Report-> File -> “Embed in SharePoint
Online”.
2. You will get a URL. Now you should log-in to the SharePoint
site and create a new page.
3. After that, you can see a PLUS button as below to add/embed the
Power BI report to SharePoint.
4. You should place the URL (Which you copied from Power BI
online My Workspace-> Report-> File -> “Embed in
SharePoint Online”) in the below box to embed.
5. Once you are done with the above steps, you can see the Power
BI report in SharePoint online.

Power BI Mobile Development Steps


1. The Power BI mobile applications are where you can view
Power BI content only, but you cannot create it.
2. Power BI Mobile development will be done in Power BI
desktop; then, it will have converted into a Mobile view.
3. Once you are done with required functionalities in Power BI
desktop.
4. Then you can change the view into the phone view by selecting
the option “Phone Layout” from the VIEW tab.
5. Then it will open the visual and Mobile view. You need to
arrange the visuals as you wanted in the Power BI Mobile screen
by drag and drop the visuals into the Mobile view.
6. Then publish the above changes into power BI service as below.
From there, you can access the Power BI service and Power BI
Mobile app as well.
a. Select the Publish button.
b. Once Publish has done, it will show below popup for
success confirmation.
7. You should install the Power BI Mobile app from the App Store
to access the same.

Cons in Power BI Row Level Security


Only Direct Query connections are supported. This doesn’t
support live the connections to Analysis Services. You have
to have them on the on-Premise Model itself.
You have to recreate the roles in Power BI Desktop if you
have them in Power BI services.
Cortana is not supported.
The roles can only be defined in Power BI Desktop.

Therefore, Row-Level Security is just a way to restrict the access of the user.
This can be achieved by applying filters at the row level.
Toggle Button and
Tooltip Features in Power BI

Introduction
In this chapter, we will discuss the Bookmarks in Power Bi Desktop, how to
implement the Toggle button with the Bookmark feature, and how to
implement report Tooltip in Power BI desktop.

Designing a Dashboard using the Imported Dataset


Metrics to be Displayed in the Report
1. To Display gross profit by year
2. To Display gross profit by country
3. To Display gross profit by product type
4. To Display revenue, planned revenue and gross profit by year
in Tabular format
5. To Display revenue, planned revenue and gross profit by
product type in Tabular format

1. To Display gross profit by year


Drag and drop the clustered column chart from the visualizations
pane to full fill this requirement.
Drag and drop the year from fields pane to the axis field of
clustered column chart and drag and drop the gross profit from
fields pane into the value filed of a clustered column chart.
To customize the chart, change the following format options
from the format tab.

To show the data labels turn the Data labels slider to On, then
in the Display units drop-down, select the Millions to show
the values as millions.

2. To Display gross profit by country


Drag and drop the Treemap from the visualizations pane to full
fill this requirement.
Drag and drop retailer country from fields pane to the group field
of treemap and drag and drop the gross profit from fields pane
into the values filed of the treemap.
To customize the treemap, change the following format options
from the format tab.

To show the data labels turn the Data labels slider to On, then
in the Display units drop-down, select the Millions to show
the values as millions.

3. To Display gross profit by product type


Drag and drop the pie chart from the visualizations pane to full
fill this requirement.
Drag and drop product type from fields pane to the legend field
of pie chart and drag and drop the gross profit from fields pane
into the values filed of a pie chart.

4. To Display revenue, planned revenue and gross profit by year in Tabular


format
Drag and drop the table from the visualizations pane to full fill
this requirement.
Drag and drop year, revenue, planned revenue, and gross profit
from fields pane into the values filed of the table.
To customize the table format, change the following format
options from the format tab.

To change the table style, select the format section, and


expand the Table Style card, then Style drop-down, select the
table style whichever is needed.

5. To Display revenue, planned revenue and gross profit by product type in


Tabular format
Drag and drop the table from the visualization pane to full fill
this requirement.
Drag and drop product type, revenue, planned revenue, and gross
profit from fields pane into values filed of the table.
To customize the table format, change the following format
options from the format tab.

To change the table style, select the format section, and


expand the Table Style card, then Style drop-down, select the
table style whichever is needed.

Use Case: The customer wants to display different views on a page when you
click on a button and show multiple metrics on a single tile.
Feature Requirements:
1. Toggle between different visuals in a single page
2. Report Page Tooltip

Toggle Button with Bookmark Feature


Create Bookmark in Power BI Desktop
Add two textboxes from the home tab and name it as Tables and
Visualizations.
Import toggle button images from the home tab to implement a
bookmark feature with a toggle button.
To get the bookmarks pane and selection pane to go to view,
check the bookmarks pane and selection pane.
Click on the Add button to add the new bookmark.

You will get the bookmark.

Click on three dots you will get the options of the bookmark,
then select rename and type Tables.
Add another bookmark and rename it as Visualizations.
Select the Tables to configure tables bookmark.
Configure the tables bookmark.

Select tables, then in the selection pane, click on the eye


button to hide the visuals of graphical visualizations and
toggle button images.
Click on three dots then select an update to update the
bookmark.

Configure the visualizations bookmark.


Select visualizations, then in the selection pane, click on the eye
button to hide the visuals of tables and toggle button images.
Click on three dots then click on Update to update the bookmark.
Configure the Tables Toggle Button.

Select the Toggle button image, turn the Action slider to On,
in the format image section, then select type as a bookmark,
and select bookmark as Visualizations

Configure the Visualizations Toggle Button.

Select the Toggle button image, turn the Action slider to On,
in the format image section, then select type as a bookmark,
and select bookmark as Tables.

Arrange both the toggle button images one under another to feel
like toggle button in the dashboard.

Click on show all in the selection pane.


After the arrangement of images, the toggle button shown
in the below image.
While clicking the toggle button, press the Control key in Power
BI Desktop; there is no need to press the control key while
clicking the toggle button in Power BI Online Services.

When you click on the below button, you will get the
tables.
When you click on the below button, you will get the
visualizations.

Report Page Tooltip in Power BI Desktop


Before you can create a tooltip, you need to enable the tooltip
feature.

To enable the tooltip feature, go to File -> Options and


Settings. Then move to Options -> Preview Features.
Finally, navigate to Power BI Desktop. Checkmark the
checkbox beside the tooltips.
You are required to restart the Power BI Desktop after
making the changes to enable the preview of the report
tooltips.

Note: To implement Report tooltip feature in Power BI Desktop install March


2018 (2.56) or later versions.
Create a report tooltip page.

First, create a report page with the help of the + button


present at the bottom of the screen.
A new template called Tooltip will be visible in the
formatting pane. It will help you to view the report page
canvas size.
You need to modify the Page View to its original size to get a
better view of the tooltip page.
Now choose the View option from the top ribbon. Now go to
Page View -> Actual Size.
Choose the information card present on the Format page. You
can provide the name in that particular field.
Now you can easily create any visuals of your choice to be
shown up in the tooltip.
There is one Stacked bar chart present on the tooltip page. It
also has two other values as Revenue and Planned Revenue
with customized colors, to provide the look you wanted.

Configure the automatic report tooltip.

You need to turn on the Tooltip slider and then move to the
Page Information card. There you can mark the page as a
tooltip.
For visuals in the report, to auto-enable the tooltip to drag the
fields into the Tooltip fields bucket, so that the fields can be
specified for all the reports appearing in the tooltip.
When the mouse is hovering over the sections in the pie
chart, it shows the product type and gross profit in normal
visuals, as shown in the below image.
But with the tooltip configured visual, when the mouse is
hovering over the sections in the pie chart, it shows the
tooltip as Revenue and Planned revenue to that particular
product type, as shown in the below image.

Manually setting a report tooltip.


For setting up the tooltip manually, you can choose the visual
of your own choice. Then navigate to visualizations pane,
followed by format section. Expanding the tooltip card will
show you the tooltip page as per the selected visual.
When the mouse is hovering over the sections in the treemap,
it shows the retailer country and gross profit in normal
visuals, as shown in the below image.
But with the tooltip configured visual, when the mouse is
hovering over the sections in the treemap, it shows the tooltip
as Revenue and Planned revenue to that particular country.

Publishing Reports on Apps in Power BI


Microsoft Power BI is a reporting tool that is used for data visualization. It
can connect to different data sources, produce reports, and publish them for
various organizations. It brings data to life with complete visualization. This
section provides detailed steps for publishing the reports/dashboard for the
members of various organizations or specific individuals using the Apps
Workspace.
For the benefit of the organization, we have tested the scenario and attached
the screenshots of the sample data and the dashboard that comes in the app
once it is published. This can be a potential use case to share the reports like
monthly profit dashboards, quarterly results of the company, etc. with
identified stakeholders.

App Workspace
Apps Workspace will act as a placeholder for published dashboards and
reports. Apps are bound to App Workspace; that is, before you create an app,
you have to have an app workspace. App Workspace is fairly similar to a
group workspace.
The App workspace has dashboards, reports, datasets, excels.
Apps are the published version of whatever is inside of the
workspace.
Apps Workspace acts as a Potential Staging Environment for the
apps.
With Potential Staging Environment, we mean that you can
modify the dashboards, and then the dashboards can be published
to apps.
After the apps are published, you can still make modifications to
the existing dashboards in the apps workspace and can publish
the updated app.
You can manage the users as to who can view the apps.

Creating Apps
Apps are a collection of reports dashboards and which are sent
across to multiple organizations or a group of people or even to
specific people.
Earlier Organizational content Packs were being used for
publishing. However, now Apps have replaced them.
As you create the app in the apps workspace, you grant
permissions on the dashboards.

Step 1: To Create the App Workspace, click on Create app workspace.


Step 2: Fill in the details for creating the apps workspace. You can add
members to this workspace.
Private: Only approved members of the workspace can view the app.
Public: All members of the organization can view the app.
Members can be granted permission:
1. View: Members can only view Power BI Content
2. Edit: Members can edit Power BI Content

Step 3: Go to your Power BI Desktop Version and publish the report to


Power BI Service.
Step 4: Select the destination to be published to:
Visit the report published by Power BI desktop in the Power BI Service and
pin this report to the dashboard.

Publishing App
Go to Workspace -> The app workspace you created -> Click on Dashboards
Click on Publish App.
This will take you through certain steps:
1. Fill in Details, Content, and Access
2. And click on Finish to end publishing the app

This is the App Icon generated through App Workspace. On clicking the app
icon user can view the dashboard.
The end-user/business user can install the app from Microsoft AppSource, or
the admin/creator of the app can directly send the URL link to the app.
Updating the App
For any changes made to the dashboards in the Apps Workspace. The app
needs to be updated.
1. Modify the dashboard: You will have edit report option on the
top of the report to make any changes
2. In the app workspace, you will find the update app option.
3. Update all the options: Details, Content, and Access.
4. Click on Update App.

Unpublish the App


For unpublishing the app, you can click on the option Unpublish App.
Below is the snapshot for the same.
Note:
APPS are created in the APPS WORKSPACE.
To create the app, you will need the Power BI Pro License.
All users need Power BI Pro Licenses to view the app.

Sourcing an Existing Power BI Report into a New Power BI


Report Using Live Connection
Let us understand in detail how to source an existing Power BI report into a
new Power BI report. If there is a requirement of creating a new Power BI
reports by making use of the existing set of the report, then Power BI
provides an option to do this. With this option, the effort of recreating the
data model, and the process of data refresh multiple times is eliminated.
The steps are explained below in detail.
Step 1: Open a new Power BI desktop file and log in using your Microsoft
account.
Step 2: In the navigation bar under ‘Get Data,’ select ‘Power BI datasets.’
This connects to the workspace created in the Power BI server.
Step 3: Select the required report from the workspace and click on ‘Load.’
Step 4: This step adds all the tables which are available in the existing power
BI report to the newly created report. These tables are available on the right-
hand side of the report. And at the bottom right corner, there is a message
displayed saying that the report is connected live to Power BI dataset, report
name, and the workspace name.
Step 5: This newly created file can then be used to create the required
visualizations for analysis.
Advantages
Rework in creating the data model is reduced.
If multiple reports are using a common dataset, then this is one of
the efficient approaches.
Refreshing the data for source. pbix file is sufficient; refreshed
data will be available in the new reports as well. This eliminates
data extraction from the same data set multiple times.

Limitations
Source. pbix file, which is to be used, must be published in the
workspace; any local files cannot be used as a source for a new.
pbix file.
Any changes made in the source. pbix file will be replicated in
the new files too.
If the source. pbix file is deleted in the workspace; the new file
will no longer work.
Power BI
and Share Point

Introduction
This chapter gives a brief introduction on using Power BI Desktop to
generate reports and dashboards and integrating the reports in SharePoint to
achieve Business Intelligence.
Business Intelligence in SharePoint is vast and is achieved with the
combination of SharePoint and Microsoft Power BI in particularly Excel.
This combination of the PBIX file and SharePoint enables us to create
dashboards, reports, and scorecards with simple as well as complex data.
The above-said process is two-fold.
Creation of Power BI Desktop file
Integration with the SharePoint

Power BI is a cloud-based Analytics Service that allows users to analyze and


visualize data with greater speed and efficiency. The data is transformed into
interactive reports, dashboards, or Compelling visualizations.
The Power BI Service is built upon Azure. The Power BI service architecture
consists of 2 clusters.
1. WFE Cluster
2. Back end Cluster

WFE Cluster manages the initial connection and authentications process.


Whereas BE Cluster handles the user interactions. Power BI uses Azure
Active directory for the purpose of user validation & authentication, whereas
Azure Blob and Azure SQL manage the storage of data and Metadata.
Power BI Service is not available as a private internal cloud. However, using
Power BI and Power BI Desktop, you can connect to your on-premises data
sources using on-premises Data Gateway.
Power BI is a Microsoft product which is of twofold:
Power BI downloadable Desktop program
Cloud service (online program).

This document elaborates the steps to install and create Power BI Reports
using Power BI Desktop program

Power BI Desktop
Power BI Desktop integrates the powerful query engine with the online
Power BI Service. It is a Powerful analytics tool designed for windows.
Powerful data connections, models, and reports are created using the Power
BI Desktop. Whereas Power BI Service is used to shares the power BI
Desktop reports to the users to view and interact with them
It is a powerful and highly accessible tool to build robust models and craft
reports.
How Power BI Desktop Works
Power BI Desktop enables the user to connect to different data sources data,
shape or refine the data and represent the data model in the form of reports.
This centralizes the scattered and disconnected data and represents them in
the form of reports. The user can save the work to a file, which is Power BI
Desktop file format (.pbix) file format. This can be shared with other users by
uploading the file to the Power BI SERVICE
Power BI Desktop Installation
Go to PowerBI.Microsoft.com and click on Products and click on Power BI
Desktop. Click on the download button. A PBI Desktop MSI file will be
downloaded to the computer.
Execute the MSI file by following the instructions. A shortcut icon will be
created on the desktop.
Requirements /Limitations
To use the Power BI, few requirements need to be satisfied.
1. Power BI Account – The user has to register to PowerBI.COM
and get created the account
2. Power pivots and power queries are used to generate reports.
3. A website is needed to upload the report. Website can be either
SharePoint / WordPress / any website / web page.

Power BI Report Creation


To start up with, double click the Desktop icon, a welcome screen is
displayed.
Click on Get Data Icon to select the raw input data. It supports many input
data formats like files, Databases, Azure, or Online services.
In this current context, you will take up the SQL Server database as input
data. Select the SQL Server database and click on the connect button. Enter
the database details.
Click on the Load button to load the data to Report.

Views in Power BI Desktop


Report View
Data View
Relationship view

There are three views found towards the left of the Power BI Desktop.
Report View is the View, which shows the actual representation of the data
based on the visualizations of the chart selected.
Data View depicts the data in table format. You can cross verify the data to
be mapped to the report. Intermediate changes are allowed to adjust the data
using the query editor window and need to refresh the data for the same to get
refreshed to the report. The below diagram depicts the sample data
Relationship View depicts the pictorial representation of the relationship
between columns.
The user can also Edit / Combine more than one table using query editor. The
query editor is used to shape and combine the data from multiple tables.
However, the original data source is not getting altered. Based on the
requirement, only the view of this data source is getting altered. This also has
an option of merging queries.
All data manipulation activities are carried out in the query editor. Suppose
the current data type of the column is decimal and need to convert to the
whole number just right-click the column header and select change type and
again select the whole number.
Finally, to apply the query Editor changes, click on the close & apply button
in the Home Ribbon Tab. The Power BI Table is added to the report.

Build Reports
The Report View has five sections.
The ribbon panel displays the tasks associated with the report.
Report View pane enables the user to view the Visualizations
and customize the report.
Pages pane enables you to add a report page.
Visualizations pane to customize the report like applying the
different kinds of charts and axis fields and filters.
Fields pane enables the user to drag query elements and filters to
the report view.

In this context, as the Power BI Table data contains state data, let us create a
Map report. Based on the input data and requirement of the user can create
different types of visualizations like Pie chart, Bar diagram, Line chart, etc.
To create the visualization, Drag and drop the fields column to the location
field, i.e., drag the state column to the report view, A map with the states
defined in the table.
In this example, as you created the selected Map Report Chart in the
visualization, the data available in the table column state is mapped to the
Map control Chart. An in-depth view of the states can be obtained by
applying filters for the states.

Creating Charts For Sharepoint List Data Using Power BI


If the source data changes, you need to update the Excel sheet. The issue
mentioned above can be rectified by using Microsoft Power BI by analyzing
and building charts.
Step 1 – Power BI Desktop Activities and publishing
1. Please download the Power BI desktop version. Once the Power
Bi desktop version is installed successfully, open the same using
the Office365 credentials.
2. Select Get Data → SharePoint Online List. Then a pop up will
open. Provide the Site link and then log in using your credentials
for that application.

Note: Apart from SharePoint online, there are so many options


available for which you have to analyze the data and create the charts.
I have listed out a few of the options available there once you click
on “Get Date.”
➢ SharePoint List – Choose this if your application is an on-
premise SharePoint application.
➢ SharePoint folder
➢ Azure, SQL
➢ Oracle
➢ ODBC
➢ SAP HANA DB
➢ Microsoft Exchange
➢ Microsoft Exchange Online
➢ Dynamic 365
3. Select the list for which you need to represent that data (list
items) in a chart.
4. Once the list is loaded successfully, select the Pie Chart option
on Visualizations (right-hand panel). Drag & drop parameters
(list columns) for which you analyze the data.
5. After completing your chart, you can save the file with the .pbix
extension.
6. In the top ribbon, you can find the “Publish” button. Click on it.

Note: Once you published the chart using the desktop version, the same will
be pushed to the Office 365 Power BI web version, where you need to
perform some actions to set the Refresh time.

Step 2 - Connection update:


1. Open the Power BI web version. Log in using your Office365
credentials.
2. Once logged in successfully, click on Datasets → Data
Connection. On that page, click on Data Source Credentials →
Edit Credentials → OAuth2. Provide your/admin credentials on
the authentication page.
3. Select “Schedule Refresh” and set the below refresh factors as
per your requirement.

➢ Refresh Frequency
➢ Time Zone
➢ Refresh between
4. Click Apply.

Note: At this point in time, you are almost done with the chart preparation in
which the data will be refreshed automatically according to the settings made
above—the only thing you need to do to make use of this chart on the
application page.
Step 3 - Sharing
You can share the chart with your organization or a particular set of people or
use it in the application.
1. Share the Report via Dashboard
a. In the web version Power BI page, you can find
“Dashboard” in the left panel. Click on + plus sign
near Dashboard.
b. In the left panel under “Report,” click on the
report which you want to share. Select the “Pin
Live” page.
c. In the Pine Live page, select the Dashboard where
you want to share and finally click on “Pin Live.”
2. Share Report using Content Pack
a. In the web Power Bi page, click on the gear icon at
the top panel.
b. From the various option listed, select “Create
Content Pack.”
c. Provide the list of users’ email addresses for whom
you want to share the data analysis and select the
respective Report.
d. Click OK.
3. Share the Report using the URL or embedded URL:
a. In the web version Power BI page, you can find
“Report” in the left panel. Click on the report you
want to publish.
b. In the top panel, click on the “File” option.
c. Then click on “Publish to Web.”
d. A pop up will appear, which will provide you the
two options.
e. The link you can send in an email → the direct
URL which you can share with users.
f. Html, you can paste into your blog or website →
the code which you can add in “Embed content” of
your HTMLK page to display the data analysis.
g. Size → You can select the required size. Once you
select the size, the above “Html” code will change
accordingly.

Integrating Power BI with SharePoint


Power BI is one of the Microsoft tools. Here you will explain the process of
publishing a Power BI report to the Power BI online dashboard and to embed
the report to the SharePoint site. Microsoft Power BI Desktop can be
downloaded from here. After installing Power BI desktop, sign in with your
enterprise office 365 account for accessing Power BI Application, which is
also available for a free trial version, also paid one as per business
requirement.
Power BI desktop can connect a variety of data sources like files such as
Excel and CSV, Azure (Azure Services), Databases (SQL, and Oracle Server
database) and SharePoint Online, etc. and create simple and complex
customized business reports.
When the installation is complete, open Power BI Desktop and connect to the
data source and create reports. Save the report in Power BI Desktop format,
which is the “.pbix” extension. Finally, publish reports to Power BI
Application and embed it to SharePoint.
Data Refresh
Power BI frequently updates the data in real-time, if you are using a paid
version of Power BI and providing options to refresh the data by schedule
refresh in a timely manner. If you are using a free version of Power BI, can
schedule refresh by timely manner (eight times per day) not frequently.
Steps to Create Power BI Reports
This section explains how to connect to SharePoint online data for creating
reports.
Connect to SharePoint Online
i. Open Power BI Desktop and click on ‘Get Data.’
ii. Click on “More…” and Select Online Services -> SharePoint
Online List and click on “Connect.”
iii. Enter the SharePoint site URL and click on “OK.”
iv. Select Microsoft account -> Select a site -> Sign in.
v. A login window will open. Provide Microsoft credentials and click
on “Connect.”
vi. Select the lists to generate reports and click on “Load.”
vii. Selected lists get loaded on the right side under “FIELDS.”

Create Reports using Different Visualizations


You can create different types of reports using different visualizations. Ex.
Pie chart, Donut chart, stacked column chart, etc. You can import charts from
the store, from the file. Also, it is possible to import custom visuals to Power
BI Desktop. Below are some of the sample charts.
ChicletSlicer: This chiclet slicer has to import from the store.
a. Click on … under visualizations and select Import from the store.
b. Search for ChicletSlicer and click on “ADD.”
c. Click on the ChicletSlicer, it gets added to the page.
d. Drag and drop fields from lists as per requirement. Here the
selected field is dragged and drop into “Category.”
e. Select the “Format” tab and add the header, change the background
color, font, etc. as per requirement.

In the same way, you will create other reports as per business needs.

Create Relationships between Two Charts


You can create a relationship between two tables in the Power BI. So, based
on the selection of one chart, other charts data get filtered in the reports.
Below are the steps to create a relationship.
i. Click on “Manage Relationships.”
ii. Select the tables.
iii. Double click on the selected tables and select the unique value
field in both tables and click on “OK.”

Create Custom and Calculated Columns in Power BI


You can create calculated columns in the tables. For example, while creating
a chart using two tables or one table, that particular chart needs a column
value that needs to be customized for chart representation. Below are some of
the columns which will be used in Power BI charts.

Create a Calculated Column


Calculated column using the DAX (Data Analysis Expressions) formula in
Power BI and visualization tools. For row-by-row calculation calculated
column will be used. For adding Calculated column,
a. Go to “FIELDS” and right-click on the table and click on “New
Column.”
b. Rename the column and write the formula as per requirement.
Use that column for creating charts.

Create Measure Column


Measures are used to calculate aggregates, such as sum or average of a
column.
a. Go to “FIELDS” and right-click on the table and click on “New
measure.”

Sample Formula: Sum of XY = CALCULATE(SUM(‘X’[a]), (‘Y’[b]))


Conditional Column and Custom Column
The custom column uses the M language. In the custom column, you cannot
perform functions like SUM, AVG, etc. So, it is recommending to use
Measures and Calculated column in Power BI for calculations. For creating
custom and conditional column.
a. Go to “Edit Queries” and select “Edit Queries.”
b. Under “Add Column,” select “Custom” or “Conditional Column.”

Publish to Power BI App and Embed in SharePoint online


This section explains how to publish the Power BI file to the Power BI app
and embed it in SharePoint online.
1. Click on “Publish” and Select a Destination and click on
“Select.”
2. Click on “Open ‘document name.pbix’ in Power BI.”
3. Sign in to Power BI Account; the Power BI app will open with
the published file.
4. For embed into SharePoint, click on “File” and click on “Publish
to the web.”
5. Click on “Create embed code.” Click on “Publish.”
6. Copy the “Html you can paste into your blog or website.”
7. Go to the SharePoint page. Click on “Edit Page.” Click on “Edit
Source” and paste the HTML code.
8. After saving the page, you will get a report on the page.

Schedule Refresh
This section explains how to refresh the data in reports. You can schedule
refresh in a timely manner. Reports can be refreshed eight times per day.
Follow the steps to schedule refresh.
1. Open the Power BI app and gear icon and click on “Settings.”
2. Click on Datasets and click on the file which you need to
schedule refresh.
3. Go to “Scheduled refresh” and change it to “On” and add the
time, click on “Apply.” You can add another scheduled time.

Schedule an Automated Refresh


This is an important feature of PowerBI. If data source (In your case
SharePoint List) gets updated, your report should get updated on SharePoint
Page. You can schedule refresh for your dataset. Click on “…” of your
dataset and select Schedule refresh.
Schedule Refresh
Keep your data up to Date: On
Refresh Frequency: Data can be refreshed daily or weekly.
Add another time: You can set your own time when you want to
refresh your data.
Send refresh failure notification email to me: Check this option
for getting the mail notification when your automatic refresh gets
failed.

Change Data Source


This section explains how to change the data source. Consider the SharePoint
site is migrated to another environment, the Power BI report also needs to be
migrated, in that case, you have to do some changes in the Power BI desktop
file and publish it to SharePoint. Make sure that whatever lists used for
reports should be the same in the Migrated site also. Below are the steps to
change the data source.
1. Open the provided “pbix” file in Power BI.
2. Click on ‘Home’ in the Ribbon menu and go to Edit queries.
Choose ‘Data Source settings.’
3. Click the ‘Change Source’ button.
4. Provide the URL of the SharePoint site and click close.
5. A pop-up to sign in to the portal opens. Choose the Microsoft
account. Select the URL from the dropdown and click sign-in.
Provide the credentials and click Connect.
6. Click on ‘Apply changes’ in the ribbon. A popup listing all the
errors will open. Click on Close.
7. Click the ‘Home’ menu again. Click on the ‘Edit Queries’ option
and choose Edit Queries.
8. A page with all the lists with errors in the left navigation pane
will open.
9. Click on ‘List.’ From the Query settings in the right pane, click
the gear icon near “Navigation.” Select ‘List’ from the pop-up
and click OK.
10. The Query Settings will now have “Renamed
Columns1” in addition to “Renamed Columns,” which was
present earlier. Delete “Renamed Columns.” (If there are more
than 1 Renamed columns with different suffixes, delete all the
older ones and retain only the newly created one.)
11. Repeat steps 8 and 9 for Waves, Sites, and
Libraries. [Note: The warning sign in the left navigation will be
changed to the list icon].
12. Click on Close & Apply.
13. Once the page is loaded, click on Publish and
follow the steps explained in Publish to Power BI App and
Embed in SharePoint Online.

Share the SharePoint Page with PowerBI Report Embedded in


It
SharePoint page can be shared with office 365 users (SharePoint Online
users). All users should have Office 365 account with PowerBI service.
However, Power Bi report is embedded into this SharePoint page, to view
these reports to SharePoint Online users must have access to PowerBI reports
also.
It means that you need to manage permission on both locations, PowerBI
report, and SharePoint Online Page.
Access to SharePoint: Open SharePoint Page where your PowerBI report is
integrated. On the right hand, there is a SHARE button. Click on it. One
popup will open to add users for whom you want to give permission to this
page.
Enter name or mail ID’s of office 365 users, select permission level as per
your requirement, and click on Share.
PowerBI Permission: The user also needs permission in PowerBI to access
the report. To handle the permission, you can use Manage Permissions. Go to
Datasets and click on the manage permissions. Click on Add Users.
Enter office 365 user’s name or mail ID whom you want to share the
PowerBI report. Click on Add. After assigning permissions on both locations,
the user can view or edit the report as per the permission level.

Hosting of Power BI Reports in SharePoint


The main prerequisites to host the Power BI Report in SharePoint are:
The SharePoint site should have been created to host on the site.
The Power BI Account should be created

To Host the power BI Reports in SharePoint, you need to publish the report.
To publish the report, open the report in Power BI and select publish to Web
option. This will open up with a dialog box showing Embed code and iframe
details. Make a note of these details.
Go to the SharePoint site to which the Power BI Report needs to
be hosted.
Click on the settings icon in the site and click on Add a page
option to create a web page.
Give proper Name and open the page in Editable mode.
Click on the insert web part option from the Ribbon.
Go to the Media and content category and in the parts select
Script Editor option.
Script Editor is added to the page.
Click on the Edit Snippet link in Top Right of the page.
Now copy the HTML iframe code and paste it to the snippet
editor.
A representation view of the image will be shown on the page.
Finally, click on insert, save, and publish the page in SharePoint.

Publish the Power BI Report on Dynamics 365


Microsoft Power BI is a suite for business analytics. You can use Power BI to
analyze the data, explore data, and create rich reports quickly.
A business analyst or a developer can use open data protocol (OData)
endpoints to create Power BI reports. Consider the Dynamics 365 for
Operations application is configured to allow Power BI reports.
1. Open the Power BI desktop application and click on the sign-in
button.
2. Provide the User Id, which has power BI access and clicks the
sign in.
3. A window opens prompting for the password. Enter the
password and click on the sign to access the Power BI desktop.
4. In the Power BI desktop, click on the “Get Data” option in the
action pane and then click OData Feed from the options listed.
5. A window pops up for OData Feed prompting to enter the URL.
Provide the URL of the Dynamics 365 application by appending
“/data” at the end and click on the Ok button.
6. An Access window for OData opens where the Sign-in can be
changed, or you will be prompted to sign- in case it is not done
in the first step when opening the Power BI Desktop. Now click
on connect.
7. Once the Power BI desktop is connected to the OData URL
provided, it lists all the tables available from the dynamics365
application.
8. Select the required tables from the list and click on “Load.” Now
the Power BI desktop application loads the table and all the
columns within it on the right side under Fields section.
9. Select a graph pattern from the visualization section by clicking
on it. Drag and drop the fields into Axis and values section. The
graph gets updated based on the fields and values selected for the
visualization.
10. Now Click on Publish. You will be prompted to
save the report if it is unsaved. Once you save the report, it gets
published to power BI.
11. Sign to Power BI online with the same
credentials used for Power BI desktop. Navigate to the Reports
tab under My workspaces, and the published report could be
seen. Click on the report published from Power BI desktop. Once
it opens, click on the Pin Visual option.
12. A window opens, asking if the report has to add
to an existing dashboard or a new dashboard. Select New
Dashboard and provide the name for it. Click on the Pin button.
13. Navigate to dashboards under My workspaces,
and the newly created dashboard is available. Click on the
SalesLine Analysis dashboard once it is available in the Power
BI online dashboards, Open Dynamics 365, for operations.
14. Create a new Workspace by right click > Add
Workspace. Provide a name for the New Workspace.
15. Now click on the Workspace “Power BI Report
Space” that is created.
16. Now for the power BI control to be available in
the workspace, navigate to the below path in the workspace
created. Options> personalize this form> click on + sign> Allow
Power BI control> click OK.
17. You can see a Power BI Tile in the workspace.
Click on the “Get Started” option. It opens a Tile Catalog,
showing all the Power BI dashboards that can be used in
dynamics 365.
18. Now select the dashboard by clicking the title.
Now click on the report, so it is Ticked and Click on OK. The
dashboard selected is now displayed in the New Workspace
created. You can add multiple graphs/reports to the same
dashboard.

You can use this tool to analyze and create quick reports and remove the
performance bottlenecks to improve the performance of the whole
application.
These reports are not only rich and interactive and but also users can make
changes without having to rely on another person. Users can pin reports to
workspaces themselves.
Power Query
for Report Generation

Introduction
Almost all of the testing projects require data to be tested/analyzed based on
the requirement. Many of the testing applications require the testers to set up
data, whether it might be simple or complex. This document helps to
understand how a user can easily get different data Sources for Data
Preparation/ Test data, modify the data as per the user’s needs (like removing
a column, changing a datatype, or splitting a single column) and for Data
analysis.
Power queries can act as an ETL tool and also can be used to build reports
adhering to the business requirements. It is a part of the larger domain
provided by Microsoft, i.e., Power BI. A power Query is a user-friendly way
to play with the data. Power Query is a free Excel add-in that allows the user
to import data into excel from many data sources, allow data modification,
refine data, and load to the data model. This applies to Excel 2016, Excel
2013, and Excel 2010.
With Power Query, user can:
Connect to a variety of data sources.
Can bring in the data from these sources and transform the data
which matches the requirement or prep it for further analysis
using tools like Power Pivot or Power view.
Create custom views over the transformed data.
Perform data cleansing/modelling/integration operations.
Data can be imported from multiple log files.

This section will mainly focus on connecting to the ORACLE database and
generating excel reports.
Setting up Power Query
Power query can be downloaded from the following link Power Query
Download. The link also has other requirements that specify the software
requirements for installation.
1. After installation, navigate to the FILE menu. Click on
OPTIONS to enable the use of add-in.
2. Now select the Add-Ins tab, which is located on the left side of
the screen. Go to Manage Combo Box and then click COM Add-
Ins. Finally, select the GO button.
3. When you have the dialog box on your screen, check the
checkbox for “Power Query for Excel.” Once done, select the
OK button to continue.

4. After doing the above steps, there will be a new Power Query tab
present in MS Excel, as shown in the below image.

Power Query for Excel


You will consider the ORACLE database as your source.
There are mainly three parts to it –
Connect to the database
Data Load
Data Refresh

Connect to the database


Under the Power Query tab, click on FROM DATABASE icon as shown
below:

Click on FROM ORACLE DATABASE. Provide the SERVER


(SID/database name) and QUERY.
Then provide the credentials of the database you want to connect.
Data Load
The user can see the data in a popup and load the data into the desired excel
sheet.
Data Refresh
Right-click on the workbook query and click EDIT.
A Query Editor window pops up. Click on the Data Source settings tab.
Then change the source to some other environment and edit the permissions
by giving the credentials.
After successfully providing the credentials and connecting to the database,
refresh the preview and then close the query editor and load the data to the
main sheet.
The user can also refresh the data from a link button present in the workbook
query window tab (right side of the screen near the black arrow).
Simple Installation
Excel 2016 - Power Query is a built-in tab in Excel 2016. It has
been renamed to the Data tab. It is known as “Get & Transform”
in Excel 2016.
Excel 2010 & 2013 – Power query has to be downloaded from
the below link and installed.

http://www.microsoft.com/en-us/download/details.aspx?id=39379
Once the installation is completed, open excel, and the user will be able to
access the Power Query tab.
Incase power query tab is missing, follow the below steps:
1) Go to File > Options > Add-in.
2) Select COM Add-ins from the Manage drop-down.
3) Click the Go button.
4) Check Microsoft Power Query for Excel checkbox and Click on OK.
5) Now power query tab will appear on the screen.

ETL Process
ETL (Extract, Transform, and Load) is a process where data is extracted from
various data sources and transformed in a proper format for analysis and
querying and loaded into the destination.
Extract
Data Sources
Power query can transform both structured and unstructured data from
various sources. Different sources include Excel, Web Page, XML file, Text
File, Folder, HDFS, Facebook, and from different databases such as SQL,
Oracle, DB2, MySQL, Sybase, Teradata, etc.
If you want to import data from the web, you need to enter the URL in the
textbox, so that the user is navigated to the desired web page.
The contents will be loaded in the form of tables on the extreme right of the
sheet under the Navigator section. If you hover over the tables specified
under the navigator, details of the table, along with the column names, will be
specified in the display box for a quick view to the user.
Due to access restrictions and for easier understanding, you shall import data
from another Excel file. Say, you import data from Excel. Data imported
from excel will be displayed under Navigation pane. Users can load multiple
files by selecting the ‘Select multiple items’ checkbox and checking the
desired files.
‘Load To option’ in the navigator pane allows viewing the data in the way the
user wants. Clicking on ‘Load’ will load the data.

Transform
Query and Design tabs will get enabled to the user.
Query tab is used for the transformation/shaping of data.
The design tab helps in improving the look and feel.

Once data is loaded, it will get displayed on excel automatically. The count of
the number of records loaded will be displayed under Workbook Queries.
Query Tab
Click on ‘Edit Query’ in the Query tab. Users can now modify/transform data
without using the normal excel formulas and coding.
Operations in the Query tab
Below are the operations that can be performed in Edit Query:
1. Choose Columns - Allows the user to select the columns that are
needed by the user.
2. Remove Columns - Remove the selected columns from the table.
3. Remove Other Columns - Remove other columns from the table
except for the selected ones.
4. Move - Columns can be reordered.
5. Keep Rows - Keep top rows/Keep bottom rows/ Keep a range of
rows- based on the number of rows specified.
6. Remove Rows - Remove top rows/Remove bottom rows/
Remove alternate rows- based on the number of rows specified.
7. Remove Duplicates - Remove rows containing duplicate values
for the selected columns.
8. Split Column -Split values in the selected column based on the
delimiter/number of characters.
9. Group by - Group rows based on the selection of columns.
10. Datatype - Change datatype for the specified
column(Text, Decimal, Whole Number, Logical, Date, Time,
Date/Time/Timezone, etc.).
11. First Row as header - First row of the column
can be used as a header.
12. Replace value - Existing value can be replaced
with the specified new value.
13. Append – Consolidate data from different
sources and from multiple tables into one.
14. Merge – More like a join operation to add data.

Values can also be sorted ascending/descending.


Merging Two Tables
If you want to merge two columns together, given the need, Power query will
evaluate the selection and will give the results on how many matches the
selection will return.
To Merge Orders and Returns table, click on the Merge option present in the
‘Power query’ ribbon. Select the tables and matching columns to create a
merged table. Matching column act as a join condition.
A new column will be added at the end of the table, which has to be
expanded to see the original results.
After expanding the columns, you can see the columns that are merged.
Unmatched rows are displayed with the value null.
Load
Close and Load: Save the changes to the query, close the query editor
window, and load the data to a new workbook.
Applied Steps
The applied steps section shows the operations applied to the data in
sequential order, which helps to keep track of the transformation process.
These steps can also be deleted.
Thus power query excel makes it easy to get data in good shape. It has all the
common transformations. This is of more use comparing to VBA macros
which use coding in data transformation.

Synoptic Panel in Power BI Desktop


One of the key components of Intelligence from Business Intelligence is to
find trends and patterns over various periods of time and be able to compare
them across. These “Periods of time” have a large generic form or structure
such as Month over Month, Year over Year, Same Month Last Year Vs. This
year. Power BI Visualizations require DAX’s Time Intelligence functions to
calculate through them. The formulae using DAX functions take different
shapes depending on the type of measure as being additive or semi-additive
or non-additive. Bringing Contexts and Filters in the mix can sometimes
make it very complicated to understand.
Let us see synoptic panel by SQLBI and their usage in Power BI Desktop.
And also how to customize a visualization using it in Power BI Desktop.

Synoptic Panel by SQLBI


A synoptic designer is a tool of Synoptic Panel by SQLBI. It will allow us to
draw customized areas, maps, images, etc. and export it as SVG file to Power
BI. Then using it, able to color the different areas based on your dataset data.
The Synoptic Panel connects regions of the image with attributes in the
dataset and coloring the regions or with a saturation of a color related to the
value of a measure. For any image, you can draw custom areas or regions
using the Synoptic Designer tool, and an SVG file is generated, which you
import in the Synoptic Panel.
Now you will try to implement one of the travel systems which owns cars;
you need to find whether the seats are available to book the cab on a sharing
basis or not.
1. Get the desired image on which the dashboard has to be created;
here, it is the car seating arrangement. Let the image look as
shown.
2. Now open the URL https://synoptic.design/
3. Drag the image or click on the insert an image path/URL, then
navigate to the image file location and import.
4. Click on Draw new areas icon. Then go clicking the areas
required. Give the appropriate names to those regions as per the
data in the dataset. Note: The region names and the data values in
the dataset should be the same.
5. You can automatically say the designer to detect the remaining
regions by clicking on the tab “automatically detect bitmap
areas,” or else you can detect them manually as earlier. And then
give appropriate names accordingly.
6. Now click on EXPORT TO POWER BI. Click on DOWNLOAD
SVG and save it in the desired location.
7. Now download and import “Synoptic Panel by SQLBI….”
visualization and click on it. Select a few of the columns as per
the requirement; it will ask for a select map or Gallery. Select
one of the options. I click on the Select map, and I will import
the SVG file created using the designer in the earlier step.
8. The column values matched with map region names come under
Matched areas.
9. You can specify the colors of the matched and unmatched
regions to a single color or multiple colors in the Format tab, as
shown. Enable the Labels button to show the values.

Now you will try to implement the colorization of the regions based on their
availability. I.e., if the seat is available, it should display in green; it is not
available or booked, show it in red and if it is the driver seat, show it in
yellow.
For this, I am adding a new column as below.
Color = IF(Car[Status] = "Available", 1, IF(Car[Status] = "Booked", 2, 3))
Place the columns values as shown, and give the values for State 1 From = 1,
To = 1 and color = Green, for State 2 From = 2, To = 2 and color = Red and
for State 3 From = 3, To = 3 and color = Yellow
Similarly you can achieve any desired customized visualization as per the
requirement using Power BI Desktop.
Filters and Slicers
in PowerBI Report

Filters in PowerBI
Filters in PowerBI are used to view the data only, which you want to focus
on. Filtering will remove the data from the visual temporarily, and it can be
viewed back once the filter is opted out. Filters enhance the visual
representation of the report.
There are four types of filters in PowerBI.
Page filter
Visual filter
Report filter
Drillthrough filter

Different Types of Filters in PowerBI


1. Page Filter

Page filter applies to all the visuals on the specific report page. In a PowerBI
report, you can create multiple pages. As the name suggests, this page filter
gets applied only at the page level. Let’s consider you have created a
PowerBI report of multiple visuals from a single dataset on the first page.
If you want to apply the filter to another visual from the same page
(populated from the different dataset), the relationship has to be created for
both the datasets to enable the page filter.
Now when you apply the page filter, all the visuals get filtered based on the
filter. You can also have multiple columns added to a page filter.
Example: In the right pane (VISUALIZATIONS), under the FILTERS, you
will be able to see the PAGE LEVEL FILTER. Drag the necessary column
from the dataset and place it in the filter.
Now once you select a specific data from the Page-level filter (e.g.,
Australia), the whole page with all the visualizations gets filtered.

2. Report Filter

The report filter applies to all the pages in the report page. A report filter is
very much similar to the page filter. While in page filter, it applies at the page
level. In the case of the report filter, it gets applied at the report level. All the
other properties remain the same.
Example: In the right pane (VISUALIZATIONS), under the FILTERS, you
will be able to see the REPORT LEVEL FILTER. Drag the necessary column
from the dataset and place it in the filter.
Now once you select a specific data from the Report level filter, the whole
report with all the visualizations gets filtered across the pages.
3. Visual Filter

The visual filter applies to a single visual on a report. This filter gets applied
only at the visual level, even if you have created multiple visuals from the
same datasets.
When you apply the visual filter, only the specific visual gets filtered based
on that filter. Similar to page filter, you can have multiple columns added to a
page filter.
By default, all the columns in that visual will get added to that filter. In the
right pane (VISUALIZATIONS), under the FILTERS, you will be able to see
the VISUAL LEVEL FILTER. All columns in the dataset will be added by
default in the filter.
Once the visual filter is applied for the country ‘Australia,’ only the specific
visual is filtered, whereas all the remaining visuals remain the same, not
filtering any data.
Generic Properties for Page, Report, and Visual Filters
There are two filter types in the Page, Report, and Visual filters.
1. Basic Filtering
2. Advanced Filtering

Basic Filtering is filtering the data by just selecting the column values present
in the dropdown. Advanced filtering consists of many options such as
‘contains,’ ‘starts with’ etc.
1. Drillthrough Filter

With the drillthrough filter in Power BI Desktop, you can navigate from the
one page with high-level data to the destination report page with detailed data
- such as a product, or sales, or country. From any report pages, you can click
on data for that entity and drillthrough to the destination page.
Drillthrough filters help us in situations where you have to navigate from the
main page with high-level data to the detailed data visualization.
Let’s take the below example to see the functionality of the drillthrough filter.
Consider you are having two pages in the PowerBI report named as
‘Highlevelview’ and ‘DetailedView.’ In the DetailedView, you have all the
salesdetails information, which includes the details salesperson, color,
country, and salesprofit.
DetailedView Page
In this DetailedView page, you are having all the sales details with respect to
country, salesperson, color, etc.

Highlevelview
In the Highlevelview page, you have the map visual in which you have added
the ‘Country’ as location and ‘Color’ as a legend in the fields.
We have added the Country and Color columns in a high-level page, as we
need to filter the detailed data in the DetailedView through these two fields.
Now to enable the drillthrough filter option, you have to add those two
columns in the ‘Detailedview’ page where you have the detailed information
of data.
Once you add the two columns in the destined page, a back button will be
enabled and shown on the page. Any image can replace this back button. If
you want to replace this image, you have to insert the new image on the same
page and make the action as ‘Back.’
In the right bottom of the page, you have added the columns added in the
Drillthrough filter. Now when you right-click on any color area in the map
and click on the DetailedView, it will take you to the DetailedView page.
(Country- Australia, Color: Green).
Now you will be able to see the DetailedView page. Your DetailedView page
with all the details is filtered based on the (Country- Australia, Color: Green).
A back arrow on the top can be used to navigate back to the Highlevelview
page.

Slicers
Slicers are the types of visualization in PowerBI, which helps the readers by
enhancing the readability of the report. A slicer is another way of filtering,
which will narrow the data populated in the dataset.
Instead of creating multiple reports dataset to a different set of readers, you
can use slicers to slice the data according to them.
Slicers can be used to:
Display the most often used filter on the report.
The currently filtered state is much visible.
Filters the necessary data and hide the unwanted in the data
tables.

Though Slicers are similar to Filters, it has its own advantages and
limitations. Usage of Slicer/Filter must be decided based on the user’s
requirement.
There are different types of slicers available. You can import the slicer from
the PowerBI visuals. Some of the examples are given below.
Chiclet Slicer – Displays image/buttons that act as a filter.
Timeline Slicer – Graphical data range selector for date filtering.
Attribute Slicer – Visualize and search data attributes
Hierarchy Slicer – Slicer with a hierarchy of different fields.

Assigning Slicers to Selective Visuals:


We have an option in PowerBI to assign a slicer to selective visuals. If you
do not want to filter the visual even when sliced, you can opt-out that visual
from that slicer. To enable that, select the slicer visual ‘Country,’ click on the
Format tab, and then select ‘Edit Interactions.’
Now you have enabled the filter for all the visuals except ‘SalesProfilt by
SalesPerson and Country.’ If the ‘Filter’ option is selected, that visual will be
enabled for that visual. If the ‘None’ option is selected, that visual will not be
enabled for that visual.
Once you are done with the changes, when you slice the data using the slicer,
it will filter all the visuals except the one which you marked as disabled. In
the country slicer, select ‘Australia,’ and all the visuals have been sliced other
than ‘SalesProfilt by SalesPerson and Country’ visuals.
Syncing Slicers
In PowerBi, you can also sync the slicer across the pages. If you have to slice
the data in the visuals across all the pages using a single page, you have to do
the below steps.
Click on the slicer.
Click on the View tab and enable sync slicers.
In the right pane, sync slicers will be enabled. Select the
pages which you enable the slicers.

Slicers vs. Filters


Use Slicer when:
1. Number of Values in the column is limited.
2. If there is any frequently used column to filter data.
3. The user needs to know by glance for what scenario data is
filtered.
4. The dashboard is used more in mobile PowerBI applications.

Use Filter when:


1. Data volume in the datasets is larger.
2. The column is not used frequently.
3. PowerBI Dashboard is used more in laptops/desktops.

How to Toggle in Power BI Report Using Images


Power BI is an enhanced BI reporting tool which helps us to fetch the data
from different sources to create and publish dashboards and BI reports.
Toggling in Power BI
Most of the business users’ requirement is to view the data in different
visuals such as charts, tables, graphs, etc. With default configurations in
Power BI Desktop, you are not having the option of Toggling between a chart
and table, or table to graph or vice versa. But in Power BI toggling can be
done with the help of Bookmark and Selection Pane.
Steps Involved
Step 1: Create a Power BI report with necessary datasets from the sources.
Step 2: Create tables, charts, and graphs based on your requirements.
Step 3: Create some images in the Power BI page for toggling.
Step 4: Enable Bookmarks and selection pane in the Power BI report.
Step 5: Link the images to bookmarks.
In Toggling, you map an image with bookmarks, where bookmarks are
mapped with visuals. So when you select an image in your report, it will
display the visuals which are mapped through bookmarks.
Assuming you have already created a Power BI report with necessary tables
and charts, let us see the process from the 3rd step.

Step 3: Create images in the Power BI page for toggling


How to add text box and images in Power BI Report
To add a text image, you have click on the ‘Image’ button on the HOME tab
of Power BI desktop, browse and select the image. Place it accordingly.
Similarly, create a ‘Text box’ and type in whatever text you want to put in.
Now, considering that you have already populated the required charts, tables,
and other required images in addition to the previous step, your Power BI
desktop will show everything on your page. (All the images, tables and
charts).
Step 4: Enable Bookmarks and selection pane in the Power BI report
GO to the VIEW tab of the Power BI desktop and enable the ‘Bookmarks
Pane’ and ‘Selection Pane.’ Now in your Power BI desktop, you will be able
to see the SELECTION and BOOKMARKS pane on the right-hand side. In
the SELECTION pane, whichever visual you have on your page will be
listed. In the BOOKMARKS, it will be empty unless you create one.
How to create a bookmark
Click on the Add button to create a BOOKMARK; a bookmark will get
created with the default name. You can rename or update or do any of the
options based on your requirement by clicking the three dots near the
bookmark.
Once you are done with creating a bookmark, you should select the images,
which have to be mapped to that bookmark.
You can do that by clicking the ‘eye’ symbol in the selection pane. Visuals
with the ‘eye’ symbol will be mapped, and visuals with the ‘hyphen’ symbol
will be hidden for that bookmark. Click on Using the same way.
Step 5: Link the images to bookmarks
As you have created all the necessary bookmarks, now you have to link an
image with the bookmark so that if you click that image, it will show you the
visuals which are bookmarked.
You can select the image (left bottom) in the Power BI report and map it with
the bookmark ‘HOME.’ So when you click that image (HOME), it should
display the images which are mapped to the bookmark HOME.
To do that, first, select the image, do the below changes in the third pan
‘FORMAT IMAGE.’
1. Make the action type as ‘ON.’
2. Select the Type as ‘BookMark.’
3. From the bookmark dropdown, select the bookmark ‘HOME,’
which you have created earlier.
4. Now do the same linking process of the image to all the
necessary bookmarks. Once you are done with linking all the
images with bookmarks, save and close the other pans.

If you click the image, it will show you the visuals which are marked in the
bookmark in which the image is linked.
Cognos Self Service BI

Self Service BI: Overview


“The specific function designed within the BI environment to give BI users
the ability to become more capable and less relied on IT.”
To meet this emerging need and improve time to build, companies are
looking for different choices for BI. One such approach is to build the
infrastructure that supports the BI environment in which the Power users can
collaborate specific sets of BI reports, Dashboards, Logic, and analytics with
less dependence on IT.
The advantage of self Service BI is to extend the scope of BI applications to
address a wider range of business users and help them solve the needs and
problems of complex scenarios. At the same time, this extension must
support the information workers need for a personalized and collaborative
decision-making framework.
It lists down a few business scenarios where self-service capabilities of the BI
platform make a difference to an organization’s ability to meet its business
goals. After establishing a business case for self-service BI, the document
gives a brief introduction to Self Service BI environment. Without going into
technicalities, it lays down the key features that can enable a self-service Bi
environment.
Self Service Business Intelligence is much under discussion these days. Users
find traditional BI platforms to be too complex and technical for them to use,
and at the same time, the IT team finds it difficult to meet the ever-rising
information needs of business users. The self-service environment aims at
removing the distance between the people who generate a report and people
who actually use it.
To meet the rising information and analytical needs, there is a need for BI
users to be more empowered and BI tools to be more exhaustive. From a
functional point of view, three things make the base for a self-service
environment - an interactive and simple user interface, a set of tools that
serve changing needs and accommodate new work practices, and a robust
backend data support to allow the first two. There are several tools from
various vendors that provide self-service capabilities in some form or
another.
Four key objectives of Self Service BI:
1) Make it easy to use.
2) Make it easy to access data.
3) Make the DW solution fast to manage and deploy.

Self Service BI: Challenges


Implementing Self Service BI is more difficult than BI professionals
anticipate.
Differing User Requirements: Business requirements keep changing. BI
Solutions must be implemented quickly to take advantage of the business
strategy. The timely market solution is the key to Self Service BI Solution’s
success.
The Balance: Self-service BI requires clean, comprehensive, and integrated
data, and a few of the key factors are:
Know your audience: There is no “One size fits all solution in
BI.”Different BI users need different types of solutions to suit
their needs. Different business user interprets data differently

Training: A significant number of Self Service BI Solutions fails


because of proper training. Training doesn’t pass on the exact
know-how of the Tool and data.
BI Tools: BI Developers need the ability and functionality to
create reports and dashboards; however, the BI Power users or
casual users need the Tool features and functionality to be simple
and easy to navigate through. In the majority of cases, Self
Service BI Solutions have often implemented a good BI tool but
has not able to reap the benefits of self-service BI.
Data Governance
a) Poor Data Quality: Abnormal definition of the same metric has
been a critical reason in getting poor data quality. The same
metric may have various definitions across different departments
of the same organization. The definitions or KPI can be created
based on functional rules which are based on functional rules
which are the same across the whole organization.
b) Data Integration: Data Integration rules comes into picture when
data has not been formatted before aggregating
c) Logical Errors: Logical errors are the addition of the data
integration issues where a KPI or metric definition is taken out of
content to do the analysis.
User can’t afford to wait:
Solution: Get Self-Service Right! Training should involve the
Functionalities of the tool and which data elements and fields can help them
with their analysis. It should also include security policy recommendations.

Why Self Service is Required in Today’s World


This trend of Self Service BI was started by Business objects with Web
Intelligence and was marketed as an Ad-Hoc reporting tool. This tool did
provide the business users the capability of Self Service BI; however, packed
with powerful features; it became difficult for business users to understand
queries and functionality.
With changing times and usage patterns, features of BI have changed. Over
the past decade, BI has evolved from the crude Integrated Development
environment to tools that have been easy to use and navigate.
Business users or analysts can now use these tools to analyze the data, create
reports, and dashboards.
Primary reasons why Self Service BI is required:
Next-Generation Solutions: BI tools provide excellent support
for smart analytics and dashboard using the Big Data
Time to Value: BI Solutions needs to be applied quickly to take
advantage of changing business scenario
Cost Optimization: Optimized hardware and software solutions
with a lot of built for purpose Analytical solutions help
businesses with less IT intervention.
Data Understanding: Self Service BI Tools provide a lot of
visualization features that help them understand the data better.
They can create any number of graphs, charts, and analytical
functions that help them see the data better.

Self Service BI is a BI platform that allows BI users to be more self-reliant


and less dependent on the IT team of their organization.
What Makes the BI Self Service
In simple words, Self Service BI is nothing but a user being able to get the
data that she wants in a format she understands, and within the time frame,
she has. Now there is a range of functionalities of a BI platform that enable
business users to be more self-sufficient and BI tools to be more user-
friendly. How many of these are achievable within the cost and a
performance boundary is a matter of separate discussion, though.
If you don’t go into technical details or in a layman’s language, a self-service
BI platform should be able to serve the following needs:
It should have a very interactive, user-friendly, and intuitive user
interface.
It should have advance features to support evolving business
needs.
It should have a robust backend that can support the above two.

The Business Case for Self Service BI


The job of IT is to support the business. In the end, the worth of any IT
solution lies in the amount it can contribute to the bottom line of an
organization. Hence let us go through a few business scenarios where an
organization’s existing Business Intelligence infrastructure finds it difficult to
support day to day information needs of business users.
I want it quick
An organization ‘ABC Motors,’ a car manufacturer, faced a drastic reduction
in top and bottom lines during the recession, which started late 2008. Due to
dropped sales and changing consumer preferences, it accumulated a huge
amount of inventory, especially those of high-end multi-utility vehicles. On
the one hand, it had to cut its IT spending by reducing IT headcount. On the
other hand, it needed to enhance its responsiveness to changes in the volume
and patterns of the demand.
For this responsiveness, its executives need to dig into data and do various
kinds of analysis to find out new business trends and to respond to them
quickly. Calling an already understrength IT department to fetch a few new
reports in quick time was an exercise in vain.
I want to do it my way
John, a marketing manager at online travel and ticketing company, wants to
regularly perform varied kinds of analysis on his sales data to find the impact
of various environmental conditions. Those conditions include the time of
year, time of travel, weather conditions, holidays, promotional schemes,
competition’s promotional offers, new advertising campaigns, etc. The
analysis and reports that he needs to keep changing every day. His need is to
play around with data as and when he wants.

I want to drill-down whenever I want


Dan is an executive assistant to the CEO of a large corporate house. While
preparing presentations for regular meetings, he usually needs financial data
at a very high level (Ex: Business Vertical, Territory, etc.). Huge reports with
data presented at a very granular level are of little use for him. But
sometimes, when a problem is detected in some part of the organization, to
diagnose the root cause, he feels the need to drill down into the data to lower
level granularities.
I want it on Excel
ABC bank is a large investment bank with operations across the globe. Bank
provides capital market research reports to investors who use its trading desk
for their investments. Due to various market manipulation frauds that have
occurred in the past, market regulator keeps a close watch on the research
reports that investment banks publish. Hence ABC bank has established a
centralized database where all the research data is stored. Governance and
checks have been put at various levels to ensure that all the data and research
work passes through regulatory filters before reaching to publishing desk.
The bank has instructed all its analysts to do all there research work on
centralized servers. Ricky, a research analyst of ABC bank, has been working
with MS Excel spreadsheets for a long time. He finds excel applications very
intuitive and very convenient to use. As he keeps traveling across the globe to
visit clients, he finds it a major bottleneck in connecting to centralized servers
to do some analysis. It is also very convenient for him to email excel sheets
to his clients and associates. For him, MS Excel is a full-fledged BI tool, and
Banks' newly established BI platform seems more of a hindrance.

Need for BI Users to be More Empowered and BI Tools to be


More Exhaustive
All the above scenarios are not very uncommon in today’s volatile market
conditions. Business feels the need to respond to the challenges as swiftly as
possible with the methods and approaches which are far away from being
‘Standard.’ With business scenarios changing every day, it is very difficult
for system designers to anticipate all the possible business needs at the time
of tool implementation. This leads to the following key drivers for a new set
of BI tools:
Volatile business needs.
IT’s limited ability to meet new requests in a timely
manner.
The need to be a more analytics-driven organization.
Slow, restricted, and untimely access to information.
Business users need to be more independent of IT.
The complexity of traditional BI platforms.
Lack of intuitiveness of existing tools.
Constrained IT budget.

The solution lies in building a BI platform that is very flexible to


accommodate changing business needs and in empowering users to serve
their own needs with minimal intervention from or dependency on IT. In
summary, it reduces the need for time and effort involved in building a report
for a new idea.
These seem to be ideal features for any BI solution; at the same time, these
are unachievable without overstretching the costs and compromising the
performance. Self Service BI tools endeavor to walk on the tight rope.
Let me briefly explain all the features of self-service Power BI. I am also
trying to put some techno-friendly names to these business needs.
Interactive, user-friendly and intuitive user interface
A business user is never concerned about what is happening at the backend.
A sales manager is interested in knowing which product is selling in which
market rather than in understanding the data structure of the database. Neither
is he interested in going through a five-day training course for being able to
use a so-called cutting edge business intelligence tool. Irrespective of what is
happening in the backend, he wants a few simple things to happen on his
desktop.
Intuitive, nontechnical front-end: A user interface that is very
interactive and uses a language that is familiar to business users.
Office integration: Making BI results available on MS office
interface, with which users are very conversant.
Advanced visualization: A picture speaks more than a thousand
words. The best way of making something simple to understand
and use is to present it in graphs, charts, and pictures.
Guided analytics: Proactively alert users and automatically
provide pathways to additional information and insight.

Features and Functions


Business expectations from BI are evolving rapidly. A traditional text-based
report is no more sufficient. To support the business decisions in a desirable
time frame, BI should have features and tools which make it easier to work
all level of users and strong enough to support analytical and presentation
needs of most sophisticated users.
1. Predefined report templates: These allow users to change content
as well as the layout of a report by simple drag and drop
functionalities.
2. Parameterized reports: This allows users to change the content of
the fixed layout report.
3. Mash boards or Custom Dashboards: To enable power users to
craft dashboards for themselves and others by selecting elements
from existing reports and external Web pages.
4. Stored analyses: Allows users to store reusable analysis work to
be used later by other users.
5. BI Web widgets and mash-ups: Small applications that can be
installed and executed within a Web page by a user.
6. Sophisticated analytical processing and algorithms / functions.
7. Statistical functions: Allows advance statistical analysis like
predictive analytics.
8. Geospatial Functions: Interactive maps and geographical
presentation.
9. Workgroup portal and collaborative working: It helps in sharing
results, enables better governance, and optimizes network usage
by eliminating the need to publish results to individual users.
Users can retrieve BI results from the portal on an as-needed
basis. Also helpful are the techniques like tagging, ratings,
comments, and information collections that help in identifying
related content both inside and outside the organization.
10. Decision workflows: These help users to make
decisions based on best practices. It not only sets the structure for
decision making but might also make available necessary data
and expert opinion from various sources.
11. Automated Triggers: It allows automatic
trigger of some actions/ workflows based on business rules and
predictive models.

A robust and swift backend


There should be a robust data warehouse to support all that we have
discussed so far. But this is not limited to data structured in one warehouse. It
has become increasingly important for a user to understand the complete
picture. To gain contextual knowledge, the user must have access to external
data (e.g., weather information, geographic, demographic, or psychographic
data, comments or e-mails, social media sources). Also, a data warehouse
should be fast to deploy and easy to manage so that changes can be
incorporated swiftly.
1. Data virtualization: Because of the diverse business needs, it is
very difficult to incorporate all the required data into a single
data warehouse. With the help of data virtualization and data
federation technologies, it is possible to build virtual business
views that allow applications to access data from various
physical sources. These tools also support access to different
types of data sources, including relational databases, non-
relational systems, web services, Web data feeds, application
package databases, flat files, etc.
2. Cloud-Based Data Platforms: DBMS might be deployed in cloud
far faster deployment and lower upfront costs. It’s a new trend,
and many vendors provide this.
3. Browser-based dashboards: Deliver flexible access to
information that has been filtered and personalized for user
identity, function, or role—including enforcement of predefined
security rules.

The Tradeoffs
It might sound that SSBI is a panacea or a holy grail that can meet all the
demands that businesses put in front of a BI platform. The reality, on the
other hand, is far from it. On the one hand, a self-service environment
empowers users to do a lot of reporting and analytics on their own. Still, on
the other hand, it exposes the system to improper usage and might make it
more complex for casual users.
a. Power users might use SSBI to query very large data sets, putting
huge pressure on query performance.
b. Inspired by a new set of sophisticated tools, power users might
create thousands of reports with conflicting and inaccurate data,
making it difficult for casual users to find a relevant report.
c. Many users might end up running a similar query putting
unnecessary pressure on system and network.
d. Making data available from various sources using data
virtualization or shared data views helps the user to get a
contextual sense of analysis. Still, this approach often harms
performance.

Available Tools: Many vendors, both big and small, have come up with self
capabilities added to their BI offerings. Following are a few of those tools:
Microsoft: Power Pivot
Tibco: Spotfire
SAP: Business Objects Explorer
IBM: Cognos Express
Information Builder: Web Focus Visual Discovery
Open Source: BEE Project, Jaspersoft, Pentaho, SpagoBI
Conclusion

So this was all about the strategies to learn the functions of Power BI and
Power Query. By following the above approaches, you can easily learn
Power BI on your own and become a master in power BI. The only thing you
need to focus on while learning Power BI and Power Query is that all steps
need to be followed properly. You can’t skip any step; otherwise, you will
not be able to utilize all the functions of Power BI simply and efficiently.
You will be able to generate intuitive reports easily after going through the
book.

You might also like