Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

Free eBook - Mastering Microsoft Power BI

3.2 (21 reviews total)
By Powell
  • A new free eBook every day on the latest in tech
  • 30 permanently free eBooks from our core tech library
  1. Planning Power BI Projects
About this book
This book is intended for business intelligence professionals responsible for the design and development of Power BI content as well as managers, architects and administrators who oversee Power BI projects and deployments. The chapters flow from the planning of a Power BI project through the development and distribution of content to the administration of Power BI for an organization. BI developers will learn how to create sustainable and impactful Power BI datasets, reports, and dashboards. This includes connecting to data sources, shaping and enhancing source data, and developing an analytical data model. Additionally, top report and dashboard design practices are described using features such as Bookmarks and the Power KPI visual. BI managers will learn how Power BI’s tools work together such as with the On-premises data gateway and how content can be staged and securely distributed via Apps. Additionally, both the Power BI Report Server and Power BI Premium are reviewed. By the end of this book, you will be confident in creating effective charts, tables, reports or dashboards for any kind of data using the tools and techniques in Microsoft Power BI.
Publication date:
March 2018
Publisher
Packt
ISBN
9781788297233

 

Connecting to Sources and Transforming Data with M

This chapter follows up on the dataset planning process described in the previous chapter by implementing M queries in a new Power BI Desktop file to retrieve the required fact and dimension tables. Parameters and variables are used to access a set of SQL views reflecting the data warehouse tables inside a SQL Server database and the Annual Sales Plan data contained in an Excel workbook. Additional M queries are developed to support relationships between the sales plan and dimension tables and to promote greater usability and manageability of the dataset.

Three examples of implementing data transformations and logic within M queries, such as the creation of a dynamic customer history segment column, are included. Finally, tools for editing and managing M queries, such as extensions for Visual Studio and Visual Studio Code, are...

 

Query design per dataset mode

Many common M queries can be written for both import and DirectQuery datasets, but with widely different implications for the source system resources utilized and the performance of the analytical queries from Power BI. It's essential that the mode of the dataset (import or DirectQuery) has been determined in advance of the development of the data access queries and that this decision is reflected in the M queries of the dataset.

The M queries supporting a Power BI dataset import mode should exclude, or possibly split, columns with many unique values, such as a Transaction Number column, as these columns consume relatively high levels of memory. A standard design technique for import mode models is to exclude derived fact table columns with relatively more unique values when these values can be computed via simple DAX measure expressions based...

 

Data sources

Data source connectivity is one of the strengths of Power BI, due to the vast list of standard data source connectors included in Power BI Desktop, in addition, to support for Open Database Connectivity (ODBC) and Object Linking and Embedding, Database (OLE DB) connections. The breadth of data connectivity options is further bolstered by the ability for developers to create custom Power BI data connectors for a specific application, service, or data source. Custom data connectors, the data retrieval processes created for all data sources for Power BI, and other Microsoft applications are developed with the M language.

Power BI's data connectors are consistently extended and improved with each monthly release of Power BI Desktop. New data sources are commonly added as a preview or beta release feature and previous beta connectors are moved from beta to general...

 

SQL views

As described in the Dataset planning section of Chapter 1, Planning Power BI Projects, a set of SQL views should be created within the data source and these objects, rather than the database tables, should be accessed by the Power BI dataset. Each fact and dimension table required by the Power BI dataset should have its own SQL view and its own M query within the dataset that references this view. The SQL views should preferably be assigned to a dedicated database schema and identify the dimension or fact table represented as shown in the following screenshot:

Views assigned to BI schema in SQL Server
A common practice is to create a database schema specific to the given dataset being created or to the specific set of reports and dashboards required for a project. However, as suggested in the Data Warehouse Bus Matrix section of Chapter 1, Planning Power BI Projects...
 

M queries

With the SQL views created, the data sources configured, and the Power BI Desktop environment options applied, the dataset designer can finally develop the data retrieval queries and parameters of the dataset.

Within the Power Query Editor of Power BI Desktop, group folders can be used to organize M queries into common categories such as Data Source Parameters, Staging Queries, Fact table Queries, Dimension Table Queries, and Bridge Table Queries as shown in the following screenshot:

Power Query Editor in Power BI Desktop with group folders

The parameters and queries displayed with a gray font are included in the refresh process of the dataset but not loaded to the data modeling layer. For example, the AdWorksSQLServer query displayed in the preceding image merely exposes the objects of the SQL Server database via the Sql.Database() M function for other queries to reference...

 

Query folding

Query folding is one of the most powerful and important capabilities of the M language as it translates M expressions into SQL statements that can be executed by the source system. With query folding, M serves as an abstraction layer to implement both common and complex data cleansing and transformation operations while still leveraging source system resources. When implementing any remaining logic or data transformations via M functions, a top priority of the dataset designer is to ensure that these operations are folded to the data source.

In the following M query, a Table.RemoveColumns() M function is applied against the SQL view for the Internet Sales fact table to exclude three columns that are not needed for the dataset:

Power Query Editor: View Native Query

The additional step is translated to a SQL query that simply doesn't select the three columns...

 

M Query examples

The M query language includes hundreds of functions and several books have been written about to its application. The greater purpose of this chapter is to understand M queries in the context of a corporate Power BI solution that primarily leverages an IT-managed data warehouse. As shown in the examples shared in the M Queries section earlier, the combination of a mature data warehouse and a layer of SQL view objects within this source may eliminate any need for further data transformations. However, Power BI Dataset designers should still be familiar with the fundamentals of M queries and their most common use cases, as it's often necessary to further extend and enhance source data.

The following sections demonstrate three common data transformation scenarios that can be implemented in M. Beyond retrieving the correct results, the M queries also generate...

 

M editing tools

Power BI Desktop stores the M code for queries created via the Power Query Editor graphical interface or the Advanced Editor within M documents for repeatable execution. Similar to other languages and project types, code editing tools are available to support the development, documentation, and version control of M queries. Dataset designers can use Visual Studio or Visual Studio Code to author and manage the M queries for Power BI and other Microsoft projects. These tools include common development features, such as IntelliSense, syntax highlighting, and integrated source control.

Advanced Editor

In Power BI Desktop, the M code for each query can be accessed from the Advanced Editor window within the Power...

 

Summary

In this chapter, we've covered all components of the data retrieval process used to support the dataset for this project as described in Chapter 1, Planning Power BI Projects. This includes the layer of SQL views within a database source, source connectivity parameters in Power BI Desktop, and the M queries used to define and load the dimension and fact tables of the dataset. In constructing a data access layer and retrieval process for a dataset, we've also discussed the design considerations relative to import and DirectQuery datasets, Power BI Desktop configuration options, and data source privacy levels. Additionally, we've reviewed core concepts of the M language, including query folding, item access, and data types. Moreover, we've reviewed three examples of efficiently implementing impactful data transformation logic via M queries as well as...

About the Author
  • Powell

    Brett Powell is the owner of and business intelligence consultant at Frontline Analytics LLC, a data and analytics research and consulting firm and Microsoft Power BI partner. He has worked with Power BI technologies since they were first introduced as the PowerPivot add-in for Excel 2010 and has been a Power BI architect and lead BI consultant for organizations across the retail, manufacturing, and financial services industries. Additionally, Brett has led Boston's Power BI User Group, delivered presentations at technology events such as Power BI World Tour, and maintains the popular Insight Quest Microsoft BI blog.

    Browse publications by this author
Latest Reviews (21 reviews total)
I like the examples and techniques proposed to assist in data analytics
This is one of the most information-dense technical reference books I've read in a long time. By this I mean -- it packs a tremendous amount of useful detail on each page. I'm coming from this as a 20+ year user of database tools, MCSA in SQL Server and someone motivated to really learn/apply Power BI as a consultant. This book really delivers in terms of in-depth explanations and content you can use to create PBI solutions. It goes above and beyond in another dimension as well: the authors very useful digressions on best-practises and real-world advice for things like visualizations and frameworks for managing users' competing needs. This is truly a useful text for someone interested in designing / deploying / managing mid-size corporate installations of BI solutions using Microsoft tools.Caution -- This is not an introductory text. If you are interested in casual use of PBI, there are probably more accessible books out there.It is easy to give this 5 stars on its content -- but would also mention a couple of minor things: - the included code samples are not directly useable. The author cautions about this in the text. Of 3 points raised, this is this the most significant. It would have been nice to be able to eyeball the worked examples on my workstation. - Minor: The index in the back is pretty sparse. For example, you won't find "hierarchy" mentioned anywhere there but have to read through the table of contents to find that section. - Minor: The printing / paper / binding quality is fine -- but I wish Packt would put more thought into typography. It's easier to digest this kind of material when the publisher uses more finesse in use of different sized/numbered heads. As-is, the chapter content just seems to run together.FWIW -- I've previously read: - Teo Lachev's "Applied MS PowerBI" (2nd ed) -- which is also good, particularly for someone first experimenting with Power BI. - Russo & Ferrari "Definitive Guide to Dax" (1st ed) -- the go-to reference on DAX.Aside: I have no affiliation with the author or publisher. I purchased this on Amazon, etc.
I just started this book and already have found it incredibly useful. I relied heavily on Brett's first book in my Power BI work. This new one is wonderful and updated to include the latest features. What I love about Brett's books is that he provides a higher level view than the Microsoft free online education, so you can understand how the different features and methods of doing things interact and compare before diving into the details, which are also provided in a clear and concise way. The information is presented from the ground-up in a logical manner that promotes a solid foundation for learning. In addition, I can easily skim the Table of Contents to find exactly what I need, and it covers every essential Power BI topic. Brett is truly the premier author for books in this field.
Recommended For You
DAX Cookbook

Solve real-world business problems by learning how to create common industry key performance indicators and other calculations using DAX within Microsoft products such as Power BI, SQL Server, and Excel.

By Greg Deckler
Microsoft Power BI Quick Start Guide - Second Edition

An accessible fast paced introduction to all aspects of Power BI for new or aspiring BI professionals, data analysts, and data visualizers

By Devin Knight and 3 more
Microsoft Power BI Complete Reference

Design, develop, and master efficient Power BI solutions for impactful business insights

By Devin Knight and 4 more
Hands-On Business Intelligence with DAX

Implement business intelligence (BI), data modeling, and data analytics within Microsoft products such as Power BI, SQL Server, and Excel

By Ian Horne