Professional Documents
Culture Documents
© www.powerquery.academy
About Power Query Recipes
These cards are a set of ready-to-use Power Query Recipes to lead you step-by-step through a
variety of data transformations and techniques. These cards are a useful reference where you
can look up the exact steps needed for a particular data transformation pattern. We hope you
find them as handy as we do ourselves!
Many of the recipes are also linked to corresponding videos in our Power
Query Academy course and are indicated with the video icon shown here:
If you are enrolled in the full Power Query Academy course (not in the free trial or any of
our other courses), clicking the video icon will take you to that video on the course site. Please
note that you will first need to login to the course site before being able to watch the video.
If you are on the ongoing subscription of these cards, we will let you know when new cards
have been added to the set you so can download your updated copy.
© www.powerquery.academy
Power Query Recipes – Table of Contents
00. Best Practice Architectures
0.100.1902 Files as a Data Source n/a
0.110.1908 Creating a Staging Query Module 2, Video 2
0.120.1908 Modifying Query Load Destinations Module 2, Video 2
TOC: 00.001.1908
Look for the No Lo Pro
Pattern Code Code Code
© www.powerquery.academy
Difficulty scale:
Power Query Recipes – Table of Contents
30. Combining Data
30.100.1809 7 Ways to Join Your Data Module 5, Video 2
30.105.1809 Exact Match Module 5, Video 1
30.110.1809 Left Outer Join Module 5, Video 2
30.111.1809 Right Outer Join Module 5, Video 2
30.112.1809 Full Outer Join Module 5, Video 2
30.113.1809 Inner Join Module 5, Video 2
30.114.1809 Left Anti Join Module 5, Video 2
30.115.1809 Right Anti Join Module 5, Video 2
30.116.1810 Full Anti Join Module 5, Video 2
30.120.1809 Cartesian Product (Many to Many Join) Module 5, Video 3
30.125.1809 Approximate Match Module 5, Video 4
50. Ranking
50.100.1809 Ordinal Ranking n/a
50.105.1905 Standard Competition Ranking n/a
50.110.1905 Modified Competition Ranking n/a
50.115.1905 Dense Ranking n/a
50.120.1905 Fractional Ranking n/a
50.125.1903 Number Grouped Rows n/a
TOC: 00.003.1908
Look for the No Lo Pro
Pattern Code Code Code
© www.powerquery.academy
Difficulty scale:
Power Query Recipes – Table of Contents
60. Date & Time Techniques
60.100.1809 Dynamic Calendar Boundaries Module 15, Video 2
60.105.1809 Dynamic Calendar: Start Date to End Date Module 15, Video 2
60.110.1809 Dynamic Calendar: Start Date + x Days Module 15, Video 3
60.900.1903 Convert a Unix Timestamp to a Valid Date n/a
60.910.1903 Convert UTC DateTime to Local DateTime n/a
60.920.1903 Switching DateTimes Zones n/a
70. Miscellaneous
70.100.1809 Add a Random Number to all Table Rows n/a
70.110.1908 Difference from Prior Row n/a
70.120.1908 Import the most Recent File in a Folder n/a
TOC: 00.004.1908
Look for the No Lo Pro
Pattern Code Code Code
© www.powerquery.academy
Difficulty scale:
0. Best Practice
Architectures
© www.powerquery.academy
Pattern Difficulty
Recipe: 0.110.1908
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Excel Tips!
1) If you accidentally loaded a query to a table, you
can convert it to a Connection Only query by
simply deleting the worksheet!
2) Change your default Load Behaviour by modifying
the Query Options found here:
Excel 2010/2013 Power Query → Options
Excel 2016 Data → New Query → Query Options
Excel 2019/365 Data → Get Data → Query Options
Recipe: 0.120.1908
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
10. Splitting Data
© www.powerquery.academy
Pattern Difficulty
Recipe: 10.100.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Desired Output
Recipe: 10.105.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
20. Reshaping Data
© www.powerquery.academy
Pattern Difficulty
Headers Fact
Pivoting Data Recipe
Select the [Headers] column
Go to Transform → Pivot Column
Change the Values drop-down to the [Fact] column
Click OK
Source Table
Headers
Output Table
Fact
Recipe: 20.100.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Recipe: 20.105.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Keep nulls During Unpivot Recipe Pivot Data With null Values
Prepare Source table
Filter out Total and Subtotal rows
Delete any Total and Subtotal columns
Select columns with null values to unpivot
Right click any column header → Replace Values
Replace null with 0 Unpivoted With null Values
Unpivot the Data
Select all columns to keep as is
Right click → Unpivot Other Columns
Rename the [Attribute] column
Right click the [Value] column
Replace Values → 0 with null
Rename the [Value] column
Set data types
Be aware that this can significantly increase This recipe uses hard-coded column names. To add new
the number of rows in your data set! columns to the data set, modify the “Replaced Value” step
Recipe: 20.106.1906
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
2. To Demote headers, go to
Home → Use Headers as First Row → Use
First Row as Headers Alternate Data View
Recipe: 20.110.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Recipe: 20.115.1902
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
LEGEND:
Connection Only Query
Headers
Query
Query Steps
Load to Table/Model
Reference RawData
Keep top x rows
RawData Recipe steps 2 to 6
Data
Query Query Steps
Source
Connect to Data Output Query Steps
Recipe step 1 Query
Data
Query
Query Steps
Reference RawData
Remove top x rows
Recipe: 20.116.1902
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! ©www.powerquery.academy
www.powerquery.academy
Pattern Difficulty
Recipe: 20.120.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
30. Combining Data
© www.powerquery.academy
Pattern Difficulty
Recipe: 30.100.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Source Table
Exact Match Recipe
Prepare Source table
Set data types
Load as Connection Only
Key Prepare Lookup table
Column
Set data types
Right click [Key] column → Remove Duplicates
Key Load as Connection Only
Column
Perform the match
Reference the Source table
Go to Home → Merge → Lookup table
Select the [Key] column on both tables
Use a Left Outer Join
Expand the new column
Lookup Table Uncheck the [Key] column and prefix option
Recipe: 30.105.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Lookup Table
Recipe: 30.110.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Lookup Table
Recipe: 30.111.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Source Table
Full Outer Join Recipe
Pink records Yellow records
For each table
are included in are included in
result result Create a staging query (load as Connection Only)
Merge the Data
Reference the Source table
Key Go to Home → Merge → Lookup table
Columns
Select the [Key] column(s) on both tables*
Use a Full Outer Join
Key Expand the Data
Columns
Expand the new column
Uncheck the [Key] column(s)
Lookup Table
Recipe: 30.112.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Source Table
Inner Join Recipe
For each table
Pink records have no match in Create a staging query (load as Connection Only)
Lookup so are excluded from result
Merge the Data
Reference the Source table
Key Go to Home → Merge → Lookup table
Columns Select the [Key] column(s) on both tables*
Use an Inner Join
Key Expand the Data
Columns Expand the new column
Yellow records have no
match in Source so are Uncheck the [Key] column(s)
excluded from result Consider unchecking Preface option
Lookup Table
Recipe: 30.113.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Lookup Table
Recipe: 30.114.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Lookup Table
Recipe: 30.115.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Lookup Table
Recipe: 30.116.1810
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Table 1
Cartesian Product Recipe
(Many to Many Joins)
For each table to be merged:
Create a staging query
Recipe: 30.120.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Source Table
Lookup Table
Recipe: 30.125.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
35. Appending Data
© www.powerquery.academy
Pattern Difficulty
Create a “Master”
Reference the
query to
FilesList query
append files
Recipe: 35.400.1908
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Recipe: 35.410.1811
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Recipe: 35.412.1901
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
https://<tenant>-my.sharepoint.com/personal/<email>
where the . and @ signs in your email are replaced with the _ character.
(The easiest way to check is to login to OneDrive for Business in the web and inspect the URL.)
Recipe: 35.414.1901
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Recipe: 35.420.1901
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Recipe: 35.500.1908
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
© www.powerquery.academy
Pattern Difficulty
Finish cleanup
Recipe: 40.100.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Finish cleanup
Recipe: 40.105.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
50. Ranking
© www.powerquery.academy
Pattern Difficulty
Recipe: 50.100.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Modified Competition
Ranking Recipe Modified Competition Ranking
Initial Preparation records ties, leaving gaps in the
ranking numbers BEFORE sets of
Perform any possible preliminary cleanup
equal-ranking items
Set data types
Sort the [Fact] column → Descending
Sort any [Dimension] column(s) to order ties
Go to Add Column → Index Column → From 1
Group the Data Source Table Ranked Table
Go to Transform → Group → Advanced
Group by the [Fact] column
Add new column names as follows:
Rank → Max → [Index]
Data → All Rows
Expand the [Dimension] field from the [Data] column
Re-order the columns if desired
Dimension Fact
Learn about ranking methods:
https://en.wikipedia.org/wiki/Ranking
Recipe: 50.110.1905
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Recipe: 50.115.1905
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
© www.powerquery.academy
Pattern Difficulty
* This step is important † Ensure that you click the cell to drill down, not the header
if you are not forcing of the table. You need your new formula to read as follows:
to start/end of period =#"<previous step name>"{0}[Date Column Name]
Recipe: 60.100.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Recipe: 60.110.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
epoch
Convert a Unix Timestamp to a Valid Date Time (UTC)
Initial Preparation
Convert the [epoch] column to a Whole Number data type
Add a Column for UTC Time
Go to Add Column → Custom Column
Name: Time (UTC)
Formula: =#datetime(1970, 1, 1, 0, 0, 0)
+ #duration(0, 0, 0, [epoch])
Set the [Time (UTC)] column to a DateTime data type
Right click the [epoch] column → Remove Column
Unix time (also known as POSIX time or UNIX Epoch time) displays
time as the number of seconds that have elapsed since 00:00:00
Thursday, 1 January 1970, minus leap seconds. All times are
tracked in Coordinated Universal Time (UTC).
Recipe: 60.910.1903
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Pattern Difficulty
Step 2A: If your data DOES NOT already have a time zone
Right click the [Original] column → Change Type → DateTime
Go to Add Column → Custom Column
Name: NewZone
Formula: DateTime.AddZone([Original],Offset)
Right click the [Original] column → Remove Column
CAUTION!
Step 2B: If your data ALREADY displays a time zone These DateTimeZone
Go to Add Column → Custom Column functions are NOT
Name: NewZone Daylight Savings Time
Formula: =DateTimeZone.SwitchZone([Original],Offset) aware! To correctly factor
in Daylight Savings Time
see Recipe 60.910.x.
Recipe: 60.920.1903
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
70. Miscellaneous
© www.powerquery.academy
Pattern Difficulty
Recipe: 70.100.1809
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Master Your Data in Excel & Power BI
Recipe: 70.110.1908
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Master Your Data in Excel & Power BI
* There are three different columns of dates that you may wish to use for this recipe:
[Date accessed] gives the last time someone opened the file
[Date modified] provides the last time the file was changed
[Date created] tells us when the file was created
Note that these timestamps are managed by Windows and can end up with scenarios where
files are modified before they are created
Recipe: 70.120.1908
Power Query Academy
Subscribers: Click here to For more data patterns check out our Academy at:
see this recipe in action! © www.powerquery.academy
Master Your Data
www.powerquery.academy
© www.powerquery.academy