Sie sind auf Seite 1von 45

Top 5 Power Query M

Functions that You


Dont Know
Reza Rad, DW/BI Architect and
Consultant
RADACAD

BID-309

Please silence
cell phones

Explore Everything PASS Has to Offer


Free SQL Server and BI Web Events

Free 1-day Training Events

Regional Event

This is Community

Business Analytics Training

Local User Groups Around


the World

Session Recordings

PASS Newsletter

Free Online Technical Training

Session Evaluations
Submit by 11:59 PM EST
Friday Nov. 7 to
WIN prizes

Your feedback is
important and valuable.

ways to access

Go to
passsummit.com/evals

Download the GuideBook App


and search: PASS Summit 2014

Evaluation Deadline:
11:59 PM EST, Sunday Nov. 16

Follow the QR code link displayed


on session signage throughout the
conference venue and in the
program guide

About Me: Reza Rad


DW/BI Architect, Consultant
SQL Server MVP
Author of SQL Server and BI books
Author of SSIS webcast series on RADACAD
Microsoft Certified Trainer
Microsoft Certified Professional
@Rad_Reza

a.raad.g@gmail.com

www.rad.pasfu.com

www.linkedin.com/in/rezarad

Agenda
Introduction to Power Query
Power Query Formula Language: M
Top Five M Functionalities
Date Dimension with Power Query
Power Query for Office 365 Benefits

Introduction to
Power Query

Power Query For Excel


Free to download!

Wide Range of Data Sources Supported

Online Search

Data Transformations on GUI

Load to Data Model

Query Can be Shared (Power BI)

Demo: Fetch
Movies Data
with Power
Query

Power Query
Formula
Language: M

What is M?
Everything that Happens on GUI works with a Code Behind
Code Behind is a Functional Language: M

More about Formula Language


M is much more powerful than Power Query GUI;
Not all functionalities of M implemented through GUI.
If you want to be Professional In Power Query; You should be
Expert in M
M is a functional language

Structure of M

M is Case Sensitive

M Syntax
let
TableA = #table({"CustomerId", "TranDate","TranCount"},
{
{1,DateTime.FromText("2014-01-01 01:00:00.000"),10},
{1,DateTime.FromText("2014-01-01 02:00:00.000"),5},
{1,DateTime.FromText("2014-01-03 01:00:00.000"),5},
{1,DateTime.FromText("2014-01-04 02:00:00.000"),80}
}),
TableB = #table({"CustomerId", "TranDate","TranCount"},
{
{1,DateTime.FromText("2014-01-01 02:00:00.000"),10},
{1,DateTime.FromText("2014-01-01 03:00:00.000"),5},
{1,DateTime.FromText("2014-01-02 01:00:00.000"),20},
{1,DateTime.FromText("2014-01-02 03:00:00.000"),15},
{2,DateTime.FromText("2014-01-01 01:00:00.000"),5},
{2,DateTime.FromText("2014-01-01 02:00:00.000"),80}
}),
TableATransformed=Table.Sort(
Table.AddColumn(TableA,"Date",each Date.From([TranDate]))
,{"CustomerId","TranDate"}
) ,
TableBTransformed=Table.Sort(
Table.AddColumn(TableB,"Date",each Date.From([TranDate]))
,{"CustomerId","TranDate"}
) ,
TableAGrouped=Table.Group(TableATransformed,{"CustomerId","Date"},{"Total",each List.Last([TranCount])}),
TableBGrouped=Table.Group(TableBTransformed,{"CustomerId","Date"},{"Total",each List.Last([TranCount])})
in
Table.Join(Table.PrefixColumns(TableAGrouped,"TableA"),{"TableA.CustomerId","TableA.Date"},TableBGrouped,{"CustomerId","Date"},JoinKind.FullOuter)

DEMO: Join
Tables with M
Script

Top 5 M
Functionalities

Top Five M Functionalities


Robust List of Built-in Functions
Custom Functions

Error Handling
EACH; Singleton Function
Generator Functions

Robust Built-in Functions


Table Functions
Date Functions
#shared keyword

Table Functions
Table.AddColumn
Table.RemoveColumns

Table.ReorderColumns
Table.SelectColumns
Table.ReplaceValue
Table.Sort
Table.AddIndexColumn
Table.FillDown

DEMO: Table
Functions

Custom Functions
Re-use your code
Reduce redundancy
Increase consistency

Custom Functions
Lamda expression
Parameters (optional,required)
Multi-Line functions

Generators
List can be generated
List.Dates(<start date>,<end date>)
Generates List of Dates from <start date> to <end date>

It can be used as Loop structure

EACH; Singleton Function


Single Valued parameter
Can be applied on transforms to the items in List or Table
DaysInMonthList=List.Transform(MonthList,each
Date.DaysInMonth(DateTime.FromText(Text.From(Year)&""&Text.From(_)&"-01")))

DEMO: Custom
Function,
Generator, Each
Function

Error Handling
Control of Execution when error happens
Sending proper error messages
Preventing failure with messages for troubleshooting

DEMO: Error
Handling

Date Dimension
with Power
Query

Date Dimension

Features
Configurable via table in Excel Sheet
Fiscal Columns
Public Holidays Fetched Live

How it works
Generators; to build the base structure
EACH; to apply transformations on each item in list
Date/Text Functions
Odata
Table Functions

DEMO: Date
Dimension

Power Query for


Office 365
Benefits

Power BI Features
Share Queries
Manage Shared Queries
Find and use a Shared Query
View Usage Analytics for Shared Query

Summary

References to Study More


Power Query Posts on my Blog:
http://rad.pasfu.com/index.php?/categories/15-Power-Query

Power Query Formula Categories online Help:


http://office.microsoft.com/en-001/excel-help/power-query-formulacategories-HA104122363.aspx

PDFs to Learn M on MSDN:


http://office.microsoft.com/en-nz/excel-help/learn-about-power-queryformulas-HA104003958.aspx
Power Query for Power BI and Excel (Book, Author; Chris Webb):
http://www.apress.com/9781430266914

Questions?
@Rad_Reza
a.raad.g@gmail.com

www.rad.pasfu.com
www.linkedin.com/in/rezarad

Explore Everything PASS Has to Offer


Free SQL Server and BI Web Events

Free 1-day Training Events

Regional Event

This is Community

Business Analytics Training

Local User Groups Around


the World

Session Recordings

PASS Newsletter

Free Online Technical Training

Session Evaluations
Submit by 11:59 PM EST
Friday Nov. 7 to
WIN prizes

Your feedback is
important and valuable.

ways to access

Go to
passsummit.com/evals

Download the GuideBook App


and search: PASS Summit 2014

Evaluation Deadline:
11:59 PM EST, Sunday Nov. 16

Follow the QR code link displayed


on session signage throughout the
conference venue and in the
program guide

Das könnte Ihnen auch gefallen