power squared: powerquery with powerbi€¦ · • use functions to call apis for data, such as...

18

Upload: others

Post on 22-May-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment
Page 2: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

Power Squared: PowerQuery with PowerBI

Solution Architect – Business Intelligence and Advanced AnalyticsEmail: [email protected]

Bryan Campbell

#HSCCATLANTA19

Session Track: Analytics and AI

Page 3: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

Power Query Introduction

Folder As A Source

SQL Query Mashup

Scrape the Web with Functions

01

02

03

04

05

C O N T E N T S

Page 4: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 4Think Digital Customer Conference 2019

Power Query – The little ETL engine that could…

• Based on the M query language• No or Low coding required• Customizable• Can leverage on prem and cloud sources• Exists in Excel 2013 and beyond

A brief introduction

Page 5: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 5Think Digital Customer Conference 2019

3 Use Cases

• Folder as a Source• Any business analyst can build an ETL process• Excel has the same engine behind the scenes

• SQL Query Mashup – Query Folding• “View Native Query”• Let Power BI write your SQL and optimize your data import

• Scraping Web Pages via Functions• Use of parameters to create functions• Automate webscrapes, or other repeatable tasks

Page 6: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 6Think Digital Customer Conference 2019

Folder as a Source

• Analysts will often run repetitious tasks over and over to extract source data

• Typical query interfaces will have timeouts built in

• Parameters are sometimes applied to “break up” the work into smaller chunks

• These chunks are then put back together with VBA code, macros, Excel ‘magic’

Page 7: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 7Think Digital Customer Conference 2019

Folder as a Source

• About this dataset:• Broken into 5 pieces• Pivoted by the source• Contains double row header, but no footer or merged cells

• Demo

Page 8: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 8Think Digital Customer Conference 2019

Folder as a Source

• Attach to the folder of like files• Remove any ‘not like’ files

• Train PQ to handle the structure of the data• Headers, footers, subtotals, errors in the data

• Unpivot• Often times data is pre-summarized by the source

• Create a repeatable process• And this exists in Excel???

Summary

Page 9: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 9Think Digital Customer Conference 2019

SQL Query Mashup – Query Folding

• Power Query contains a GUI based SQL writer• “View Native Query”

• Proper selection of steps early in the transform will help optimize server load• Merge = Join• Append = Union

Page 10: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 10Think Digital Customer Conference 2019

SQL Query Mashup – Query Folding

• Speed of refresh improvements• Pulling fewer columns and/or

fewer rows means less server load and network load

Page 11: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 11Think Digital Customer Conference 2019

SQL Query Mashup – Query Folding

• Size of data model

Page 12: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 12Think Digital Customer Conference 2019

SQL Query Mashup – Query Folding

• Aggregation of the data at the source…

Page 13: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 13Think Digital Customer Conference 2019

SQL Query Mashup – Query Folding

• Power Query contains a GUI based SQL writer• “View Native Query”

• Proper selection of steps early in the transform will help optimize server load• Merge = Join• Append = Union• Custom SQL is NOT optimized• Queries on Views are less efficient, but still improve

Summary

Page 14: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 14Think Digital Customer Conference 2019

Web Page as a Source - Parameters and Functions

• www.boxofficemojo.com dataset• All time domestic gross

Page 15: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 15Think Digital Customer Conference 2019

Web Page as a Source - Parameters and Functions

• Dataset is paginated over several pages• We want to pull this data• But not 1 page at a time…

• Demo

Page 16: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 16Think Digital Customer Conference 2019

Web Page as a Source - Parameters and Functions

• www.boxofficemojo.com dataset• Go to AllTime, then DOMESTIC

• Bring in a page via the webpage as a source, name this query WebPage• Set up a Parameter as TEXT, call this parameter PAGENUM• Insert this Parameter into the query formula bar• Create a blank query “DATA” = {1..3}, covert to table and datatype = text• Create the function fxGetWebPage from the WebPage query• Invoke custom function to your generated list query, and expand• Disable loading of the fxGetWebPage• Advanced Editor – add in a “WAIT UNTIL”• Check datatypes and errors

Step by Step Review

Page 17: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 17Think Digital Customer Conference 2019

Comments

• Power Query is often overlooked• A stepping stone for business analyst to grow further, from the Excel skillset

into relational database skillset• Query Mashup is UNDERUTILIZED – too important to not take advantage of• Use functions to call APIs for data, such as Microsoft Cognitive API for

language translation, key phrase extraction, sentiment analysis, image tagging, or machine learning models

• Don’t forget this entire engine is both behind Excel and in the Web (Dataflows, Microsoft Flow, PowerApps, etc)

Page 18: Power Squared: PowerQuery with PowerBI€¦ · • Use functions to call APIs for data, such as Microsoft Cognitive API for language translation, key phrase extraction, sentiment

/ 18Think Digital Customer Conference 2019

Power Squared: PowerQuery with PowerBI

Questions??

• Bryan Campbell• [email protected]