Microsoft Power BI CookbookCreating Business Intelligence Solutions of Analytical Data Models, Reports, and Dashboards... Automatic data type detection Numeric data types Power BI Deskto
Trang 2Microsoft Power BI Cookbook
Creating Business Intelligence Solutions of Analytical Data Models, Reports, and Dashboards
Trang 3Brett Powell
BIRMINGHAM - MUMBAI
Trang 6Microsoft Power BI Cookbook
Copyright © 2017 Packt Publishing
All rights reserved No part of this book may be reproduced, stored in a retrievalsystem, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews
Every effort has been made in the preparation of this book to ensure the accuracy ofthe information presented However, the information contained in this book is soldwithout warranty, either express or implied Neither the author, nor Packt Publishing,and its dealers and distributors will be held liable for any damages caused or alleged
to be caused directly or indirectly by this book
Packt Publishing has endeavored to provide trademark information about all of thecompanies and products mentioned in this book by the appropriate use of capitals.However, Packt Publishing cannot guarantee the accuracy of this information
First published: September 2017
Trang 7ISBN 978-1-78829-014-2
www.packtpub.com
Trang 9Ruben Oliva Ramos
Juan Tomas Oliva Ramos
Trang 10Acquisition Editor
Varsha Shetty
Indexer
Tejal Daruwale Soni
Content Development Editor
Trang 12Microsoft Power BI Cookbook is a great example of how to leverage the multitude of
features that are available in Power BI You will find some great examples in thisbook that will first explain the issues and then give a solution on how to achieve thedesired result I, personally, learned something when going through this cookbookand all the recipes provided in it This is a book that can be picked up and referencedwhen looking for solutions for particular challenges or issues Likewise, it is a greatread from cover to cover to expand your skills, which in turn will help build greatPower BI Models for your clients/customers
Gilbert Quevauvilliers,
Microsoft MVP - Power BI & Microsoft Power BI Consultant at Fourmoo
Trang 14About the Author
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 firstintroduced as the SQL Server 2008R2 PowerPivot add-in for Excel 2010 He hascontributed to the design and development of Microsoft and Power BI solutions ofdiverse scale and complexity across the retail, manufacturing, financial, and servicesindustries Brett regularly blogs and shares technical papers regarding the latest
MSBI and Power BI features and development techniques and patterns at InsightQuest He is also an organizer of the Boston BI User Group
Erin Stellato, featured in Developing Solutions for System Monitoring and
Administration, is a principal consultant at SQLskills and Microsoft Data Platform
MVP
I'd first like to thank Varsha Shetty, acquisition editor at Packt, for giving me the opportunity to author this book and her guidance throughout the planning process I'd also like to thank the Packt board and team for approving the book outline and for their flexibility with page counts and topics Like most Power BI projects, we followed an agile delivery model in creating this book and this allowed us to
include essential details supporting the recipes and the latest Power BI features Additionally, I'd like to thank Mayur Pawanikar, content editor at Packt, for his thorough reviews and guidance throughout the development process His
contributions were invaluable to the structure and overall quality of the book I'd also like to thank Gilbert Quevauvilliers and Juan Tomas Oliva Ramos for their technical reviews and suggestions.
Finally, I'd like to thank the Power BI team for creating such an amazing platform and for everyone around the Power BI community that contributes documentation, white papers, presentations, videos, blogs, and more
Trang 16About the Reviewers
Gilbert Quevauvilliers has been working in the BI space for the past 9 years He
started out learning the basics of business intelligence on the Microsoft stack, and astime went on, he became more experienced Gilbert has since moved into the Power
BI space, after starting out with Power Pivot in Excel 2010 He has used Power BIsince its inception and works exclusively in it He has been recognized with the
Microsoft MVP award for his contributions to the community and helping other users
Gilbert is currently consulting in his own company, called FourMoo (which
represents the four family members) Fourmoo provides Microsoft Power BI
solutions for business challenges by using customers' data and working with theirbusiness users Gilbert also has an active blog at http://www.fourmoo.com/blog/ This is thefirst book that he has been asked to review
I would like to say a big thanks to my wife, Sian, for her endless support and for helping me find the time to review this book.
Ruben Oliva Ramos is a computer systems engineer from Tecnologico de Leon
Institute, with a master's degree in computer and electronic systems engineering,teleinformatics, and networking specialization from the University of Salle Bajio inLeon, Guanajuato, Mexico He has more than 5 years of experience in developingweb applications to control and monitor devices connected with Arduino and
Raspberry Pi using web frameworks and cloud services to build the Internet of
Things applications
He is a mechatronics teacher at the University of Salle Bajio and teaches students ofthe master's degree in design and engineering of mechatronics systems Ruben alsoworks at Centro de Bachillerato Tecnologico Industrial 225 in Leon, Guanajuato,Mexico, teaching subjects such as electronics, robotics and control, automation, andmicrocontrollers at Mechatronics Technician Career; he is a consultant and
developer for projects in areas such as monitoring systems and datalogger data usingtechnologies (such as Android, iOS, Windows Phone, HTML5, PHP, CSS, Ajax,JavaScript, Angular, and ASP.NET), databases (such as SQlite, MongoDB, and
MySQL), web servers (such as Node.js and IIS), hardware programming (such asArduino, Raspberry pi, Ethernet Shield, GPS, and GSM/GPRS, ESP8266), and
control and monitor systems for data acquisition and programming
He wrote Internet of Things Programming with JavaScript by Packt Publishing He
is also involved in the monitoring, controlling, and acquisition of data with Arduinoand Visual Basic NET for Alfaomega
Trang 17I would like to thank my savior and lord, Jesus Christ, for giving me the strength and courage to pursue this project; my dearest wife, Mayte; our two lovely sons, Ruben and Dario; my dear father, Ruben; my dearest mom, Rosalia; my brother, Juan Tomas; and my sister, Rosalia, whom I love, for all their support while
reviewing this book, for allowing me to pursue my dream, and tolerating not being with them after my busy day job.
Juan Tomás Oliva Ramos is an environmental engineer from the university of
Guanajuato, with a master's degree in administrative engineering and quality He hasmore than 5 years of experience in management and development of patents,
technological innovation projects, and development of technological solutions
through the statistical control of processes
He is a teacher of statistics, entrepreneurship and technological development ofprojects since 2011 He became an entrepreneur mentor, and started a new
department of technology management and entrepreneurship at Instituto TecnologicoSuperior de Purisima del Rincon
He is a Packt Publishing reviewer and he has worked on the book: Wearable designs
for Smart watches, Smart TV's and Android mobile devices.
He has developed prototypes through programming and automation technologies forthe improvement of operations, which have been registered to apply for his patent
I want to thank God for giving me wisdom and humility to review this book.
I want to thank Packt for giving me the opportunity to review this amazing book and to collaborate with a group of committed people.
I want to thank my beautiful wife, Brenda, our two magic princesses, Regina and Renata, and our next member, Angel Tadeo, all of you, give me the strength,
happiness and joy to start a new day Thanks for being my family.
Trang 19For support files and downloads related to your book, please visit www.PacktPub.com.Did you know that Packt offers eBook versions of every book published, with PDFand ePub files available? You can upgrade to the eBook version at www.PacktPub.com,and as a print book customer, you are entitled to a discount on the eBook copy
Get in touch with us at service@packtpub.com for more details At www.PacktPub.com, youcan also read a collection of free technical articles, sign up for a range of free
newsletters and receive exclusive discounts and offers on Packt books and eBooks
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt Mapt gives you full access to allPackt books and video courses, as well as industry-leading tools to help you planyour personal development and advance your career
Trang 23Customer Feedback
Thanks for purchasing this Packt book At Packt, quality is at the heart of our
editorial process To help us improve, please leave us an honest review on thisbook's Amazon page at https://www.amazon.com/dp/1788290143
If you'd like to join our team of regular reviewers, you can email us at
customerreviews@packtpub.com We award our regular reviewers with free eBooks andvideos in exchange for their valuable feedback Help us be relentless in improvingour products!
Trang 25Table of Contents
Preface
What this book covers
What you need for this book
Who this book is for
Piracy Questions
1 Configuring Power BI Development Tools
There's more
See also Power BI's advantages over Excel Power BI Security and Data Source Privacy Installing the On-Premises Data Gateway
Getting ready Hardware and network configuration How to do it
Installation of on-premises gateway How it works
Gateway recovery key There's more
Trang 26There's more
Guy in a Cube video channel
2 Accessing and Retrieving Data
Introduction
Viewing and analyzing M functions
Getting ready How to do it
Formula Bar Advanced Editor window How it works
Query folding
M query structure Lazy evaluation There's more
Partial query folding Limitations of query folding See also
M language references Establishing and managing connections to data sources
Getting ready How to do it
Isolate data sources from individual queries Query groups
Manage source credentials and privacy levels How it works
Data Source settings Data source privacy settings There's more
See also Building source queries for DirectQuery models
Getting ready How to do it
Applying M transformations with DirectQuery models How it works
There's more
DirectQuery project candidates DirectQuery performance See also
Importing data to Power BI Desktop models
How to do it
Denormalize a dimension Provide automatic sorting How it works
There's more
One GB dataset limit and Power BI Premium
Trang 27Conditional expression evaluation
Query folding of custom columns
There's more
Add column from example
Conditional columns interface
DAX calculated columns
Error handling and comments
Integrating multiple queries
Getting ready
How to do it
Trang 28Consolidate files Self-joining querying How it works
Nested join versus flat join Append multiple files There's more
Combine binaries Staging queries versus inline queries See also
Choosing column data types
How to do it
Remove automatic type detection steps Align relationship column data types Add numeric columns from text columns Use fixed decimal number for precision How it works
Automatic data type detection Numeric data types
Power BI Desktop automatic time intelligence There's more
Data type impacts Date with locale Percentage data type See also
Visualizing the M library
Four-step dimensional design process Data warehouse and implementation bus matrix Choose the dataset storage mode - Import or DirectQuery In-Memory mode
DirectQuery mode How it works
DAX formula and storage engine There's more
Project ingestion questions Power BI delivery approaches See also
Trang 29Implementing a multi fact data model
How to do it
SQL view layer
M queries in Power BI Desktop
Create model relationships
Author DAX measures
Configure model metadata
Single, bidirectional, and CROSSFILTER()
Single direction relationships Bidirectional relationship CROSSFILTER() Measure Many-to-many relationships
Bidirectional cross-filtering for many-to-many How it works
Trang 30Row level security visibility
Visibility features from SSAS
Embedding business definitions into DAX measures Getting ready
How to do it
Sales and cost metrics
Margin and count metrics
Active verus inactive customers
Actual versus budget model and measures How it works
Filter Context Functions
Correlation coefficient syntax
Goodness-of-Fit logic and syntax
Supporting virtual table relationships
How to do it
Segmentation example
Trang 31Summary to detail example Actual versus plan How it works
Year and month selected Virtual relationship functions There's more
Multiple dimensions Alternatives to virtual relationships See also
Creating browsable model hierarchies and groups
DAX calculated columns as rare exceptions Natural hierarchies versus unnatural hierarchies Grouping dates and numbers
DirectQuery models supported See also
4 Authoring Power BI Reports
Introduction
Building rich and intuitive Power BI reports
Getting ready Stakeholder Matrix How to do it
Report planning and design process Report Design Example
European Sales and Margin Report Page European country sales and margin report page How it works
European sales report design There's more
Power BI report design checklist Custom visuals
Published Power BI datasets as data sources See also
Creating table and matrix visuals
How to do it
Table visual exceptions Identifying blanks in tables
Trang 32Matrix visual hierarchies
How it works
Matrix visual navigation
There's more
URL and mail to email support
Percent of total formatting
Measures on matrix rows
Data bar conditional formatting
Utilizing graphical visualization types
Getting ready
Choosing visual types
How to do it
Waterfall chart for variance analysis
Line chart with conditional formatting Shape map visualization
Create featured Q&A questions
Parameterized Q&A report
Current year Measures
Associating slicers with report pages
How to do it
Trang 33Configure dimension slicers Horizontal slicers Customize a date slicer Relative date filters How it works
Date slicer There's more
Text search Numeric range slicers Applying filters at different scopes
How to do it
Report and page level filters Visual level filter - top N How it works
DAX queries from report, page, and visual Filters There's more
Advanced report and page level filters Formatting reports for publication
How to do it
Visual alignment and distribution Shapes as backgrounds and groups There's more
Snap objects to grid and keyboard shortcuts Textbox with email link
Format painter See also
Designing mobile report layouts
Getting ready Plan for mobile consumption How to do it
Phone layout - Europe report page Phone layout - United Kingdom report page How it works
How to do it
Dashboard design process
Trang 34Dynamic date columns
KPI target measures
How it works
Target measure - trailing 6 months
Preparing datasets and reports for Q & A natural language queries Getting ready
Determine use cases and feasibility
How to do it
Prepare a model for Q & A
Model metadata Model design Apply synonyms
Analyze Q & a use cases Apply synonyms
Publish the dataset Embedding analytical context into visualizations
How to do it
Design the visual
Create the visual
Top 25 resellers with below -3% margin
Last year's top 50 products with below -10% growth How it works
Prior year rank measure
Visualizing performance relative to targets with KPIs and gauges How to do it
Create the visuals
Grouping KPIs
Publish KPIs to dashboard
How it works
Current month filter
Time intelligence measures
Leveraging Power BI reports in Power BI dashboards
How to do it
Define live page requirements
Create and publish to the dashboard
Trang 35Refine dashboard layout How it works
Live page slicers Deploying content from Excel and SSRS to Power BI Getting ready
How to do it
Publish and pin excel objects Pin SSRS report items Adding data alerts and email notifications to dashboards How to do it
Configure data alert Automate email notification How it works
6 Getting Serious with Date Intelligence
Introduction
Building a complete date dimension table
Getting ready How to do it
Date dimension design Required date dimension columns Date dimension planning and design Add date intelligence columns via SQL How it works
Date intelligence columns Loading the date dimension There's more
Role playing date dimensions Surrogate key date conversion Prepping the date dimension via the Query Editor How to do it
Date dimension M Query Add the date intelligence column via join How it works
Date dimension M query DirectQuery support Authoring date intelligence metrics across granularities Getting ready
How to do it
Current time period measures Prior time period measures Dynamic prior period measure How it works
Current and prior time period measures Developing advanced date intelligence metrics
How to do it
Count of days without sales
Trang 36Dynamic Prior Year-to-Date How it works
Dynamic prior period intelligence Simplifying date intelligence with DAX queries and calculated tables How to do it
Role playing date dimensions via calculated tables Date table logic query
Single and multiple URL parameters Dynamic embedded URLs
Trailing days query parameter filter Multi-parameter query filters How it works
Query folding of parameter value filters There's more
Power BI Service support Preserving report metadata with Power BI templates
Getting ready How to do it
Template parameters Export template Converting static queries into dynamic functions
SQL Server database Excel filename and path
Trang 37Stored procedure input parameters Generating a list of parameter values via queries
How to do it
Dynamic date parameter query Product subcategories parameter query There's more
DirectQuery support Capturing user selections with parameter tables
Forecast variables from Excel Power BI Desktop forecast model Source connection and unpivoted forecast tables Apply the forecast to historical values
Allocate the forecast according to the dimension variable inputs Create relationships, measures, and forecast visuals
Test and deploy forecasting tool How it works
8 Implementing Dynamic User-Based Visibility in Power BI
Introduction
Capturing the current user context of Power BI content
Getting ready How to do it
How it works
Power BI authentication There's more
USERNAME() versus USERPRINCIPALNAME() See also
Defining RLS roles and filtering expressions
Getting ready How to do it
United States online Bike Sales Role Europe reseller sales - mountain and touring Deploy security roles to Power BI
How it works
Filter transfer via relationships There's more
Managing security Dynamic columns and central permissions table Designing dynamic security models in Power BI
Trang 38Getting ready How to do it
There's more
Performance impact Building dynamic security in DirectQuery data models
Getting ready How to do it
FILTERS() and CONCATENATEX() Avoiding manual user clicks with user-based filtering logic
Getting ready How to do it
How it works
There's more
Personal filters feature coming to Power BI apps
9 Applying Advanced Analytics and Custom Visuals
Bullet chart custom visual Scoped quick insights How it works
There's more
Quick insights in Power BI Desktop Quick insights on published datasets Creating geospatial mapping visualizations with ArcGIS maps for Power BI Getting ready
How to do it
Trang 39Single field address
Customer clustering Map
There's more
ArcGIS map field wells
Conditional formatting logic
Chiclet slicer custom visual
Building animation and story telling capabilities
Getting ready
How to do it
Scatter chart with play axis
ArcGIS map timeline
Pulse chart custom visual
There's more
Bookmarks
Play axis custom visual
Storytelling custom visuals
Embedding statistical analyses into your model
Getting ready
How to do it
Regression table and measures
Residuals table and measures
First purchase date grouping
Days since last purchase grouping Detecting and analyzing clusters
Trang 40There's more
R clustering custom visuals Scatter chart-based clustering Forecasting and visualizing future results
Getting ready How to do it
Monthly forecast via date hierarchy Weekly sales forecast analysis How it works
Exponential smoothing Dynamic week status column There's more
Forecast requirements Using R functions and scripts to create visuals within Power BI
Getting ready How to do it
Base graphics histogram ggplot2 histogram How it works
Automatic duplicate removal Filter context
Constructing a monitoring visualization and analysis layer
Getting ready How to do it