Professional Documents
Culture Documents
Power Bi Succinctly
Power Bi Succinctly
Power BI Succinctly
By
Pierstefano Tucci
2
Copyright © 2017 by Syncfusion, Inc.
This book is available for free download from www.syncfusion.com on completion of a registration
form.
If you obtained this book from any other source, please register and download a free copy from
www.syncfusion.com.
The authors and copyright holders provide absolutely no warranty for any information provided.
The authors and copyright holders shall not be liable for any claim, damages, or any other liability
arising from, out of, or in connection with the information in this book.
Please do not use this book if the listed terms are unacceptable.
SYNCFUSION, SUCCINCTLY, DELIVER INNOVATION WITH EASE, ESSENTIAL, and .NET ESSENTIALS are
the registered trademarks of Syncfusion, Inc.
3
Table of Contents
Building blocks............................................................................................................................... 15
An example.................................................................................................................................... 20
Cooperate ................................................................................................................................. 39
Configure relations......................................................................................................................... 61
Calculated column..................................................................................................................... 63
4
Measure .................................................................................................................................... 63
5
Explore the sample code ......................................................................................................... 139
6
The Story Behind the Succinctly Series
of Books
Daniel Jebaraj, Vice President
Syncfusion, Inc.
taying on the cutting edge
S As many of you may know, Syncfusion is a provider of software components for the
Microsoft platform. This puts us in the exciting but challenging position of always being on
the cutting edge.
Whenever platforms or tools are shipping out of Microsoft, which seems to be about every
other week these days, we have to educate ourselves, quickly.
While more information is becoming available on the Internet and more and more books are being
published, even on topics that are relatively new, one aspect that continues to inhibit us is the inability
to find concise technology overview books.
We are usually faced with two options: read several 500+ page books or scour the web for relevant
blog posts and other articles. Just as everyone else who has a job to do and customers to serve, we
find this quite frustrating.
We firmly believe, given the background knowledge such developers have, that most topics can be
translated into books that are between 50 and 100 pages.
This is exactly what we resolved to accomplish with the Succinctly series. Isn’t everything wonderful
born out of a deep desire to change things for the better?
7
Free forever
Syncfusion will be working to produce books on several topics. The books will always be free. Any
updates we publish will also be free.
As a component vendor, our unique claim has always been that we offer deeper and broader
frameworks than anyone else on the market. Developer education greatly helps us market and sell
against competing vendors who promise to “enable AJAX support with one click,” or “turn the moon to
cheese!”
We sincerely hope you enjoy reading this book and that it helps you better understand the topic of
study. Thank you for reading.
8
About the Author
Pierstefano Tucci is a developer and data analytics consultant. He was born in Italy and has a
strong DB and BI background as well as a special interest in languages such as SQL, U-SQL,
R, .NET, HTML, JS, and CSS. He has a bachelor’s degree in economics and management
along with a master’s degree in IT security and computer forensics. He is currently studying for
a fourth degree in computer engineering. He works in the IT department of an international
company.
9
Chapter 1 What is Power BI?
Power BI is a cloud-based business analytics service that gives us a single view of the most critical
business data. Using a live dashboard and creating rich, interactive reports, Power BI allows access to
data for monitoring the health of a business. Essentially, it is a tool for creating our own BI reports and
dashboard. Power BI is not complicated—it is powerful, easy, and for everyone.
1st Wave—Technical BI (IT people-to-end users): In order to achieve BI results, in the past companies
had to rely on consultants and IT professionals in order to develop Analysis Server Models. These
professionals would develop a data warehouse and then create reports and analysis in order to give
end users options for making sound business decisions. However, there was a problem: there were
not enough IT people. And, actually, this is the problem we still have today. Because of a lack of IT
professionals, oftentime companies, which are always looking for reports, must wait too long while
assuming the additional risk that what they eventually obtain is not still valid.
2nd Wave—Self-service BI (analysts-to-end users): This wave included PowerPivot Excel, which
allowed users to make their own data analysis. This worked well. Data analysis and data scientist
consultants began to buzz in the BI world. However, this wave was not as innovative as first expected
because, despite improvements, the data analysis was still difficult.
Data analysis requires a flexible mindset that comes from traveling a long path of rethinking both our
mental and data approaches.
3rd Wave—BI wave (end user BI). The aim is to give business intelligence to all. What is the
difference between the first wave and the second wave? In the first, we have tools such as ClickView
and PowerPivot. In the third wave, end users not only have a tool, but a tool series. Different tools for
different users. The idea is that each user has a unique platform with many choices available for their
unique needs.
Developers who take care of ops integration; data scientists who take care of data analysis;
visualization experts who take care of data visualization and choose the best visualization option—
each professional has a role in developing data analysis in Power BI.
The first problem involves access to data. Data is often stored in a database, and on-premises data
decreases over time. Data is typically stored in the cloud, in an Excel file, or on websites. We need to
collect information and bring it into our own analysis systems. In order to do that, we also need to have
data access and the correct tools.
In general, our data is stored in a database, but often we do not know exactly where it is. If we use a
web service, we will have the access credentials to the portal, but we still won’t know where the data is
saved. For example, Google Analytics allows to us analyze data access for websites, but we do not
know where the database is. We can’t plug a direct cable into the Google databases and collect or
select data. We need a tool to simplify this process, one that starts from Google Analytics and uses its
own process or application.
10
The second problem involves security and accessibility. We need our data stored in a virtual machine,
otherwise that data is available for some users (or user groups) but not for everyone. We need to
implement safety mechanisms and rules—user mechanisms that allow particular groups to view
different information—in order to achieve this security goal.
Power BI Scenario
In order to understand the Power BI scenario, we must understand clearly who the content creators
are and who uses the content.
The Executive needs heavily aggregated information in order to see a high-level image of the
company’s state or a particular functional area. This information for the executive is often presented in
the form of a dashboard or a scorecard, and it is bound to raise strategic questions.
The Analyst needs raw, or slightly summarized, data with the aim of creating a detailed analysis of a
specific problem or business opportunity. The analyst presents the data in the form of spreadsheets,
presentations, or ad hoc reports that focus on the specific problems they have been called upon to
solve.
The Manager needs data, which provides a detailed analysis of an area, a specific business, or a
function. The data for the manager is used to evaluate past performances or to plan future activities.
The data must have a detail level that can define specific actions, for example a sales plan or a
marketing activity for the launch of a product. The data for the manager is usually supplied as reports
or scorecard details.
The Operational Users deal with data on a transactional level. For example, an operating report in
which the invoice registers information that comes from bookkeeping or a daily production plan. The
operational data is usually shared in the form of reports. More and more frequently, the data for the
operational users is shared online through an Intranet or directly through mobile devices.
All of the people in these positions work and cooperate by using tools of Business Intelligence.
The data visualization and discovery tool is important for several reasons. First, it allows us to use a
very strong and sensitive organ—our eyes. Through our eyes we interpret the information correctly. It
is a sophisticated instrument, so much so that machine learning algorithms still rely on it.
In 1973, Frank Anscombe produced four collections of information that he called “the quartet,” to
demonstrate this idea. He drew 11 points in each quadrant of his diagrams. The points have very
similar statistical features, and they represent variance, average values, correlation, and linear
regression. The values vary by a few percentage points. The way in which the points give us
completely different information is shown in these graphs. The graphs allow us to identify the
outliers—the individual points that are meaningfully different from others and therefore provide us with
the information needed to write our analysis.
11
Figure 1: Anscombe’s Quartet (source: Wikipedia)
12
Figure 3: Used Property (source: Wikipedia)
We can deduce that, once our data reaches millions or billions of rows, it would be helpful for the
analysis to have an expression power such as Power BI. This helpfulness is another reason why the
Power BI tool is having great success. Users prefer Power BI because of its easy usage, great
availability of visualizations, and capacity to integrate data from different sources.
Power BI is arguably one of the two or three most powerful and sophisticated data analysis programs.
Research firm Gartner places it as the leader among the Magic Quadrant in business intelligence,
transactional systems, data warehousing, and advanced analytics. At the time of this writing, the
Microsoft data platform is first in all the reports regarding safety, performance, and capacity to do
advanced analytics “in-place” (that is, inside the data contained in the database). By adding the in-
memory and the capability to work in either on-premises systems or in the cloud, as well as in hybrid
environments, we can obtain the full richness and the power of this tool.
13
Chapter 2 Service
Power BI is not a product we install, but rather a product that is carried out in the Microsoft Cloud that
we can use in different interfaces.
Data sources
There are many types of data sources:
• SaaS solutions, e.g., Marketo, Salesforce, GitHub, Google Analytics, CRM Online
• On-premises data, e.g., SQL Server Analysis Services
• Organizational content packs, e.g., corporate data source or external data services
• Azure services, e.g., Azure SQL, Stream Analytics
• Excel files, e.g., workbook data/data models
• Power BI Desktop files, e.g., data from files, databases, Azure, and other sources
The organizational content packs stand out in the data sources. They offer a simple and intuitive way
of sharing data within your company.
A program interface has been introduced in Power BI through a RESTful API that allows interaction
directly with the service, building datasets and, if necessary, importing our Power BI visualizations
inside our applications as web applications.
In order to try Power BI, you can register for the service free of charge. But be sure to pay attention
and use an Office 365 email address, which must end with the domain microsoft.com (you can also
use a company email account). Email accounts from many public servers, such as gmail.com,
live.com, hotmail.com, and outlook.com do not allow the registration.
When you have registered, you can test the functionalities. It is possible to update the license at any
time, simply by subscribing to Power BI Pro.
• Microsoft Edge
14
• Internet Explorer 11
• Chrome desktop, latest version
• Safari Mac, latest version
• Firefox desktop, latest version
• Power BI (works with older browser versions, but may have rendering problems)
Along with the browser, we can also use these mobile apps:
• Windows
• iOS (iPhone and iPad)
• Android
• Windows Phone 10
Building blocks
Power BI is composed of “tiles,” which are the main elements of Power BI. Called “building blocks,”
they are:
15
Figure 4: Dashboard Examples
It is possible to use the Navigation pane to create or select the elements, or building blocks, of
interest.
A tile derives from the pinning of a single display in a report or from a Q&A answer.
16
The tiles can be resized, and they can be updated.
As Figure 6 shows, you can use Q&A to ask questions in the dashboard and in the natural language.
In order to connect to a dataset, the dashboard must contain at least one tile.
Only cloud-based datasets associated with the current dashboard are supported. Q&A provides
support for the formulation of questions, and Q&A also formats the questions with suggestions,
autocomplete, and even corrections. Note that only questions in basic English are supported. Using
meaningful nouns within the basic model works best.
A report is built starting from a dataset. The model is displayed, and we select the data from the
dataset directly in the report.
• Navigation bar
• Dashboard with tiles
17
• Q&A question box
• Help and Feedback buttons
• Dashboard title
• Office 365 app launcher
• Power BI home buttons
• Additional dashboard actions
Service types
Power BI Services is, in fact, a particular service that we can access through a set of functions. It
offers a number of functionalities and is free, so we refer to this version as the “freemium.” There is
also a pay version of the same service, Power BI Pro, which does not have the limitations of the
freemium version.
18
Figure 8: Power BI Licensing
Note that the “publish to the web” option is a free functionality in both versions. However, the data
update and the cooperation of the two versions differ from each other—with the pay version, the data
can be updated with very high frequency. Also, with the pay version we have 10 GB available for data
storage and processing, while with the free version we have only 1 GB.
19
With the pay version, we can carry out planned updates more than eight times a day. With the free
version, the updates can be carried out only once a day.
An example
Let’s start from zero. We import a certain example of data that we can download from this website:
Financial Sample workbook for Power BI. Note that the data can be loaded from:
• My Organization
• Services
• Files (directly from the system file)
• Databases
Uploading the data from the system file, a CSV in our example, Financial Sample workbook for Power
BI, the data model is imported quickly and available within a few seconds.
Figure 9 shows that if you drag the Sales field to the white page of the report, Power BI will display the
data in the method it considers most appropriate at the time.
If you drag the Year field to the graph, as in Figure 10, you will immediately notice that Power BI
reworks the visualization by adding the year.
20
Figure 10: Power BI Displays Data
We can move the year to the abscissas field and see how Power BI now changes the visualization by
taking the modification into consideration, as in Figure 11.
We can implement the drill down by placing the Month field under the Year field (in the x-axis section).
The drill down is enabled by clicking the round icon with the “down” arrow. If we analyze the data by
clicking the Year, the visualization changes by also showing the Months.
21
Figure 12: Power BI Displays Data—sequence
If we want to go up with the visualization, we must click the “Drill Up” icon.
22
Figure 14: Power BI Displays Data—Slicer
Next, as we see in Figures 15 and 16, we select the Segment field and drag it into the slicer.
23
Figure 16: Power BI Displays Data—Use of Slicer
We can interact with the report by noticing how the selection of a value in the slicer affects the
adjacent visualization.
Now we create a new dashboard and save the report, as the three graphics in Figure 18 demonstrate.
24
25
Figure 18: Power BI Display—Datase of Slicer—sequence
When we have saved the report, we can select the Reading View mode, which allows us to interact
with the data by clicking the Edit report tab. By going back to the Design mode, we can change the
information we want to modify by clicking the Pin icon.
26
Figure 19: Pin to Dashboard—sequence
Next, we add the graph that has been pinned to the new dashboard.
When the operation has been completed, we will notice a tile, which is the graph we pinned into the
dashboard. By clicking the tile, we open the original report in Reading View mode.
Another mode for pinning the report is accessed by going back to the same edit page, reducing it, then
clicking Pin Live Page on the top right of the screen. The report will be pinned into the dashboard.
This mode is important because it allows us to interact with the data through the slicer.
27
28
Figure 21: Pin Live Page—sequence
If we want to delete a tile from a dashboard, we click the ellipsis icon (…) that indicates whether a
context menu is available. In the following visualization, we click on the Delete entry.
In the Context menu, we can also carry out other operations, such as Focus mode, which opens the
graph to full screen, and Insights, which also opens the graph in full screen and offers significant
values such as Value Sum and Summary charts.
29
Figure 23: Insights
We can also use the “Pin visual” icon to pin the same tile into another dashboard. “Export data” allows
us to export the data present in the tile (in CSV format).
With “tile details,” shown in Figure 24, another window is displayed in which we can edit the
information of the tile.
30
Figure 24: Tile Details
As we can see in the Edit page of the report in Figure 25, if we click a new page at the bottom left, we
can add new pages to the report. If we explore the various fields, we’ll notice that the Country field of
the dataset is represented by a little globe. Power BI recognizes the data type and, if we drag it to the
report, it will be identified as geographical data and so a map will be displayed. When we drag and
drop the Sales field to the geographical map, the sales distribution across the map is displayed.
31
Figure 25: Power BI Visualizations
Figure 26 shows that we can add a new chart on the same page by inserting the Sales field, and in
the same graph we can add the Month field in order to have a temporal base. By clicking the graph
type, we can change the visualization to one that best meets our expectations.
32
Visual gallery
If the visualizations are not sufficient, we can obtain new ones from the visual gallery at
https://store.office.com/en-us/appshome.aspx?productgroup=PowerBI, where we can see numerous
visualizations published by people who have implemented and shared them.
As Figure 28 shows, we can also download the Timeline. Note that the checks can be constantly
updated, so it is advisable to always download them in order to be certain you have the updated
version. To do this, click Add, then click Select to download Timeline Slicer.
33
Figure 28: Power BI Timeline Slice—sequence
We import this new control by clicking the “...” icon in the visualizations section.
34
Figure 29: Power BI Visualizations
The Timeline visualization will be available on the display commands. By adding the Timeline to the
report and later dragging the Data field there, we can implement a control that allows us to select the
data based on temporal intervals. It is simple and intuitive. The other visualizations present in the
report will display the data based on the selection carried out through the Timeline.
35
Note that because the custom visuals have been developed by third parties, they include a disclaimer
asking us for usage confirmation.
Figure 32 demonstrates the download of a custom visual from the visual gallery. We can add a report
on a new page by dragging the Country field onto it, and then, for example, the Sales field. Doing so
will create a stage visualization.
The report pages are independent. We can set certain filters on a page or report basis. On a page
basis, the data is filtered on the page only, and therefore the visualizations will show only data that
makes it through the filter. On a report basis, the visualizations present in all the report pages will
show the data that makes it through that filter. In Figure 33, the Segment field has been selected and
linked to a report-level filter. All the pages will interact based on the filtered data.
36
Figure 33: Use of Filters
For example, in asking, “Which segment has the most revenue?” the term “the most” tells Power BI
that we are asking for a system.
37
Figure 34: Use of Q&A—sequence
“What segment got the greatest number of profits?” will receive an answer through a visualization. If
we are not satisfied with the graph form, we can change it by choosing the visualization that most
satisfies us. We can carry out the pinning directly in the dashboard. And by clicking the tile that has
just been inserted, we can go back to the original question. Notice that Revenue is not present in our
data model, but Power BI has realized that that is related to the Profit field and shows us the profits.
• Sharing dashboards and tiles directly with the users of our organization.
• Using Groups of Office 365: reporting and cooperating directly in a workspace dedicated to the
group.
• Publishing an organizational content pack, which is shown in an internal gallery (all the users
of the organization or of a group inside the organization are able to surf the store, the content
packs are displayed, and it is possible to install the relevant packs with the same usage
experience).
Each method requires that all users have a Power BI Pro license. And except for the dataset on-
premises Analysis Services case, all the users will see the same shared data.
38
Table 1: Share Options Comparison
It is applied to: Specific dashboards All the contents All the contents
or tiles
Some functions are more suitable to specific contexts than others. For example: the sharing of a
dashboard is very useful when we must share it with a collaborator in a very short time. In this case,
we must insert the account of the collaborator—we will receive a notice and will be able to display the
dashboard—but we will not be able to modify the work. In the context of a collaboration group, we can
utilize the collaboration method through a workspace, and all the users can modify reports and
dashboards, cooperating as a team for the writing of a report. In short, the content pack is well suited
for scenarios in which multiple people are using the data because we publish the package (which
includes dashboard, report, and dataset) in a package and we publish it to a gallery that is visible to
all the users of the organization (who are therefore free to install and modify it).
Cooperate
In order to cooperate, we must go into the dashboard and click Share.
39
Figure 35: Dashboard
Next, we indicate the users we want to share the dashboard with and click Share.
40
On the same sharing page, we will find the option to specify whether or not the user can share the
dashboard with other users. We can also choose to send notifications via email (or not).
In the cooperation example (where Option 1 is no and Option 2 is yes), the user who receives the
shared dashboard will not be able to modify it—only display it.
We can cancel the sharing with particular users by selecting Share in the Access section and then
clicking Cancel invite.
Regarding cooperation through the Office 365 groups, on the upper left of the screen we will find the
entry “My workspace,” indicating it is our personal workspace.
We can browse to check whether there are several group workspaces. If there are none, we can
create a new one by specifying the name of the group, whether the group is private or public, and if all
the members of the group are able to modify the contents within the workspace or only display them.
Lastly, we include the users who belong to the workspace.
41
Figure 38: Share Dashboard to Cooperate—sequence
42
We can go back to sharing by selecting a group workspace. We get a new triple set of dashboard,
report, and datasets that are independent from the personal ones. In this new workspace, we are able
to cooperate with others who are part of the Office 365 group.
Publishing a report on the web allows us to make the report visible to anyone, assuming we allow
default anonymous access to the report.
Figure 40 shows the sequence of our next actions—selecting Create embedded code, then Publish.
43
Figure 40: Publish to web—sequence
The new window (in Figure 41) will display several items: a link we can send by email; HTML we can
paste into our blog or website; and HTML iframe tags we can integrate in our web application. Note
that the size of the graph is in pixels and we can choose from three different dimensions.
44
Figure 41: Publish to Web—finishing the publish step
If we use the link by specifying it in the URL of a browser, we will have direct access to our report and
can browse it without authentication.
45
Figure 43: Publish to Web—result
We choose the data source type we want to use by clicking Get Data.
In the Content pack, we can specify one of four different sources for the data:
• Organizational
• SaaS application (files included)
• Excel workbook
• Files produced through the Power BI Desktop app (databases and data services present in the
cloud)
The Excel files can be imported directly from the browser and can be loaded from a local source, or
we can access OneDrive for Business, OneDrive Personal, or SharePoint team sites.
The file updates in OneDrive/SharePoint are recognized automatically in the reports and dashboards,
and the data will remain in the workbook. If the workbook connects to the external data sources, we
can use Power BI for the refresh.
46
Figure 44: Get Data
The maximum size for the uploaded files is 250 MB (240 MB for the data model present in the
workbook and 10 MB for the remaining part of the data inside the workbook).
If the Excel files are in OneDrive Personal/For Business or in a SharePoint team site, in addition to the
import, we can also connect to the Excel workbook, which will have its own life (where it lies). We can
also use refresh functions to update our dataset once the data has been imported.
During the import of the Excel workbook, everything contained in the data model will be converted to a
dataset. In this particular case:
• Contents of the data model take precedence over the contents at the worksheet level.
• Workbook data model will be converted to a Power BI dataset.
• Workbook Table will be converted to a Power BI dataset.
• Power View Sheets will be converted to pages of a Power BI.
• PivotTable, PivotChart, and custom fields are not recognized.
The data in the workbook will be imported only if it is defined as tables. Power BI will ignore scattered
data in the workbook.
47
Figure 45: Excel Online—sample Excel table
48
Figure 46: Excel Online—Pivot Chart—sequence
49
Figure 47: Importing Excel file—sequence
Note that the workbook is converted to various Power BI contents, which are created gradually. After
importation of a single content, it will be present in the corresponding section (report, dataset).
By displaying the dataset, we can see how the table present in the PowerPivot data model has been
converted to a Power BI dataset and that all the columns have been reported.
50
Figure 48: Fields from Excel File
A report will be created that contains a page (with the name of the imported Power View sheet) and
the same graph we had on the Power View sheet in the workbook.
We can edit the content or create new graphs and use them together to create dashboards. The
content will be identified as a Power BI graph.
The connect option does not convert the workbook but rather embeds it into Power BI. We can see
this in the Navigation pane on the left side, among the reports with the Excel icon.
By selecting it, we can now surf the Excel workbook in Excel Online.
51
Figure 49: Finishing the Import
The value of this workbook connection with Excel in OneDrive or SharePoint lies in the possibility of
setting up the data to refresh. As Figures 50 and 51 show, we can carry out the pinning of the
contents by selecting a table or part of a table and doing the pinning in the dashboard.
52
Figure 51: Pin to Dashboard—sequence
When we click the tile in the dashboard, we are redirected to the Excel file with Excel Online.
53
Chapter 3 Desktop
• Products: a display of the product differences and the licensing and service policies.
• Solutions: examples of how Power BI has been used in certain industries and departments.
The examples are interactive and available for download.
• Partners: a gallery dedicated to partners. You can search for and find partners who have
developed solutions or have experience with your concerns.
• Learning: a set of resources for studying relevant topics; a community where we can
compare our work or look for new information.
If we look toward the bottom of the website, we will find a section that offers an entire series of tools.
Below that, there is a series of resources for developers available together with a series of examples,
so that we can develop the application and embed to Power BI inside our websites, mobile
applications, or dashboards. We will also find important examples and in-depth videos. The second
resource is the YouTube channel of Power BI. Accessible in user/mspowerbi, the channel is very
informative, and it is constantly updated directly by the product group.
Power BI Desktop
The Power BI Desktop app can be downloaded free of charge through Power BI.
Power BI Desktop a visual tool for reporting as well as for elaboration of the data. It is available in 32-
or 64-bit, and it is optimized for use with the Power BI service. It completes consolidated Microsoft
technologies, such as Excel, where an add-in is available: Power Query, PowerPivot, and Power
View.
The application allows us to connect to different data sources, and it is typically updated on a monthly
basis. It simplifies the building of data models used as the basis for the reporting design that will be
published on Power BI.
Development method
The development method consists of these simple steps:
54
Query creation Relation set up Data model definition Report design Publication on Power
BI
The development method consists of a series of necessary steps and uses the creation of queries to
work toward our data sources, filter the data, and determine the correct formats for the data as well as
the information we want to build our reporting on. Once we have imported different data sources and
determined the queries for those data sources, we can identify or establish relationships between the
data. Possible relationship types are 1-to-1, or 1-to-N relations, just as in the relational (i.e., SQL)
world. The data model can be enhanced by defining calculated columns or measures. We can explore
the data model by using drag-and-drop functionalities, which is exactly what we do when we work with
the online Power BI. We start from the dataset, drag the columns related to the tables (part of our
dataset), and establish the most appropriate visualizations for building our reporting.
Steps 4 and 5 are actually the same steps, the same techniques we carry out online. The difference is
that we carry them out on the app. In the end, the result of our work can be shared with our coworkers
and other users in our organization by publishing reports and datasets directly on Power BI. Afterward,
we would be able to build dashboards online.
A query is defined as a “data retrieval,” and data source types include File, Database, and Azure,
along with other services and data sources.
In the app, the query creation uses a module that is easily linked to the experience of Power Query in
Excel. Power Query was an add-in of Excel until the 2013 version, then it was integrated into the 2016
version. The same techniques are used—defining the data sources and carrying out the necessary
elaborations, which are later described through a particular language, the “M” language, which is the
informal name of Power Query Formula Language. Through this language, we can refine our data
source and our table. The supported data sources are numerous, and they are the same supported in
Power Query.
55
Figure 52 shows how to get data such as Excel, CSV, XML, text files, or other files.
Figure 53 shows that sources such as SQL Server, Analysis Services, Oracle, and many others are
added as the app updates are released.
It supports the online data services present on Azure such as SQL Azure Database and SQL Azure
Data Warehouse.
56
Figure 55: Power BI Desktop—Get Data
Supported data connectors allow us to access data sources ranging from Facebook to Google
Analytics, Sales Force, ODBC, and so on.
As shown in Figure 56, we can open the query editor by right-clicking the loaded table.
In this editor, we can manage columns and formulas, we can filter, and we can load other data (Figure
57).
57
Figure 57: Query Editor
By clicking the columns, we can apply filters, order the data, or remove empty values (Figure 58).
The creation of queries allows us to filter data, format, and refine them in order to obtain the desired
result. The steps can be created easily by applying filters to the columns through the use of controls
available from the ribbon or through the context menus of the query or columns. We can select a step
and have a preview of the resulting data. The steps can also be removed, and the formula steps can
be shown or edited in the formula bar.
As these sources are saved and we carry out the editing steps of our query, they are saved in a
descriptive panel, as seen in Figure 59.
58
Figure 59: Applied Steps—descriptive panel
We can also delete or edit intermediate steps at any time. If, for example, we accidentally remove all
the rows by leaving only the first 10, when we intended to remove all rows except for the first 20, we
can cancel the remove operation and then correct the operation. All of the following steps will
recognize the modification that has been carried out in the intermediate step.
Because the query editor is WYSIWYG, we can easily test and do a rollback of the modifications.
We can also use different controls on the query that we want to define, and all that we do will be
reflected in the data we display in tabular format. We display exactly the result of the steps as we carry
them out. It is possible to manage columns, change data types, remove or add columns, split the
tables (columns), and take many other actions.
New queries can be created through the merge of two queries (joined in a common column) or with
the appending of two queries (union).
• Left Outer (all the data from the first table, matching with the second one)
• Right Outer (all the data from the second table, matching with the first one)
• Full Outer (all the rows from both the reported tables)
• Inner (only matching rows)
59
• Left Anti (rows only related to the data present in the first table)
• Right Anti (rows only related to the data present in the second table)
We can define more than one query. Typically, numerous queries are used, and they can be
connected to heterogeneous data sources. Once the queries are defined, they can be combined by
carrying out the merge or the append. In the case of the merge, a join is defined. In fact, we connect
two queries. In the case of the append, the results of two different queries are put together and
connected. It is good to make sure that the tables are compact as well as solid and that they have the
same column names so that the columns can be identified in both tables.
60
Figure 62: Query Editor—merge options
Figure 63 demonstrates that you can edit this merge via the Merged Queries icon.
Configure relations
By defining a relationship, we create an implied filter that operates across two or more tables. The
filtering relationship is not the same as Foreign Key Constraint, which is used to ensure data integrity.
The relationship can be defined between any two tables, independent of their data connection or data
source type, but they must be based on a single column with matching data types. Self-referential
relations are not supported.
61
In fact, with a merge between two queries, we set up a relationship on which we can carry out further
steps. There are restrictions for which a relationship cannot be created in a single table (hence the so
called self-referential relationships are not supported). However, there are no restrictions at the level
of Foreign Key.
In this way, we define our relations by obtaining, for example, a model like the one represented in
Figure 64, in which we have N relations that can be 1-to-1 or 1-to-N. We are, in fact, building our data
model.
• Data type
• Format
• Category (that is spatial or web URL)
• System (based on another column of the table)
• Visibility
Starting from the relationship, we have a data model. At this stage, once the data model has been
defined, we can define the types that will be used and the formats, and we can decide if and which
columns will be visible or not, define the systems among data, and so on.
62
Data model definition: calculations
We can also enhance the data model by using the Data Analysis Expression language (DAX). People
familiar with the PowerPivot models will have a familiarity with the DAX language, which allows us to
implement calculated columns and measures.
We must insert calculated columns or measures in whichever data model we use. We will hardly be
able to do without it. All the support for the DAX language is also present in Power BI.
There are two different types of calculations, and both are defined by using DAX:
• Calculated column
• Measure
Calculated column
We use a formula to define a calculated column. Starting from other columns, we add a new column,
which is the result of the formula we have previoiusly defined. A calculated column in a model uses
memory space at runtime. We should keep this in mind to avoid Power BI out-of-memory errors.
There are defined calculated columns to add new columns to the tables. Each Column Value per row
creates and saves the data in the data model. Note that they use up space in the data model. The
Column Values are recalculated when a refresh occurs in the table and when the refresh is carried out
on the dependencies of the formula.
Measure
The measures, unlike the calculated columns, do not use up storage space. The measures are
defined by using a formula. They are made available to the dataset of Power BI, but they are
calculated in real time, and for this reason they do not use up space. The formulas are defined by
using the group functions, such as sum, count, distinct count, average, minimum, and maximum.
There are defined measures for adding group logic to the data model. The values are neither created
nor saved in the data model. The formulas are enhanced in the query time mode.
63
Design report
Once the data model has been set up, we can proceed with the report design exactly as it occurs
online by using the Power BI service through the browser interface. We can also build a report by
using the Power BI app.
The reports can be designed based on the interface of the visible data model. It is also possible to add
text boxes and pictures.
The design experience is very similar to the one available with the online service of Power BI.
Publication on Power BI
At the end, our work can be directly published online on Power BI, and it can be shared with other
users. Starting with the reports and datasets we published, we can also define certain dashboards.
The Power BI Desktop file can be loaded on the Power BI service or published directly. In case of
overwriting an existing dataset, we must take into account that if there are two or more datasets with
the same name, one must be removed and the Power BI Desktop file must be renamed.
Remember, too, that when renaming the columns or the measures, the report or the dashboard tile
can be damaged.
64
http://www.bankrate.com/finance/retirement/best-places-retire-how-state-ranks.aspx
The link includes an article about retirement in the United States—specifically, which states are the
best for retirement. It displays the states with different indexes, such as the cost-of-living, the crime
rate, and so on. Let’s use one of the article’s tables for writing a report.
Note that the use of the full name of a state can be a problem in the graphical representations.
Generally, the use of standard abbreviations as recorded by Wikipedia is preferred. In particular, we
will use ANSI abbreviations.
https://en.wikipedia.org/wiki/List_of_U.S._state_abbreviations
If we click on the More entry, we can display all the source data currently supported. We choose the
entry Web, click Connect in the URL, specify the page concerning the state statistics, and click OK.
As we see in Figure 67, two types of content are recognized on the page (Document and Table). By
searching, we can see the contents and select the table containing the data we are interested in.
65
Figure 67: Power BI Desktop—Get Data, Navigator
Note that Figure 68 shows how to click Edit in order to edit as well as to work on the data of the table.
The column named Rank is not relevant, and we can remove it (right-click).
66
Figure 68: Query Editor
If a field has been identified as a numerical whole number, we must correct the string with empty
spaces via the Replace Values interface, as in Figure 69.
Note that when all the target values have been replaced, it is possible to convert them to whole
numbers (no decimal points) by right-clicking and selecting from the context menu.
67
Figure 71 shows how to use Advanced Editor on the ribbon in the query section in order to get a
summary of all the reproducible steps.
The query is imported automatically and is visible on the right panel, as in Figure 73.
We also import the data concerning the abbreviations present in Wikipedia. We use the “Get data”
functionality, then we click Web and specify the address in which the information is contained.
68
In Figure 74, you can see the address we want—the one that contains the table with state
abbreviations—and we edit.
We remove rows via the row removing functionality present on the ribbon: Reduce Rows, Remove
Rows, and Remove Top Rows.
69
Figure 76: Query Editor—Remove Top Rows form
We are only interested in the states present in the statistics, therefore all the other areas won’t matter
here. By using the Remove Bottom Rows button in Figure 77, we will remove the 25 rows from
number 54 to 78.
Remember, we are only interested in the abbreviations with the ANSI two-letter codes, so it makes
sense to select the two columns we are interested in and remove all the others.
70
Figure 78: Query Editor—column options
As a result, we have the table we will use to build the data model.
We can rename the table and save it with Close and Apply, which is the first entry on the top left of
the ribbon.
71
We use the “Manage relationships” function present on the ribbon Relationships in order to obtain the
relationship.
We can also try to implement Autodetect in order to carry out the automatic survey, which is based on
the names of the columns.
Figure 81 shows a case that will not work, which demonstrates why it is wise to create the report in
manual mode.
Next, we click the entry New and identify the first table. As shown in Figure 82, the other table is
automatically selected.
We use the name of the state to create a relationship of 1-to-1. Note that the direction of the filter can
work both ways.
72
Figure 82: Relationships—Create relationship
Now the data model is set up. We can display the data of our queries at any time (see Figure 84).
73
Figure 84: Data Section
74
Figure 86 shows that we can create a graph about the cost of living. Note again that instead of using
the name of the state, we use the two-letter ANSI code.
Figure 87 shows how we might change our graph by using a more suitable visualization.
75
Figure 88: Save Power BI File
Click the entry Publish in the Share section of the ribbon (Figure 89).
Figure 91 depicts how to authenticate—by supplying our access credentials to Power BI.
76
Figure 91: Publish—Sign in
Now we display Power BI through the browser to see the effect of our last operation.
77
Figure 93: Publish Result
As we can see on the left panel, we have options of Datasets and Reports. The dataset is exactly the
one we have built with the data model using the app. And the report containing the visualization we
chose is also present.
78
Figure 95: Power BI Service—create a dashboard
Figure 96 is a reminder that, as usual, we need to pin the visualization to the dashboard.
79
Figure 96: Pin to Dashboard—sequence
Our report, which has been built on-premises through the app, can be edited in order to enhance its
information. Any modifications will remain available online.
80
Chapter 4 Mobile Apps
Power BI is available in apps for the following operating systems: Windows 8, Windows 10, Windows
Phone, iPhone, and Android. The app versions allow us to connect to the Power BI service and
explore the dashboards and reports available.
81
Figure 100: Power BI App
By proceeding with Get Started, we access the connection request. You can connect to the Power BI
service or to a reporting sevice of SQL Server 2016. In our example, we will connect to the Power BI
service.
82
Figure 102: Power BI App
Supply the access credentials to the Power BI service, as shown in Figure 103.
83
Figure 104: Power BI App
Figure 106 shows that we can explore the reports and dashboards present in our Power BI service.
84
Figure 106: Power BI App
By selecting a dashboard, we can activate the contextual menu to invite people and share our
dashboard, add it to the favorite dashboard list, or insert the dashboard into the start panel.
When we invite users who are external to the visualization of our dashboard, a context window
appears in which we must specify the user or users with whom we want to share the dashboard. We
must insert a contextual message while sending the invitation and specify if the recipient will be able,
in turn, to share the dashboard with other users.
85
Figure 108: Power BI App—invite options
If you select a dashboard or a report, a series of icons will appear on the right side that will allow you
to enlarge the chart/information you are consulting. You are now able to:
• Invite people.
• Add the dashboard or report to the favorites list.
• Insert the dashboard into the start panel.
• Update the dashboard or report you are displaying.
• Search for the dashboard or report in your Power BI service.
86
Figure 109: Power BI App
Next, go back to your dashboard and click the chart. The menu on the top right will change to a new
set of icons. Enlarge to full screen, open Report, Share, Search.
87
Figure 111: Power BI App
If you click Open Report, you can also base the selection of your data on filters, set up customized
filters, and obtain new results.
88
App for Android
From Google Play, you can install the application, authenticate to Power BI, and begin using the
contents right away.
On the top right of the menu, you can add notes or explore the report.
If you want to edit and add some notes, underneath the report you’ll see the panel where you can
insert your text, draw on the report, add emoticons, delete your notes, or share everything with other
users.
89
Figure 115: Power BI Android App—sequence
The procedure for the iPhone is the same as for the Android. If you go to edit the report and you want
to add notes, you can insert text underneath the report where the panel is displayed. You can also
draw on the report, add emoticons, delete your notes, or share everything with other users.
90
Figure 117: Power BI Android app
91
Next, click Get Started, as in Figure 120.
Next, the connection type is requested. You can connect to the Power BI service or to a Reporting
Sevice of SQL Server 2016. In our example, we will connect to the Power BI service, as in Figure 121.
Note that you will be asked to supply credentials in order to access the Power BI service.
92
Figure 122: Power BI Windows 10 Mobile Sign In—sequence
At this point, the authentication has been successful and you can click the “Start exploring” bar.
If you prefer, you can also accept the boxed offer that reads: “Send us information about your Power
BI usage and Power BI performance to help improve your Microsoft experience.”
Now you can begin using the dashboards or reports present on your service.
93
Figure 124: Power BI Windows 10 Mobile
On the top right, you’ll see the search icon, which allows us to research dashboards and reports
present on the service we are connected to.
If you select a dashboard, you can invite other users to use the content, add the report to the favorites
list, insert the dashboard into the start panel, or update the report.
94
Figure 126: Power BI Windows 10 Mobile
If you invite other users to use the dashboard, you’ll need to insert the email addresses of the users
you want to include.
95
Figure 128: Power BI Windows 10 Mobile
In addition to the social profiles connected to the phone, the sharing option also offers the applications
suitable to accept that information.
In our sample, we have chosen to share the report via email. The attachment inserted into the email
by default is nothing but the snapshot image of the report we decided to share.
96
|
97
Chapter 5 Solution Template
Now let’s examine the latest sharing mode, which is the most innovative mode and offers us the ability
to create content packs.
In order to create a new content pack, first we go to the top right, click the Setting icon, and select
Create content pack, as in Figures 131 and 132.
98
We can quickly decide if we want to share this with our entire organization or only with a specific
group. In fact, we can specify:
With any items we want to share, dependent reports and datasets can be selected, too. We can also
add other datasets and reports without having problems related to interdependence restriction.
When we have finished the configuration, we can carry out the publication by clicking Publish.
Next, we can enter the Get Data as user, via the icon in Figure 133.
As the graphics in Figure 134 show, we can next select My organization, where we can see all the
previously published content packs. When we select the content pack, the owner is indicated. By
clicking Get, we add that to the workspace.
99
Figure 134: Microsoft AppSource—sequence
Next, we go to the top right, click the Settings icon, and select View content pack in order to delete a
content pack. Next, we click the Delete entry corresponding to the content pack we want to delete.
Content pack
The content pack is one of the three sharing modes that allow us to gather together report and
dataset dashboards as well as to share them within our organization.
100
The Software as a Services (SaaS) can be embedded by Power BI through content called connectors,
which are made available directly on the Power BI portal and are simply content packs created
specifically for this application. Once one of the connectors has been used and the connection data,
such as the authentication account, has been provided, we can log onto source data like CRM Online,
Google Analytics, and Salesforce. We can also use connectors to link to source data in the cloud,
such as Azure SQL Database, Azure SQL Data Warehouse, and Spark on Azure HDInsight. (Note
that Apache Spark is a generic engine for large-scale data storage with Azure HDInsight).
Database and data services are connectible, and a number of Azure (cloud-based) services offer the
possibility of having a direct connection:
• Queries are sent to Azure, while the users export data and reports (the dashboard tiles are
updated every 15 minutes).
• This functionality is for users who already have experience with databases and with the
entities they connect to.
• It is available only with the Power BI Pro license.
Using Azure Online services such as Azure Stream Analytics, for example, leads us to interesting
scenarios, like the possibility of creating RealTime dashboards with Azure Stream Analytics.
In the Big Data world, we can collect a considerable quantity of data coming, for example, from
sensors—in such a case, we have data flows that can be gathered through the Azure Event Hubs
service. Afterward, we can carry out real-time analysis of the data by using the Azure Stream
Analytics service. Finally, we can display the data by using Power BI and integrate it directly with a
data source such as Azure Stream Analytics.
For example, we can imagine the data coming from a web application, perhaps an eCommerce
website. In that case, we can collect data related to the web surfing of the user and we can analyze
the temporal windows and display a summary of the analysis that can be the number of web requests
received in the last minute. We can identify a temporal window because Azure Stream Analytics
allows us to do real-time analysis. And because Power BI offers a visualization that is updated in real
time, there is no refresh needed in this case.
101
We need to use connectors for the SaaS applications in order to connect Power BI to the online
sources. So, we refer to the Get Data and we go to Services, where we can display the number of
available connectors. We can use Microsoft Dynamics CRM Online and click Connect. We will be
asked for the data services URL of Dynamics and also an authentication account. The result we
receive will be very similar to the following reports because a report is created automatically.
There are also several pages available for us in the report. The data comes from a CRM Online test.
At the same time, we have a dataset available to implement a further report starting from our CRM
Online.
102
Figure 138: Dashboards—sequence
103
We can also use database online data sources—in particular, Azure SQL Database, Azure SQL Data
Warehouse, SQL Server Analysis Services, and Spark on Azure HDInsight. In this case, we need only
select Azure SQL Database, click Connect, then provide the server address, the name of the
database, and information about the authentication. Automatically, we have a data model available
that is updated about every 15 minutes.
Power BI allows the update of the online as well as on-premises data for the dataset loaded from:
The data update can be on-demand or scheduled. If scheduled, the maximum frequency is:
We need to keep the credentials in order to keep the data updated in Power BI. Moreover, we must
provide the access credentials for the data sources included in the dataset. The credentials are saved
securely so that Power BI can connect on behalf of the user.
104
Figure 140: Datasets—Scheduled refresh
When we schedule the data refresh, Power BI should keep the credentials used to carry out the query
of the data sources. We will be asked to provide the credentials, which will be kept securely in the
cloud.
Now let’s look at an example of how to implement an automatic refresh for the Excel workbook.
Typically, when working on-premises we can update the data. If we use an Excel workbook with a
data source on the SQL Server, the database is AdventureWorks, and if we modify some data, the
modification should also be mentioned in the reports and in the dashboard of Power BI.
In Power BI Service, we add a new report page with a new visualization about the SubTotal column
sum.
105
Figure 142: Power BI Service Report
Next, let’s make a modification that cannot go unnoticed in our report. We’ll update the SubTotal field
from 20565.6206 to 205656.206. Now let’s open the Excel workbook and run a data refresh.
Figure 144 shows an update to the dataset of the Excel workbook, achieved by running the manual
refresh.
106
Figure 144: Excel Workbook
Power BI Gateway
After considering the previous example, we need to configure the Personal Gateway in order to
refresh the Excel data. In the case of Excel workbooks, which have no connections to external
sources, the error message will not appear and the data will be updated without any problems.
To install the Personal Gateway, we need to download the program by accessing the gateway pages
at https://powerbi.microsoft.com/en-us/gateway and install it. Once the installation is finished, we can
set up the Personal Gateway.
Figure 145 shows the steps for installing and configuring our Personal Gateway.
107
Figure 145: Personal Gateway Installation—sequence
We start with the Personal Installation Wizard. We’ll see some advertising, then we can click Next.
As Figure 147 shows, you’ll be asked to accept the license agreement. Do so.
108
Figure 147: Personal Gateway Installation
109
Figure 149: Personal Gateway - Sign in
This is how the Personal Gateway connects to the dedicated Azure Services Bus channel in order to
establish communication with Power BI. When the authentication has occurred successfully, the
Personal Gateway is online.
110
Figure 151: Personal Gateway—connected status
We also need to provide the credentials that will be used by Power BI to carry out the refresh. We can
check the status on Power BI Service.
111
In this case, we use the Windows Authentication, which means it is not necessary to provide the
credentials because the Personal Gateway service credentials will be used. At this stage, the refresh
is set up and it can be scheduled.
Note that we can add different timetables because we are using a Power BI Pro License; conversely,
if we use a Power BI Free license, we can update only once per day.
We can go back to the dataset, click the data source, which contains the connection to the external
SQL data, and run “Refresh now.”
Therefore, we can use the Personal Gateway to complete a data update even if the data sources are
on-premises.
Next, after the dataset refresh, we can go to the report and see data updates. The SubTotal is
displayed, as in Figure 153.
112
Chapter 6 Developer
Developers can use two modes to extend and personalize Power BI:
Try it by going to the console, carrying out calls to the services, and looking at what happens.
113
Figure 155: Power BI Console Portal
On the left side of the screen, you’ll find references to the connections to the various APIs, and under
the datasets you will find the calls to the APIs that can be evoked.
Our first action is to use our API to query a dataset currently saved in Power BI. By selecting Datasets
and Datasets Collection, we’ll find several APIs that can be called. Next, we’ll obtain a list of all the
datasets. On the right side of the screen, you’ll see the web service that can be evoked, the URL you
want to call, the details of the request type (necessary for the request transmission), and the format
you will obtain from the call return. By clicking Try, the request gets carried out, but remember that you
must authenticate and authorize Power BI.
114
Figure 156: Power BI Console Portal, Authentication—sequence
115
Figure 157: Power BI Console Portal—datasets collection
By clicking on the entry Call Resource, we allow the API to call the desired resource. So this first call
simply lists the data sets available.
The result of the call will be displayed in the underlying section. On the left side of the screen, you’ll
see the possible calls you can carry out, while on the right side you’ll see the interactive console used
to evoke the calls. The answer to the call is quick, typically returned in less than one second.
116
Next, we go back to the data collection to create a dataset through the dedicated API. From the left
side, we click on the entry Create a Dataset. The console changes the information. We can compose
a new dataset from the Body section.
The entry Call Resource will carry out the request. Go back to Power BI and you will see the newly
created dataset.
117
Figure 160: Power BI Service—datasets update
Now you’ll notice the presence of the new dataset and you can start using it, but note the data is not
present. Only the structure of the data has been defined.
Before populating the data, we should save the report and the dashboard.
118
Figure 162: Power BI Service Report
Go back to the console to insert data and select the entry Add Rows to a Table in a Dataset. In the
parameters, in the section “URI Parameter,” specify the ID of the dataset and the name of the table to
be populated (in our case, “sales”).
In the Body section, specify the data you want to insert, as shown in the example in Figure 164, and
click Call Resource:
119
Figure 164: Power BI Console Portal—Table Rows, Add Rows
From this moment forward, the data will be persistent in our dashboard. You can keep that as is, or
you can change the content. If so, you will notice the changes in the dashboard.
120
Figure 165: Power BI Service—report update
The same API functions can be invoked from our applications to create a dashboard that displays data
in real time.
To create a visual object, you first need to set up the development environment. Then you need
to install the NodeJS 4.0+ Required (5.0 recommended). Next, use the code in Code Listing 1.
Code Listing 1: NodeJS Command
To confirm that the installation is the successful, you can execute the command in Code Listing 2.
121
Code Listing 2: NodeJS Command
pbiviz
In order to enable the live preview of the visual objects, we must install an SSL certificate used in
HTTPS. This will allow the display and the uploading of objects via the browser, and it will work for
users of Windows or OSX.
122
Code Listing 3: NodeJS Command
pbiviz --install-cert
In the procedure for Windows users, the following window, as in Figure 167, will appear:
123
Figure 169: Certificate Import Wizard
Next, we select Place all certificates in the following store and click Browse... next to that line.
Figure 170 shows the next steps—we select Trusted Root Certification Authorities and click OK.
Then we go back to the previous screen, where we select Next.
124
Figure 172: Security Warning
In the procedure for Mac OS X users, the window in Figure 173 will appear.
125
Figure 174: MAC Root Certificate Authority
Figure 175 shows the next interface, in which we enter our username and password, then click
Update Settings.
When creating our first visual, we follow the prompt of the Node.js controls, as in Code Listing 4.
Rename “Name of visual” with a name that suits your needs. When the visual has been generated,
you can change the name in the file pbiviz.json.
126
Figure 176: Pbiviz Create New Visual
Next, enter the newly created folder and execute the command in Code Listing 5.
pbiviz start
The following step enables the mode developer visual for testing—from the PowerBI service, we go to
Settings.
127
Figure 179: Power BI Service—report and new visual—sequence
• Refresh Visual—you can manually select the visual if the autoreload is off.
• Toggle Autoreload—when the visual is on, it will be updated automatically every time the file is
saved.
• Show Dataviews—shows the visual’s underlying dataview for debugging.
• Get Help—links to the documentation.
• Send Feedback—for sharing experiences.
In order to create the distribution packet, follow the Node.js prompt to the folder containing the visual
and execute the command in Code Listing 6.
pbiviz package
128
Figure 180: Pbiviz Create New Package
By navigating to the subfolder “dist,” you will notice the .pbiviz file, useful for importing as a custom
visual within the visualization objects.
129
Chapter 7 Power BI Embedded
Power BI Tiles
Power BI can be embedded in the Office suite (for example, PowerPoint).
In PowerPoint, it is sufficient to insert an add-in from the ribbon via the Insert, Store within the Add-ins
section. We must look for Power BI Tiles in the store and install it; if it is installed, we must recall it in
the Add-ins section.
130
Figure 183: PowerPoint Online—Power BI Add-in
131
Figure 185: Power Point Online—Power BI Add-in
We can also run a tile refresh. Power BI allows you to update data and information dynamically in a
way that’s somewhat analogous to the way online speakers join and leave a group conversation.
132
Figure 187: PowerPoint Online presentation with Power BI Dashboard
Power BI Embedded
Power BI Embedded is an Azure service that allows app developers to bring the Power BI experience
and intelligence to their applications. The applications that integrate Power BI Embedded have users
with distinct licensed functionalities. Those applications can also access data elements incorporated
as graphs and reports, which can now be fed through Microsoft Power BI Embedded. The users do
not need a Power BI account to use the app. They can continue accessing the application as before
without authentication, as well as displaying and interacting with the Power BI reports without needing
possible further licenses.
133
Conceptual model
As with any Azure service, the resources of Power BI Embedded are provided through the Azure
Resource Manager API. In this case, the resource being provided is present in the Power BI
Workspace Collection.
Workspace Collection
A Workspace Collection is an upper-level container of Azure that contains resources and the
possibility of zero or more Workspaces. The Workspace Collections have all the standard Azure
properties:
• Access keys—keys used when we safely call the API of Power BI.
• Users—Azure Active Directory (AAD) users, who have available administrator rights to
manage the Power BI Workspace Collections through the Azure ARM API.
• Region—as part of a Workspace Collection supply, we are able to select a region to carry out
the supply.
Workspace
A workspace is a content container of Power BI that can include datasets, reports, and dashboards.
Remember that a workspace is empty when it is created. A Power BI Desktop can be used and
published in its own workspace by using the Power BI REST APIs.
134
Use of Workspace Collections and workspaces
Workspace Collections and workspaces are content containers, and they are used to arrange and
improve the design of the application being created. We can use many ways to arrange the content
within them. We can choose to put the entire content inside a workspace and then, at a later time, use
the Application Authentication Tokens (app tokens) to split the content further.
Cached datasets
The datasets saved in the caches can be previewed. However, it is not possible to update the saved
data in the cache once it has been uploaded on Power BI Embedded.
The app tokens are used for authentication in Power BI Embedded. There are three types of app
tokens:
These tokens are used for the various phases of the interaction with Power BI Embedded. The tokens
are designed in order to delegate authorizations from our app to Power BI.
With Microsoft Power BI Embedded, we can integrate Power BI reports directly into our own web
application or mobile applications.
1. Download and decompress: Power BI Embedded. Integrate a report into a web app sample on
GitHub.
135
2. Open PowerBI-embedded.sln in Visual Studio. You might need to carry out the commands to
update the NuGET packets used in the solution.
3. Build the solution.
4. Run the console ProvisionSample application. In this example, the console application
provisions a workspace, and it is possible to import a PBIX file.
5. Provision a new workspace in a collection of existing workspaces.
Next, we insert the name of the Workspace Collection and the Access Key. Figure 190 shows this
procedure in the Azure portal.
136
Figure 190: Azure Portal—Power BI Embedded, Create a workspace collection—sequence
Copy and save the newly created Workspace ID. You will find this in the Azure portal.
In order to import a PBIX (Power BI desktop file) into an Azure Workspace, you can use an existing
workspace or create a new one. If you do not have a PBIX file, you can experiment with an example
Retail Sales Analysis PBIX file from Microsoft.
137
Insert a descriptive name for the dataset content if one is requested.
At this point, the Power BI PBIX file has been imported into its own workspace.
Here are the steps for setting up the sample web app:
1. In the Power BI Embedded Visual Studio solution, select the web application EmbedSample,
followed by Set as StartUp project.
2. Open the web.config file associated with the EmbedSample web application, then edit the
appSettings section to supply values for the AccessKey, WorkspaceCollection, and WorkspaceId
keys.
Code Listing 7 web.config
<appSettings>
</appSettings>
138
After selecting a report, the web application Embed Sample will look like Figure 193.
The sample code is separated into sections that include the filename of the PowerBI-embedded.sln
solution so that the code can be easily found in the sample.
Model
The sample is composed of ReportsViewModel and ReportViewModel.
139
}
Connection string
The connection string must be composed as shown in Code Listing 10.
Data Source=tcp:MyServer.database.windows.net,1433;Initial
Catalog=MyDatabase
Using the common server and database attributes will bring a negative result. For instance, see Code
Listing 11.
Server=tcp:MyServer.database.windows.net,1433;Database=MyDatabase
View
The view displays and manages both reports and report.
Reports.cshtml interacts with Model.Reports to create an ActionLink. The ActionLink is composed of:
Title (the name of the report) and the QueryString (a link to the Report ID).
140
Code Listing 12 Reports.cshtml
<div class="panel-body">
<li class="@reportClass">
</li>
</ul>
</div>
</div>
The Report.cshtml sets up the Model.AccessToken and the Lambda expression for the
PowerBIReportFor.
@model ReportViewModel
@Html.PowerBIAccessToken(Model.AccessToken)
</div>
141
Controller
DashboardController.cs creates a PowerBIClient and passes to it the app token. A JSON Web Token
(JWT) is generated from the Signing Key of the credentials. The credentials are used to create an
application request for PowerBIClient. Once the PowerBIClient has been instantiated, GetReports()
and GetReportsAsync() can be called.
CreatePowerBIClient()
};
return client;
ActionResult Reports()
var reportsResponse =
client.Reports.GetReports(this.workspaceCollection,
this.workspaceId);
Reports = reportsResponse.Value.ToList()
142
};
return PartialView(viewModel);
var embedToken =
PowerBIToken.CreateReportEmbedToken(this.workspaceCollection,
this.workspaceId, report.Id);
Report = report,
AccessToken = embedToken.Generate(this.accessKey)
};
return View(viewModel);
143
Figure 194 shows a snippet of powerbi.js present in the example of Power BI Embedded.
In order to do so, we have to add a $filter to the interrogation parameters with a URL-escaped eq
operator for the iframe src url with the specific filter. Code Listing 15 shows a query syntax.
https://app.powerbi.com/reportEmbed?reportId=d2a0ea38-...-9673-
ee9655d54a4a&$filter=tableName/fieldName}%20eq%20'{fieldValue}'
144
Chapter 8 Power BI Gateway: Data Security
If the data source we have is on-premises, we can’t update from Power BI automatically, which
instead runs in the cloud. Therefore, we need to implement a communication channel between what is
in the cloud and what runs on-premises. This is possible through the gateways that are made
available by Power BI. In particular, we have the personal gateway and the on-premises data
gateway, both free and directly downloadable from the Power BI portal.
The personal gateway is a Windows service that can act as a data source for Windows applications. If
the user is an administrator, the personal gateway will run as a Windows service by using the same
credentials of the user who installed it. But if the user is not an administrator of the machine, the
personal gateway will run as a Windows application. The personal gateway service runs as a 64-bit
Windows application that communicates with Power BI using the Azure Service Bus, which allows a
secure channel for data transfer. It is very important to specify here that we do not need to open
firewall ports in the infrastructure in order to accept incoming connections because the Azure Service
Bus works in “relay” mode and therefore all communicating entities are clients of the Services bus.
This means we must be open to the possibility of open outgoing connections, although incoming
connections are not required. It is a little bit like the chat functionality in which all the users use chat
clients, but in fact the communication among them is bidirectional.
The personal gateway cannot run in combination with other gateways, therefore it must be the only
gateway present on the machine on which it is installed. It is called a personal gateway because it is
meant for personal use. For instance: the user who works with Excel workbooks daily and decides to
load the workbooks on Power BI would need a data refresh because they are working on-premises.
We can reach the same result by installing the personal gateway in a personal laptop. The personal
gateway will be linked to the personal Power BI workspace of the user who installed it. At that point,
we will be able to update the data exactly as it occurred when the workbook was on-premises. But if
we think about an organization with more users, even 10 users, each of them should install their own
personal gateway, so that they will have the ability to update the data. To solve this, the on-premises
data gateway is available, which is indeed meant for enterprise environments.
The on-premises data gateway has been designed to run on-premises 24/7. The results of the queries
are sent safely (SSL) through the Azure Service Bus.
145
Figure 195: Power BI Gateway rule
With Power BI, the Enterprise Gateway is installed on a dedicated server. There is also a recovery
procedure in case of failure. In such a case, if we know the recovery key, we can carry out the refresh
even on a different server. Also remember that the personal gateway interrupts the refresh
functionality when the user’s is shut down. With the Power BI Enterprise Gateway, we can have a
constant refresh, seven days a week and 24 hours a day. The on-premises data gateway works by
using a channel of Azure Service Bus similar to how the personal gateway works. Azure Service Bus
gives us the ability to interact with data sources such as Analysis Services. The gateway allows us to
accept the account from which the query comes. In the specific case of a connection to a data source
of Analysis Services, we can accept the so-called Effective User Name. The gateway will receive the
users as well as carry out the query on behalf of the specific user, and the result of the query will
depend only on the users who updated the report on Power BI. Another essential aspect of the on-
premises data gateway is that it allows us to manage data sources in a centralized way. The user who
installs an on-premises data gateway is the administrator of the data sources. Furthermore, the
administrator can add other administrators and set up different types of data sources, such as SQL
Server, Database Oracle, and many others. Access to the data sources can be set up on the basis of
the destination user. As administrators, we can decide that only one category of users will be able to
access that specific data source, while the others cannot.
146