100% found this document useful (5 votes)
13 views

Data Mashup with Microsoft Excel Using Power Query and M: Finding, Transforming, and Loading Data from External Sources Adam Aspin pdf download

The document is a comprehensive guide on using Power Query and M in Microsoft Excel for data mashup, focusing on finding, transforming, and loading data from various external sources. It includes detailed chapters on using Power Query, loading data from files, databases, web services, and structuring imported data. The author, Adam Aspin, provides practical insights and techniques to enhance data analysis and visualization in Excel.

Uploaded by

cordsdemro3n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
13 views

Data Mashup with Microsoft Excel Using Power Query and M: Finding, Transforming, and Loading Data from External Sources Adam Aspin pdf download

The document is a comprehensive guide on using Power Query and M in Microsoft Excel for data mashup, focusing on finding, transforming, and loading data from various external sources. It includes detailed chapters on using Power Query, loading data from files, databases, web services, and structuring imported data. The author, Adam Aspin, provides practical insights and techniques to enhance data analysis and visualization in Excel.

Uploaded by

cordsdemro3n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Data Mashup with Microsoft Excel Using Power

Query and M: Finding, Transforming, and Loading


Data from External Sources Adam Aspin download

https://textbookfull.com/product/data-mashup-with-microsoft-
excel-using-power-query-and-m-finding-transforming-and-loading-
data-from-external-sources-adam-aspin/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Data Visualization in Excel 2016 Adam Aspin

https://textbookfull.com/product/data-visualization-in-
excel-2016-adam-aspin/

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-
loucas/

Analyzing Data with Microsoft Power BI and Power Pivot


for Excel 1st Edition Alberto Ferrari & Marco Russo

https://textbookfull.com/product/analyzing-data-with-microsoft-
power-bi-and-power-pivot-for-excel-1st-edition-alberto-ferrari-
marco-russo/

Pro Power BI Desktop: Self-service Analytics and Data


Visualization for the Power User 3rd Edition Adam Aspin

https://textbookfull.com/product/pro-power-bi-desktop-self-
service-analytics-and-data-visualization-for-the-power-user-3rd-
edition-adam-aspin/
Pro Power BI Desktop Self Service Analytics and Data
Visualization for the Power User Third Edition Adam
Aspin

https://textbookfull.com/product/pro-power-bi-desktop-self-
service-analytics-and-data-visualization-for-the-power-user-
third-edition-adam-aspin/

Learning Apache Drill Query and Analyze Distributed


Data Sources with SQL 1st Edition Charles Givre

https://textbookfull.com/product/learning-apache-drill-query-and-
analyze-distributed-data-sources-with-sql-1st-edition-charles-
givre/

Data Analysis with Microsoft Power Bi Brian Larson

https://textbookfull.com/product/data-analysis-with-microsoft-
power-bi-brian-larson/

Targeting Using Augmented Data in Database Marketing


Decision Factors for Evaluating External Sources 1st
Edition Bettina Hüttenrauch

https://textbookfull.com/product/targeting-using-augmented-data-
in-database-marketing-decision-factors-for-evaluating-external-
sources-1st-edition-bettina-huttenrauch/

Microsoft Excel Data Analysis and Business Modeling 5th


Edition Wayne Winston

https://textbookfull.com/product/microsoft-excel-data-analysis-
and-business-modeling-5th-edition-wayne-winston/
Data Mashup
with Microsof t
Excel Using Power
Query and M
Finding, Transforming, and Loading Data
from External Sources

Adam Aspin
Data Mashup with
Microsoft Excel Using
Power Query and M
Finding, Transforming, and
Loading Data from
External Sources

Adam Aspin
Data Mashup with Microsoft Excel Using Power Query and M: Finding,
Transforming, and Loading Data from External Sources
Adam Aspin
Stafford, UK

ISBN-13 (pbk): 978-1-4842-6017-3 ISBN-13 (electronic): 978-1-4842-6018-0


https://doi.org/10.1007/978-1-4842-6018-0

Copyright © 2020 by Adam Aspin


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Jonathan Gennick
Development Editor: Laura Berendson
Coordinating Editor: Jill Balzano
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-
sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a
Delaware corporation.
For information on translations, please e-mail rights@apress.com, or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484260173. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
Table of Contents
About the Author��������������������������������������������������������������������������������������������������� xiii

About the Technical Reviewer���������������������������������������������������������������������������������xv


Acknowledgments�������������������������������������������������������������������������������������������������xvii

Introduction������������������������������������������������������������������������������������������������������������xix

Chapter 1: Using Power Query to Discover and Load Data into Excel���������������������� 1
Power Query��������������������������������������������������������������������������������������������������������������������������������� 2
The Data Load Process����������������������������������������������������������������������������������������������������������������� 4
Why Use Power Query?����������������������������������������������������������������������������������������������������������������� 7
The Queries & Connections Pane�������������������������������������������������������������������������������������������������� 8
Displaying the Queries & Connections Pane���������������������������������������������������������������������������� 9
The Peek Window�������������������������������������������������������������������������������������������������������������������� 9
Peek Window Options������������������������������������������������������������������������������������������������������������ 10
View in Worksheet����������������������������������������������������������������������������������������������������������������� 11
Deleting a Query������������������������������������������������������������������������������������������������������������������������� 12
Understanding Data Load������������������������������������������������������������������������������������������������������������ 12
The Navigator Dialog������������������������������������������������������������������������������������������������������������� 13
Select Multiple Source Tables����������������������������������������������������������������������������������������������� 15
Searching for Datasets���������������������������������������������������������������������������������������������������������� 15
Navigator Display Options����������������������������������������������������������������������������������������������������� 17
Refresh���������������������������������������������������������������������������������������������������������������������������������� 17
The Navigator Data Preview�������������������������������������������������������������������������������������������������� 18
Modifying Data���������������������������������������������������������������������������������������������������������������������� 19
The Power Query Editor�������������������������������������������������������������������������������������������������������������� 20
Data Sources������������������������������������������������������������������������������������������������������������������������������� 20

iii
Table of Contents

Source Data Properties��������������������������������������������������������������������������������������������������������������� 22


Query Properties������������������������������������������������������������������������������������������������������������������������� 23
Load Destinations����������������������������������������������������������������������������������������������������������������������� 25
Repurposing an Existing Connection������������������������������������������������������������������������������������� 26
Load to Excel������������������������������������������������������������������������������������������������������������������������� 28
Load to the Data Model��������������������������������������������������������������������������������������������������������� 28
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 30

Chapter 2: Discovering and Loading File-Based Data with Power Query��������������� 31


File Sources�������������������������������������������������������������������������������������������������������������������������������� 31
Loading Data from Files�������������������������������������������������������������������������������������������������������������� 33
CSV Files�������������������������������������������������������������������������������������������������������������������������������� 33
Text Files������������������������������������������������������������������������������������������������������������������������������� 37
Text and CSV Options������������������������������������������������������������������������������������������������������������� 38
Fixed-Width Text Files����������������������������������������������������������������������������������������������������������� 40
Simple XML Files������������������������������������������������������������������������������������������������������������������� 41
Excel Files����������������������������������������������������������������������������������������������������������������������������� 43
Why Use Power Query to Connect to Excel��������������������������������������������������������������������������� 47
From Table/Range������������������������������������������������������������������������������������������������������������������ 48
Microsoft Access Databases������������������������������������������������������������������������������������������������� 49
JSON Files����������������������������������������������������������������������������������������������������������������������������������� 51
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 51

Chapter 3: Loading Data from Databases and Data Warehouses��������������������������� 53


Relational Databases������������������������������������������������������������������������������������������������������������������ 54
SQL Server���������������������������������������������������������������������������������������������������������������������������������� 56
Automatically Loading Related Tables����������������������������������������������������������������������������������� 60
Database Options������������������������������������������������������������������������������������������������������������������ 61
Searching for Tables�������������������������������������������������������������������������������������������������������������� 64
Oracle Databases������������������������������������������������������������������������������������������������������������������������ 71
Other Relational Databases��������������������������������������������������������������������������������������������������������� 74

iv
Table of Contents

Microsoft SQL Server Analysis Services Data Sources��������������������������������������������������������������� 76


From Analysis Services��������������������������������������������������������������������������������������������������������� 80
SSAS Tabular Data Warehouses�������������������������������������������������������������������������������������������������� 83
Types of Credentials When Connecting��������������������������������������������������������������������������������������� 87
Unable to Connect����������������������������������������������������������������������������������������������������������������������� 87
Other Database Connections������������������������������������������������������������������������������������������������������� 88
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 88

Chapter 4: Loading Data from the Web and the Cloud�������������������������������������������� 89


Web and Cloud Services������������������������������������������������������������������������������������������������������������� 89
Web Pages����������������������������������������������������������������������������������������������������������������������������� 90
Online Services���������������������������������������������������������������������������������������������������������������������� 90
Microsoft Azure��������������������������������������������������������������������������������������������������������������������� 91
Web Pages���������������������������������������������������������������������������������������������������������������������������������� 91
Advanced Web Options���������������������������������������������������������������������������������������������������������� 93
Viewing the Source Web Page����������������������������������������������������������������������������������������������� 94
Salesforce����������������������������������������������������������������������������������������������������������������������������������� 95
Loading Data from Salesforce Objects���������������������������������������������������������������������������������� 96
Salesforce Reports�������������������������������������������������������������������������������������������������������������� 102
Microsoft Dynamics 365����������������������������������������������������������������������������������������������������������� 102
Azure SQL Database������������������������������������������������������������������������������������������������������������������ 104
Azure SQL Data Warehouse (Azure Synapse Analytics)������������������������������������������������������������ 106
Connecting to SQL Server on an Azure Virtual Machine����������������������������������������������������������� 108
Azure Blob Storage������������������������������������������������������������������������������������������������������������������� 110
Azure Security��������������������������������������������������������������������������������������������������������������������������� 112
Other Source Types������������������������������������������������������������������������������������������������������������������� 113
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 114

Chapter 5: Generic Data Sources�������������������������������������������������������������������������� 115


ODBC Sources��������������������������������������������������������������������������������������������������������������������������� 116
OLE DB Data Sources���������������������������������������������������������������������������������������������������������������� 125

v
Table of Contents

OData Feeds������������������������������������������������������������������������������������������������������������������������������ 129


OData Options���������������������������������������������������������������������������������������������������������������������� 132
Refreshing Data������������������������������������������������������������������������������������������������������������������������ 132
Refreshing the Entire Data in the Excel In-Memory Model�������������������������������������������������� 133
Refreshing an Individual Query������������������������������������������������������������������������������������������� 133
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 134

Chapter 6: Structuring Imported Data������������������������������������������������������������������ 135


Extending Queries in Power Query������������������������������������������������������������������������������������������� 136
Editing Data After a Data Load��������������������������������������������������������������������������������������������� 137
Transforming Data Before Loading�������������������������������������������������������������������������������������� 141
Query or Load?�������������������������������������������������������������������������������������������������������������������������� 141
The Power Query Editor������������������������������������������������������������������������������������������������������������ 143
The Applied Steps List��������������������������������������������������������������������������������������������������������� 144
The Power Query Editor Ribbons����������������������������������������������������������������������������������������� 145
Dataset Shaping������������������������������������������������������������������������������������������������������������������������ 152
Renaming Columns������������������������������������������������������������������������������������������������������������� 153
Reordering Columns������������������������������������������������������������������������������������������������������������ 153
Removing Columns�������������������������������������������������������������������������������������������������������������� 155
Choosing Columns��������������������������������������������������������������������������������������������������������������� 156
Merging Columns���������������������������������������������������������������������������������������������������������������� 158
Moving to a Specific Column����������������������������������������������������������������������������������������������� 161
Removing Records�������������������������������������������������������������������������������������������������������������������� 162
Keeping Rows���������������������������������������������������������������������������������������������������������������������� 163
Removing Duplicate Records���������������������������������������������������������������������������������������������� 166
Sorting Data������������������������������������������������������������������������������������������������������������������������������ 167
Reversing the Row Order����������������������������������������������������������������������������������������������������� 168
Undoing a Sort Operation���������������������������������������������������������������������������������������������������� 168
Filtering Data���������������������������������������������������������������������������������������������������������������������������� 170
Selecting Specific Text Values��������������������������������������������������������������������������������������������� 170
Finding Elements in the Filter List��������������������������������������������������������������������������������������� 171

vi
Table of Contents

Filtering Text Ranges����������������������������������������������������������������������������������������������������������� 172


Filtering Numeric Ranges���������������������������������������������������������������������������������������������������� 173
Filtering Date and Time Ranges������������������������������������������������������������������������������������������� 174
Filtering Numeric Data�������������������������������������������������������������������������������������������������������� 175
Applying Advanced Filters��������������������������������������������������������������������������������������������������� 177
Grouping Records��������������������������������������������������������������������������������������������������������������������� 179
Simple Groups��������������������������������������������������������������������������������������������������������������������� 179
Complex Groups������������������������������������������������������������������������������������������������������������������ 181
Count Rows������������������������������������������������������������������������������������������������������������������������������� 184
Saving Changes in the Query Editor������������������������������������������������������������������������������������������ 184
Exiting the Query Editor������������������������������������������������������������������������������������������������������������ 184
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 185

Chapter 7: Data Transformation���������������������������������������������������������������������������� 187


Viewing a Full Record��������������������������������������������������������������������������������������������������������������� 188
Power Query Editor Context Menus������������������������������������������������������������������������������������������ 189
Using the First Row as Headers������������������������������������������������������������������������������������������������ 190
Changing Data Type������������������������������������������������������������������������������������������������������������������ 192
Detecting Data Types����������������������������������������������������������������������������������������������������������� 195
Data Type Indicators������������������������������������������������������������������������������������������������������������ 195
Switching Data Types���������������������������������������������������������������������������������������������������������� 196
Data Type Using Locale�������������������������������������������������������������������������������������������������������� 197
Replacing Values����������������������������������������������������������������������������������������������������������������������� 198
Transforming Column Contents������������������������������������������������������������������������������������������������� 201
Text Transformation������������������������������������������������������������������������������������������������������������� 201
Adding a Prefix or a Suffix��������������������������������������������������������������������������������������������������� 203
Removing Leading and Trailing Spaces������������������������������������������������������������������������������� 204
Removing Nonprinting Characters��������������������������������������������������������������������������������������� 204
Number Transformations����������������������������������������������������������������������������������������������������� 205
Filling Down Empty Cells���������������������������������������������������������������������������������������������������������� 215

vii
Table of Contents

Extracting Part of a Column’s Contents������������������������������������������������������������������������������������ 218


Advanced Extract Options���������������������������������������������������������������������������������������������������� 219
Duplicating Columns����������������������������������������������������������������������������������������������������������������� 221
Splitting Columns���������������������������������������������������������������������������������������������������������������������� 222
Splitting Column by a Delimiter������������������������������������������������������������������������������������������� 223
Advanced Options for Delimiter Split����������������������������������������������������������������������������������� 225
Splitting Columns by Number of Characters����������������������������������������������������������������������� 226
Merging Columns���������������������������������������������������������������������������������������������������������������������� 228
Creating Columns from Examples��������������������������������������������������������������������������������������������� 229
Adding Conditional Columns����������������������������������������������������������������������������������������������������� 231
Index Columns�������������������������������������������������������������������������������������������������������������������������� 234
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 236

Chapter 8: Restructuring Data������������������������������������������������������������������������������ 237


The Power Query Editor View Ribbon���������������������������������������������������������������������������������������� 238
Merging Data���������������������������������������������������������������������������������������������������������������������������� 239
Extending a Query with Merged Data���������������������������������������������������������������������������������� 240
Aggregating Data During a Merge Operation���������������������������������������������������������������������� 244
Merge as a New Query�������������������������������������������������������������������������������������������������������� 248
Types of Join������������������������������������������������������������������������������������������������������������������������ 248
Joining on Multiple Columns����������������������������������������������������������������������������������������������� 250
Preparing Datasets for Joins����������������������������������������������������������������������������������������������� 252
Correct and Incorrect Joins������������������������������������������������������������������������������������������������� 253
Examining Joined Data�������������������������������������������������������������������������������������������������������� 254
Appending Data������������������������������������������������������������������������������������������������������������������������� 256
Adding the Contents of One Query to Another��������������������������������������������������������������������� 256
Appending the Contents of Multiple Queries����������������������������������������������������������������������� 259
Changing the Data Structure����������������������������������������������������������������������������������������������������� 260
Unpivoting Tables���������������������������������������������������������������������������������������������������������������� 261
Pivoting Tables��������������������������������������������������������������������������������������������������������������������� 263
Transposing Rows and Columns������������������������������������������������������������������������������������������ 265

viii
Table of Contents

Loading Data from Inside the Query Editor Directly������������������������������������������������������������������ 266


Error Display����������������������������������������������������������������������������������������������������������������������������� 267
Removing Errors������������������������������������������������������������������������������������������������������������������ 268
Viewing Errors��������������������������������������������������������������������������������������������������������������������� 268
Data Transformation Approaches���������������������������������������������������������������������������������������������� 269
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 269

Chapter 9: Complex Data Loads���������������������������������������������������������������������������� 271


Adding Multiple Files from a Source Folder������������������������������������������������������������������������������ 272
Filtering Source Files in a Folder���������������������������������������������������������������������������������������������� 275
Displaying and Filtering File Attributes������������������������������������������������������������������������������������� 278
Removing Header Rows After Multiple File Loads�������������������������������������������������������������������� 280
Combining Identically Structured Files������������������������������������������������������������������������������������� 280
Loading and Parsing JSON Files����������������������������������������������������������������������������������������������� 281
The List Tools Transform Ribbon����������������������������������������������������������������������������������������������� 283
Parsing XML Data from a Column��������������������������������������������������������������������������������������������� 284
Parsing JSON Data from a Column������������������������������������������������������������������������������������������� 286
Complex JSON Files������������������������������������������������������������������������������������������������������������ 288
Complex XML Files�������������������������������������������������������������������������������������������������������������������� 294
Convert a Column to a List�������������������������������������������������������������������������������������������������������� 295
Reusing Data Sources��������������������������������������������������������������������������������������������������������������� 296
Pinning a Data Source��������������������������������������������������������������������������������������������������������� 297
Copying Data from Power Query Editor������������������������������������������������������������������������������������ 298
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 299

Chapter 10: Organizing and Managing Queries���������������������������������������������������� 301


Managing the Transformation Process������������������������������������������������������������������������������������� 301
Modifying a Step����������������������������������������������������������������������������������������������������������������� 302
Renaming a Step����������������������������������������������������������������������������������������������������������������� 303
Deleting a Step or a Series of Steps������������������������������������������������������������������������������������ 304

ix
Table of Contents

Discarding Changes������������������������������������������������������������������������������������������������������������������ 305


Modifying an Existing Step�������������������������������������������������������������������������������������������������� 306
Adding a Step���������������������������������������������������������������������������������������������������������������������� 308
Altering Process Step Sequencing�������������������������������������������������������������������������������������� 309
An Approach to Sequencing������������������������������������������������������������������������������������������������ 309
Error Records����������������������������������������������������������������������������������������������������������������������� 310
Managing Queries��������������������������������������������������������������������������������������������������������������������� 310
Organizing Queries�������������������������������������������������������������������������������������������������������������� 311
Grouping Queries����������������������������������������������������������������������������������������������������������������� 312
Duplicating Queries������������������������������������������������������������������������������������������������������������� 314
Referencing Queries������������������������������������������������������������������������������������������������������������ 315
Documenting Queries���������������������������������������������������������������������������������������������������������� 316
Adding a Column as a New Query��������������������������������������������������������������������������������������� 318
Managing Queries from the Queries & Connections Pane�������������������������������������������������������� 319
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 320

Chapter 11: Parameterizing Queries��������������������������������������������������������������������� 321


Parameterizing Queries������������������������������������������������������������������������������������������������������������� 321
Creating a Simple Parameter���������������������������������������������������������������������������������������������� 322
Creating a Set of Parameter Values������������������������������������������������������������������������������������� 324
Creating a Query-Based Parameter������������������������������������������������������������������������������������� 326
Modifying a Parameter�������������������������������������������������������������������������������������������������������� 328
Applying a Parameter When Filtering Records�������������������������������������������������������������������� 329
Modifying the Current Value of a Parameter������������������������������������������������������������������������ 331
Applying a Parameter to a Data Source������������������������������������������������������������������������������� 332
Other Uses for Parameters�������������������������������������������������������������������������������������������������� 334
Using Parameters in the Data Source Step������������������������������������������������������������������������� 334
Applying a Parameter to a SQL Query��������������������������������������������������������������������������������� 335
Query Icons�������������������������������������������������������������������������������������������������������������������������� 337
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 337

x
Table of Contents

Chapter 12: The M Language�������������������������������������������������������������������������������� 339


What Is the M Language?��������������������������������������������������������������������������������������������������������� 340
M and the Power Query Editor�������������������������������������������������������������������������������������������������� 341
Modifying the Code for a Step��������������������������������������������������������������������������������������������� 342
M Expressions��������������������������������������������������������������������������������������������������������������������� 344
Writing M by Adding Custom Columns�������������������������������������������������������������������������������������� 345
The Advanced Editor����������������������������������������������������������������������������������������������������������������� 348
Expressions in the Advanced Editor������������������������������������������������������������������������������������ 348
The Let Statement��������������������������������������������������������������������������������������������������������������� 350
Modifying M in the Advanced Editor������������������������������������������������������������������������������������ 350
Syntax Checking������������������������������������������������������������������������������������������������������������������ 352
Basic M Functions��������������������������������������������������������������������������������������������������������������������� 352
Text Functions��������������������������������������������������������������������������������������������������������������������������� 354
Number Functions��������������������������������������������������������������������������������������������������������������������� 355
Date Functions�������������������������������������������������������������������������������������������������������������������������� 357
Time Functions�������������������������������������������������������������������������������������������������������������������������� 359
Duration Functions�������������������������������������������������������������������������������������������������������������������� 359
M Concepts������������������������������������������������������������������������������������������������������������������������������� 360
M Data Types����������������������������������������������������������������������������������������������������������������������������� 361
M Values������������������������������������������������������������������������������������������������������������������������������������ 362
Defining Your Own Variables in M���������������������������������������������������������������������������������������� 363
Writing M Queries��������������������������������������������������������������������������������������������������������������������� 364
Lists������������������������������������������������������������������������������������������������������������������������������������� 365
Creating Lists Manually������������������������������������������������������������������������������������������������������� 365
Generating Sequences Using Lists�������������������������������������������������������������������������������������� 367
Accessing Values from a List����������������������������������������������������������������������������������������������� 367
List Functions���������������������������������������������������������������������������������������������������������������������� 368
Records������������������������������������������������������������������������������������������������������������������������������� 368
Tables���������������������������������������������������������������������������������������������������������������������������������� 370
Other Function Areas���������������������������������������������������������������������������������������������������������������� 372

xi
Table of Contents

Custom Functions in M������������������������������������������������������������������������������������������������������������� 372


Adding Comments to M Code���������������������������������������������������������������������������������������������������� 374
Single-Line Comments�������������������������������������������������������������������������������������������������������� 374
Multiline Comments������������������������������������������������������������������������������������������������������������ 374
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 375

Appendix A: Sample Data������������������������������������������������������������������������������������� 377


Downloading the Sample Data�������������������������������������������������������������������������������������������������� 377

Index��������������������������������������������������������������������������������������������������������������������� 379

xii
About the Author
Adam Aspin is an independent business intelligence consultant based in the United
Kingdom. He has worked with SQL Server for over 25 years. During this time, he has
developed several dozen reporting and analytical systems based on the Microsoft
Analytics Stack.
Business intelligence has been Adam’s principal focus for the last 20 years. He has
applied his skills for a variety of clients in a range of industry sectors. He is the author
of Apress books: SQL Server 2012 Data Integration Recipes, Pro Power BI Desktop (now
in its third edition), Business Intelligence with SQL Server Reporting Services, and High
Impact Data Visualization in Excel with Power View, 3D Maps, Get & Transform and
Power BI.
A graduate of Oxford University, Adam began his career in publishing before moving
into IT. Databases soon became a passion, and his experience in this arena ranges from
dBase to Oracle, and Access to MySQL, with occasional sorties into the world of DB2.
He is, however, most at home in the Microsoft universe when using SQL Server Analysis
Services, SQL Server Reporting Services, SQL Server Integration Services, and Power
BI—both on-premises and in Azure.
A fluent French speaker, Adam has worked in France and Switzerland for many years.

xiii
About the Technical Reviewer
Karine Aspin is a principal consultant with Calidra Ltd., a UK-based data and analytics
consultancy. A mathematics graduate of the Swiss Federal Institute of Technology,
Karine has worked at a range of IT companies including IBM Global Services.

xv
Acknowledgments
Writing a technical book can be a lonely occupation. So I am all the more grateful for
all the help and encouragement that I have received from so many fabulous friends and
colleagues.
First, my considerable thanks go to Jonathan Gennick, the commissioning editor
of this book. Throughout the publication process, Jonathan has been both a tower
of strength and an exemplary mentor. He has always been available to share his vast
experience selflessly and courteously.
Heartfelt thanks go to Jill Balzano, the Apress coordinating editor, for calmly
managing this book through the production process. She succeeded—once again—in
the well-nigh impossible task of making a potentially stress-filled trek into a pleasant
journey filled with light and humor. Her team also deserves much praise for their
efficiency under pressure.
I also owe a debt of gratitude to my wife, Karine, for her time and effort spent
reviewing this book. Being a technical reviewer is a thankless task, but I want to say a
heartfelt “thank you” to her for the range and depth of her comments and for picking up
so much that otherwise would have gone unnoticed. The book is a better one thanks to
her efforts.
My thanks also go to Ann Gemer Tuballa for her tireless and subtle work editing and
polishing the prose and to the team at SPi Global for the hours spent preparing the book
for publishing.

xvii
Introduction
Analytics has become one of the buzzwords that define an age. Managers want their staff
to deliver meaningful insight in seconds; users just want to do their jobs quickly and
well. Everyone wants to produce clear, telling, and accurate analysis with tools that are
intuitive and easy to use.
Microsoft recognized these trends and needs a few short years ago when they
extended Excel with an add-in called Power Query. Once a mere optional extension to
the world’s leading spreadsheet, Power Query is now a fundamental pillar of the Excel
toolkit. It allows a user to take data from a wide range of sources and transform them into
the base data that they can build on to add metrics, instant analyses, and KPIs to project
their insights.
With Power Query, the era of self-service data access and transformation has finally
arrived.

What Is Power Query?


Power Query is a tool that is used to carry out ETL. This acronym stands for Extract,
Transform, Load. This is the sequential process that covers

• Connecting to source data outside the current Excel workbook (or


file if you prefer) and accessing all or part of the data that you need to
bring into Excel. This is the extract phase of ETL.

• Reshaping the data (the “data mashup” process) so that the resulting
data is in a form that can be used by Excel. Essentially, this means
ensuring that the data is in a coherent, structured, and complete
tabular format. This is the transform phase of ETL.

• Returning the data into Excel as a table in a worksheet or into the


Excel/Power Pivot data model. This is the load phase of ETL.

These three phases make up the data ingestion process. So it is worth taking a short
look at what makes up each one of them.

xix
Introduction

Connecting to Source Data


Gone are the days when you manually entered all the data you needed into a
spreadsheet. Today’s data are available in a multitude of locations and formats—and are
too voluminous to rekey.
This is where Power Query’s ability to connect instantly to 40-odd standard data
sources is simply invaluable. Is your accounting data in MS Dynamics? Just connect. Is
your CRM data in Salesforce? Just connect. Is your organization using a Data Lake?...you
can guess the reply.
Yet this is only a small part of what Power Query can do to help simplify your
analyses. For not only can it connect to a multitude of data sources (many of which
are outlined in Chapters 1 through 5), it does this via a unified interface that makes
connecting to data sources brilliantly simple. On top of this, you can use Power Query to
preview the source data and ensure that you are loading exactly what you need. Finally,
to top it all, the same interface is used for just about all of the available source data
connections. This means that once you have learned to set up one connection, you have
learned how to connect to virtually all of the available data sources.
In essence, part of Power Query is just another connection to external data. However,
its unified data access interface, range of available data sources, and sheer simplicity will
probably induce you to replace any data connections made using older technologies
pretty quickly.

D
 ata Transformation
Once you have established a connection to a data source, you may need to tweak the
data in some way. Indeed, you may even need to reshape it entirely. This is the data
mashup process—and it is the area where Power Query shines.
Power Query can carry out the simplest data transformation tasks to the most
complex data restructuring challenges in a few clicks. You can

• Filter source data so that you only load exactly the rows and columns
you need

• Extend the source data with calculations or data extracted from


existing columns of data

xx
Introduction

• Cleanse and rationalize the data easily and quickly in


a multitude of ways

• Join or split source tables to prepare a logical set of data tables for
each specific analytical requirement

• Group and aggregate source data to reduce the quantity of data


loaded into Excel

• Prepare source data tables to become a usable data model

This list merely scratches the surface of all that Power Query can do to mash up your
data. It is, without hyperbole, unbelievably powerful at transforming source data. Indeed,
it can carry out data ingestion and transformation tasks that used to be the preserve of
expensive products that required complex programming skills and powerful servers.
All of this can now be done using a code-free interface that assists you in taking the
messiest source data and delivering it to Excel as limpid tables of information ready to
work with. If you wish to become a Power Query super-user, then you can extend its
possibilities using the built-in M language.

Loading into a Worksheet or the Data Model


This final phase is the easiest by far. It is simply a question of telling Power Query where
to land the data. This can be one—or both—of

• A worksheet: Power Query can place the data from each source
query into a separate worksheet. Once in a worksheet, it is perfectly
“normal” Excel data. From here on you can do what you want to
the data in Excel just as you normally would using all the Excel
techniques that you have learned over the years.

• The data model: Also referred to, often, as the Power Pivot data
model (which is the term that I prefer to use), this is an in-memory
data store. It can handle many more rows of data than Excel—tens
of millions in some cases—and is normally the basis for pivot table
output in Excel. When dealing with large source datasets, it is often
the ideal destination for data that you have accessed using Power
Query, as it is compressed in memory (and consequently takes up
less space when saved to disk) and can easily exceed the 1,048,576
row limit of Excel worksheets.
xxi
Introduction

The data model and Power Pivot are extensive subjects in their own right, and this
book will not be looking at either of them in detail.

Integrating Power Query into Daily Workflows


Power Query is completely integrated into the latest versions of Excel. This means that
you can use it seamlessly as part of your daily routines when ingesting and analyzing
data. Put simply:

• Data source connections, transformation routines, and data loading


into Excel are created once and can be reused whenever suits you.

• You can trigger manual data refreshes at any time—and these can be
total refreshes of every source connection in a workbook or refreshes
of a single source if you prefer.

• Data sources can be reused across different Excel workbooks.

• Power Query processes can be copied between different Excel files.

• Power Query processes (called queries) can be managed and


extended with interactive parameters to create immensely powerful
ETL processes.

• Power Query–based data flows can be customized and extended


using the built-in M language.

So, as is the case for nearly all your Excel-based work, you are likely to build once
and use often.

The Evolution of Power Query


Power Query has evolved considerably over the years since it was first made available as a
downloadable add-in for Excel 2010. It was still optional for Excel 2013 and only attained
the status of being completely integrated into Excel by the 2016 version. Indeed, it suffered
a name change at that point and was accessed under the heading “Get & Transform.”
Since around 2017—and since the Excel 2019 version—it has reverted to being
Power Query once again. This is the version that is the subject of this book. This does not
mean that you cannot use the techniques described in these pages with earlier versions

xxii
Introduction

of the product. However, it will mean that certain aspects of the Excel interface that you
use to launch Power Query will be slightly different from those described in Chapters 1
through 5. These differences are essentially minor and should not present any
difficulties to experienced Excel users.
This is made possible due to the fact that Power Query is accessed using a separate
interface. It is called from inside Excel, but exists in its own parallel universe. This
ensures a consistent look and feel whatever the version of Excel that you are using. The
entry point into Power Query may change with Excel versions—but the product itself
remains the same. Just remember that the range of available data sources will depend on
the version of Excel that you are using. Some of the “enterprise-level” data sources are
only available in Pro and Enterprise subscriptions to Excel.

How to Use This Book


If you wish, you can read this book from start to finish as it is designed to be a progressive
tutorial that will help you to learn Power Query. However, as Power Query is composed
of four main areas, this book is broken down into four sets of chapters that focus on the
various key areas of the product. It follows that you can, if you prefer, focus on individual
topics in Power Query without having to take a linear approach to reading this book.

• Chapters 1 through 5 show you how to connect to a range of varied


data sources and bring this data into Excel using Power Query.
Depending on the source data that you need to use, you may only
need to dip into parts of these chapters to find guidance on how to
use a specific source data type.

• Chapters 6 through 9 explain how to transform and clean data so that


you can use it for analysis. These data transformations range from
the extremely simple to the potentially complex. Indeed, they are as
potentially vast as data itself. You may never need to apply all of the
extensive range of data modification and cleansing techniques that
Power Query can deliver—but just about everything that it can do is
explained in detail in these chapters.

xxiii
Introduction

• Chapters 10 and 11 explain how to tame the real world of data


loading and transformation. Here you will learn how to organize and
manage your queries, as well as how to add parameters to make them
more interactive and resilient.

• Chapter 12 introduces you to M—the language that Power Query uses


to transform your data. Using M you can push your data ingestion
and transformation routines to new heights that are simply not
possible using just the Power Query interface.

On to Learning Power Query


This book comes with a small set of sample data that are used to create the examples
that are used throughout the book. I realize that it may seem paradoxical to use a tiny
dataset for a product that can handle tens of millions of rows of data, but I prefer to use
a comprehensible set of source data so that the reader can concentrate on what is being
learned, rather than the data itself.
It is inevitable that not every question can be anticipated and answered in one book.
Nonetheless, I hope that I have answered many of the data ingestion and transformation
questions that you might encounter and—more importantly—have given you the
approaches and the confidence to resolve most of the Power Query challenges that you
might meet when applying this product to solve real-world problems.
As a final point, the information on “pure” Power Query in Chapters 6–12 is
independent of Excel. So if you are learning Power Query in Power BI, SQL Server
Integration Services, or the Power BI Service, you can find a wealth of relevant
information to assist you in your data transformation projects.
I wish you good luck in using Power Query, and I sincerely hope that you have as
much fun using it as I did in writing this book.

xxiv
CHAPTER 1

Using Power Query


to Discover and Load
Data into Excel
If you are reading this book, it is most likely because you need to use data. More
specifically, it may be that you need to take a journey from data to insight in which
you have to take quantities of facts and figures, shape them into comprehensible
information, and add the analysis that delivers clear meaning. More to the point, you
want to do all this using the spreadsheet that you know and trust—Microsoft Excel.
This book is all about that journey. It covers the many ways that you, an Excel user,
can transform external raw data into the information structures that enable you to
deliver high-impact analyses. This fresh approach presumes that you are not dependent
on central IT to help you to load data from external sources, nor do you need their
help on a regular basis. It is based on enabling the user to handle industrial-strength
quantities of source data using the world’s most popular spreadsheet in the shortest
possible time frame.
The keywords in this universe are

• Fast

• Decentralized

• Intuitive

• Interactive
• Delivery

1
© Adam Aspin 2020
A. Aspin, Data Mashup with Microsoft Excel Using Power Query and M,
https://doi.org/10.1007/978-1-4842-6018-0_1
Chapter 1 Using Power Query to Discover and Load Data into Excel

Using the techniques described in this book, you can discover and load data from
a multitude of external sources. You can then, quickly and intuitively, transform and
cleanse this raw data to make it structured and usable. Once ready for use, you can load
it into either Excel worksheets or the Power Pivot data model in Excel and start using the
tool you already know so well—Excel—to provide detailed analytics.
It follows that this book is written from the perspective of the user. Essentially it is
all about empowerment—letting users define their own requirements and satisfy their
own needs simply and efficiently by building on their existing skills. The amazing thing
is that you can do all of this using Excel without needing any other tools or utilities. Your
sources could be in many places and in many formats. Nonetheless, you need to access
them, sample them, select them, and, if necessary, transform or cleanse them in order to
deliver your analyses. All of this is enabled by Power Query.

Power Query
Power Query is one of the most recent additions to the Excel toolkit. Now fully integrated
into Excel, it allows you to discover, access, and consolidate information from varied
sources. Once your data is selected, cleansed, and transformed into a coherent table, you
can then place it in an Excel worksheet for detailed analysis or load it directly into Power
Pivot (the Excel data model), which is a natural repository for data when you want to
“slice and dice” it interactively.
Power Query allows you to do many things with source data, but the four main steps
are likely to be

• Import data from a wide variety of sources. This covers corporate


databases to files and social media to big data.

• Merge data from multiple sources into a coherent structure.

• Shape data into the columns and records that suit your use cases.

• Cleanse your data to make it reliable and easy to use.

There was a time when these processes required dedicated teams of IT specialists.
Well, not any more. With Power Query, you can mash up your own data so that it is the
way you want it and is ready to use as part of your self-service solution.

2
Chapter 1 Using Power Query to Discover and Load Data into Excel

This is because discovering, loading, cleansing, restructuring, and modifying source


data are what Power Query is designed to do. It allows you to accomplish the following:

• Data discovery: Find and connect to a myriad of data sources


containing potentially useful data. This can be from both public and
private data sources. This is the subject of Chapters 1 through 5.

• Data loading: Select the data you have examined and load a subset
into Power Query for shaping.
• Data modification: Modify the structure of each dataset that you have
imported.

• Filter and clean the data itself.

Although I have outlined these three steps as if they are completely separate and
sequential, the reality is that they often blend into a single process. Indeed, there could
be many occasions when you will examine the data after it has been loaded into Excel—
or clean datasets before you load them. The core objective will, however, always remain
the same: find some data and then sample it in Power Query where you can tweak, clean,
and shape it before loading it into Excel.
This process could be described simplistically as “First, catch your data.” In the world
of data warehousing, the specialists call it ETL, which is short for Extract, Transform, and
Load. Despite the reassuring confidence that the acronym brings, this process is rarely
a smooth, logical progression through a clear-cut series of steps. The reality is often
far messier. You may often find yourself importing some data, cleaning it, importing
some more data from another source, combining the second dataset with the first one,
removing some rows and columns, and then repeating these operations, as well as many
others, several times over.
In this and the following few chapters, I will try to show you how the process can
work in practice using Power Query. I hope that this will make the various steps that
comprise an ETL process clearer. All I am asking is that you remain aware that the
range of options that Power Query includes make it a multifaceted and tremendously
capable tool. The science is to know which options to use. The art is to know when to
use them.

3
Chapter 1 Using Power Query to Discover and Load Data into Excel

The Data Load Process


Let’s begin with a rapid overview of what you need to do to get some data into Excel
(assuming that you have downloaded the sample data that accompanies this book from
the Apress website—this is explained in Appendix A). The following steps explain what
you have to do to load data from a source that you know well already—Excel itself. Yes,
I know that you can copy and paste data between workbooks, but that would be to miss
the point and miss out on all the incredible extra facets of data mashup that Power Query
can offer. In this initial case, the actual source of the data is irrelevant. It could come from
any of a few dozen available sources. Excel is simply an example of potential source data.

1. Open a new, blank workbook in Excel.

2. Click Data in the menu to switch to the Data ribbon.

3. Click Get Data. The Get Data popup menu will appear, as shown
in Figure 1-1.

Figure 1-1. The Get Data popup menu

4
Chapter 1 Using Power Query to Discover and Load Data into Excel

4. Click From File.

5. Click From Workbook. The Import Data dialog will appear.

6. Click the file C:\DataMashupWithExcelSamples\


BrilliantBritishCars.xlsx. The Import Data dialog will look like the
one in Figure 1-2.

Figure 1-2. The Import Data dialog when loading data from an Excel workbook

7. Click the Import button. The Navigator dialog will appear.

8. You will see that the BrilliantBritishCars.xlsx file appears on


the left of the Navigator dialog and that any workbooks, named
ranges, or data tables that it contains are also listed under the file.

9. Click the BaseData worksheet name that is on the left. The


contents of this workbook will appear in the data pane on the
right of the Navigator dialog. The Navigator dialog should look like
Figure 1-3.

5
Chapter 1 Using Power Query to Discover and Load Data into Excel

Figure 1-3. The Navigator dialog with data selected

10. Click Load. The data will be loaded from the external Excel
workbook into a new worksheet inside the current workbook.

You will see the Excel window, like the one shown in Figure 1-4. The external data is
now an Excel table (named BaseData, as this was the name of the source data table). You
can see that the connection to the external workbook now appears on the right of the
Excel spreadsheet data in the new Queries & Connections pane. I will explain this new
element in a couple of pages once I have explained exactly why Power Query is such a
cool solution to data ingestion challenges.

6
Chapter 1 Using Power Query to Discover and Load Data into Excel

Figure 1-4. Data available in Excel

I imagine that loading this data took a few seconds at most. Yet you now have a
complete set of external data in Excel that is ready to be used for analysis and reporting.
However, for the moment, I would like to pause and explain exactly what you have seen
so far.

Why Use Power Query?


What you have just done is to open up Excel to become the preferred analysis and MI/BI
(Management Information and Business Intelligence) tool when it comes to connecting
to the information held in dozens of external data sources. What you just saw was that
Excel can now connect to multiple sources of data and bring them into spreadsheets for
further analysis in a few clicks.
However, it is vital to understand that you have so far only scratched the surface of
Power Query and all that it can do to facilitate data ingestion. This is because viewing
and loading data are just the start. As well, you can use it to

• Import data from multiple different data sources

• Import multiple datasets from external data sources at the same time

7
Another Random Document on
Scribd Without Any Related Topics
holding up her hand, said, "Please, teacher, it means that the child
Jesus will have to be vaccinated."

The Widow Again.—The teacher had been giving a lesson on


Magna Charta, during the course of which he tried to impress on the
children the benefits certain Articles conferred on Englishmen at the
present day. He especially drew attention to Article 20, and called
upon a boy at the close of the lesson to repeat that Article. Boy: "No
freeman, merchant, or villain, shall be excessively fined for a small
offence; the first shall not be deprived of his means of livelihood; the
second of his merchandise; and the third of his implements of
husbandry." Teacher: "Can anyone tell me the name of an
implement of husbandry." Little Girl: "Please, sir! a widow."

Thoughtful.—Billy, an urchin of five, going to school, takes an


apple from his pocket, spits on it, and rubs it vigorously on his dirty
and ragged trousers. "Hallo, Billy! What are you doing that for?" Billy
(holding up apple and looking pleased): "'Tis for taicher. Her wont ait
un if he's dirty."

The Correct Thing to Say.—Town lad's composition on "A Half-


holiday": "Yesterday we had a half-holiday and I enjoyed myself very
much. After dinner I did the knives and forks and cleaned the
windows and the boots. Then a boy came round with a football and
wanted me to go to the park with him. But I could not go because
my mother was going out and I had to mind the baby. When she
came home we had tea, and then I went to my place and took out
orders till nine o'clock. Then I went to bed and came to school this
morning. I enjoyed myself very much."

Subject to a Proviso.—Composition by boy, age seven. Time.—


Morning previous to half-holiday for the opening of Kew Bridge by
the King. Subject.—What I shall do this afternoon. "Wen I have had
my diner I shall call for Bob Scott and his mother mite let me play
tops with him in there yard. Then we shall go on the Common to
here the band, and if my tea is not ready I will wait to see the King
go by and I will wave my cap at him and I expect he will wave his at
me."

The Rain and the Unjust.—A smart boy's composition on rain: "Rain
comes down from heaven on the just and the unjust, but mostly
upon the just, because the unjust have borrowed the umbrellas of
the just and have forgotten to return them."

A Surprising Prayer.—"How do we pray for the magistrates in the


Litany?" asked the Vicar. "That it may please Thee to bless and keep
the magistrates, giving them grace to execute all Bishops, Priests,
and Deacons," answered the unconscious boy.
The "Egg-cups."—I had set the class, writes a teacher, an essay to
write on "Good Manners." They had to think about it one evening
and write it the next day in school. When correcting the exercise I
came upon the following: "When you have the egg-cups it is good
manners to put your hand before your mouth and say, 'Manners
before ladies and gentlemen.'"

Balaam and the Ass.—The story as reproduced in a South London


boy's essay: "It was about an owld gentleman as was a-wallopin' of
a donkey and as the donkey was stupied he whached it with a stick,
the donkey ran agin a wall and squeezed the gentlemans leg and he
walloped it then and no mistake and serve it right. Then the donkey
began to speak and told him, and told him he was wicked to serve
him in that ere style, and a angel come down and took sides with
the donkey and preached a sarmint to the owld gentleman and they
all went away jolly."

An Excuse for Late Arrival at School.—The village tailor sent a note


to the schoolmaster as his son James was very late one afternoon.
The following is the effusion:—
"Schoolmaster dear don't cane the youth,

He's not in fault to tell the truth,

His mother is the greatest sinner.

She would not give the kid his dinner."

Dropped into Poetry.—The following reply, writes a teacher, was


received by me some years ago from a parent, evidently of a
poetical turn of mind, in answer to an inquiry as to the cause of his
boy's absence from school:—

"I'm full of wants and minus riches,

Truth is, William has no breeches,

I mean to buy a pair to-night,

To-morrow he will come all right.

Accept this plain apology

From, dear Sir, ever yours, E. B."

On another occasion I suspected William of truant-playing, and


sent a boy to make inquiry, when immediately came back the
answer:—

"At one p.m. was sent to school,

So must have played the nick,


If thrashing truants is a rule,

With my leave, use the stick."

William is now a hard-working and well-known missionary in ——.

Found Out.—A school attendance officer quite recently met a lad


who, instead of being at school, was wending his way to a public-
house for a pint of beer. "How is it you are not at school, my boy?"
said the man of law. "It's washing day, and I'm going for a pint of
ale for my mother." He let the boy go on his errand and walked
straight to the lad's house. "Good morning, Mrs. So-and-so. How is it
your boy is not at school this morning?" "Ah! bless you," she says,
"the poor lad's ill in bed, and has been the past two days. I'm afraid
we shall never rear him, for you see he's been delicate ever sin he
was born." "Can I see him?" returned the officer. "Certainly, if you'll
wait a minute till I see if he's awake. He's had a bad night, and I
should not like to disturb him if he's asleep." The good lady went on
tiptoe to the foot of the stairs and called out very softly, "Johnny,
Johnny, Johnny, are you awake?" Returning to the attendance officer
she said, "You see, Mr. Schoolboard, Johnny's asleep, and it would
be such a pity to disturb him." Just as she finished, in walks Johnny
with the pint of beer. The old lady, to make the best of a bad job,
threw up her hands and exclaimed, "My dear Johnny, how did you
get out? What a bad lad to get out of the bedroom window again,
after all I've said!"
A Trifle Inconsistent.—An excited woman rushed into school one
morning holding a lad by the jacket collar. The moment she got
inside she shouted out, "Now, master, here's a lad that's been
playing the wag [truant], and I don't intend to leave this blessed
spot until I see him skinned. Please, master, skin him alive! I must
see him skinned!" she said. To make the best of a serious case, the
master replied, "Well, I don't skin till ten o'clock, and it is only a
quarter past nine yet, so you had better sit down till I'm ready." She
took a seat, still holding the lad by the collar, and he went to his
desk. In about five minutes she sent the boy to his class, and
coming up to the master, whispered very softly into his ear: "Please,
master, don't touch the poor lad, he's so delicate, you could almost
blow him away with a breath!"

Johnny Worked the Clock.—"Plese Sir dont cain pore jonny he as


been keping the clock agoing with a stick cos is father mendid it an
it wont go now an jonny kep the clock agoing so as I would no the
time so no more as it leaves me at present. ——."

Blurted Out the Truth.—A mother came with a truant one morning
and said, "Please excuse my boy, he has been ill the last fortnight."
The master said, "Very good, let him go to his class." The woman
then turned suddenly round and, seizing the lad by the jacket, gave
him a good shaking, saying at the same time, "I'll break every bone
in your dirty carcase if I've to come again and tell a pack of lies like
this for you."
The Point of View.—Overheard in infants playground. Little Girl:
"It's my grannie's funeral to-day. I've got threepence halfpenny and
a packet of sweets already."

A Trifle Mixed.—Poor Johnny had been on an errand for his


mother and was consequently late for school. His mother, in order to
coax him, prepared to write a note to his teacher explaining his
lateness. The look on Johnny's face made the mother somewhat
dubious about Johnny's going to school, and this is how the note
read: "Dear Sir,—Please excuse Johnny for being late, and kindly let
me know if he hasn't been."

She was Sorry.—A boy was absent from school. The teacher sent
to his home to ask the reason. The answer came back that he was
playing truant—sent by the mother. The next day the master made
inquiries, and found that the mother had sent this message because
she did not wish the boy's father, who was at home when the
messenger arrived, to know that she had kept him at home. During
this time the boy himself was hidden in a cupboard. A few weeks
after a similar occurrence happened, and a like answer was sent to
the master by the mother. The next day the boy appeared with the
following note: "Sir,—Sorry my boy was away yesterday, but he had
to go to the hospital and was kept, and I never sent him yesterday,
and I was sorry to tell a lye like last time. Please forgive me again.—
Mrs. ——."
"The Lavender."—"Deer Sur,—Plese let Jon go to the lavender wen
hever he wants as he as had some metson.—Yours truly, Mrs. ——."

"Res Angusta Domi."—In a village school in Devonshire the master


had one morning been giving a lesson on the life of Jacob. Just as
he was concluding he asked whether Jacob was rich or poor. Some
stated that he was rich, while others held a contrary view. Eventually
one of the lads who had stated that Jacob was poor was asked for
his reason, and he replied as follows: "Please, sir, the Bible says
Jacob slept with his fathers, and if he had been a rich man he would
have had a bed to his-self."

The Postman.—"The postman has to be up erly in the morning to


meet the males at the station. Then he takes them to the G.P.O.
where they are soughted out. Then he ties up his streets in bungles,
and goes quickly from door to door, because the passengers dont'
like to have their letters delaid. On his way back, he collects the
pillow boxes, and conveys them to the G.P.O. Inside the postmen
they are stamping letters. The postman is a simple servent because
he works for the goverment and wear a uniform. He has a good time
at Xmas I should like to be a postman then. He gets plenty of Xmas
boxes and can read all the picture postcards."

Exactly.—The other week Standard V. were asked to write an


essay on "My Home." This is how one boy commenced: "Our house
is in Peel Green Road. It is on the left side going up, and the right
side coming down."

On Girls.—By a boy.—"There are two sorts of children, boys and


girls and of the two boys are the best. Girls cause all the rows and
quarrels. They think they are wonderful if they can get a bird's
feather stuck in their hat. They are proud and vain and are always
gossipping and making mischief. I simply hate them. They boast of
what they can do, this that and the other and a fat lot it is when it
comes to the put. If there were no girls and women in the world, it
would be a very peaceful place. They love to sit and rest. Girls do
vary from day to day. On washing days they think they are nearly
killed. They would rather gossip half a day, than walk half a mile. Its
no good, they are a bad race and deceitful. If your wife sells
anything she keeps a shilling back. Girls like to wear rings and think
they are ladies. They bob their hair on the top like mountains and
wears a fringe to make us boys think they are pretty, but aint they
just deceived. The young men have a hard job to find a good and
hard working wife in these days. Girls are cowards and I never knew
one to face danger. If a cow looks at them they run and cry. Boys go
about with their eyes open and their mouths shut, just the opposite
to girls. Boys are also strong and useful while girls are timid,
frightened weak little creatures. I would not be a girl for £10."

"Your Grace."—A certain duchess, well known for the interest she
takes in the progress of education, once visited a school in L—— and
began to talk freely to a mite in the first standard. Several questions
were put to the child, to which the latter replied, "Yes, ma'am," or
"No, ma'am." The teacher of the class was annoyed at the frequency
with which the scholar used the word "ma'am," and at last said,
"You must say 'Your Grace.'" The duchess laughed heartily when the
child began, "Lord, make us truly thankful, &c."

About a "Cinmattergraf."—"We had a grand cinmattergraf at school


on November 30th by Eddyston. Eddyston is America man. He
invented to make it. Cinmattergraf works very fonny. If you swing a
stone round it is in your eye a tenth of a cetend after you have
stopet. If you are in a dark room and somebody brings a light it is in
your eye a tenth of a cetend. The cinmattergraf is like a fonagrapt. It
is like a mager lantin. A cinmattergraf is eaquil to five thousand
candles. The ribbing rowls off one rowler on to another rowler. The
cinmattergraf was worked by angle. It is like a soingnmersheen. It
will play any song. The cinmattergraf talks like people. You cant
understand what a gramophone says. When you light the oxgin it
not give much light. When one of the things is burken the other
blows in and it give bleu light. When the man shows the foters he
has to put the lamp out. Because if he does not put the lamp out the
pictures look shady. It is the light which helps to show the pictures.
The pictures on the cinmattergraf are only an inch big. One picture
that it showed was a woman laughting, and you could see every
form her mouth was in. When all the pictures were put together they
were a quarter of a mile long."

Concerning the Horse.—Standard III. boy's essay: "The horse does


not belong to the cat tribe, because its paws are hoofs. It breathes
with its gills when it is young and chews the cud just like other
people. There are many kinds of horses such as racer horses and
hunters and worker horses and little welsh ponies. A mule is a horse
with long ears and if a horse had long ears it would be called a
donkey. You can see the age of a horse if you look in its mouth. It is
defensive with its hind legs and when they kick you, you say, Woe."

The Retort Courteous.—One of my boys, writes a friend, had his


hair notched in a disgraceful manner one morning, and I quietly
asked him who cut it. The accompanying note was the result: "from
missus ——,—sir—as you seam so anshus to no wear my boy ad is
air cut i wish to tell you that i put im in the cole seller al larst nite so
as the rats cood nibbel hit horf and i cood save tuppence."

On the Baby.—"A baby is a man or woman as they first enter the


world, and is sometimes called a infant, and they bring plenty of joy
to its parents. Babies need much care because the bones are not
strong enough for the baby to be used naturally. When a baby is a
few months old a malecart is wanted so as to give it some fresh air,
and it as to be nursed till it can crawle about on the flour. Most
women like babies very much and wouldn't do without them. When
first it is born it is very teisey and begins to cry, and they are enough
to make anyone mad. It also needs a lot of care, for it will enhail any
disease. Baby is the pet of the family, especially mother, who if the
baby is a boy he becomes her darling boy in after years. When baby
is about four years old it is briched if it is a boy, but if a girl she
remains in her same clothes. To look after a baby is very awkard if
you ain't used to it, for they jump and kick and have to be carefully
handled. It is crisined when it is old enough to eat solid food. Some
babies are very tiresome and have to be nutritiously looked after. My
father told me that he came in a little blue box, but learned men say
we came from monkeys. If the mother trys to learn it to walk very
early it will make them bandy. My baby is a dear little thing!"

"To keep milk from turning sour you should leave it in the cow."—
Jane, aged 10.

"The Duke of Marlborough was a great general, who always


fought with a fixed determination to win or lose."—Our Sammy, aged
11.

"The name of Cæsar's wife was Cæsarea. She was above


suspicion."—Small Boy's History Paper.

EXCUSED!

Teacher: "Why did you stay away yesterday, Jimmy?"

Jimmy: "Please, sir, muvver's ill!"

Teacher: "Oh! that's bad! What does the doctor say it is?"

Jimmy: "Please, sir, he says it's a girl!"


Fond Mother: "Charley, do you know God's other name?"

Charley: "Yes, mamma, we learnt it to-day. Harold be Thy name!"

Parental Note: "Dear Sir,—Don't hit our Johnny. We never do it at


home except in self-defence!"

Head Master: "How did God bless Abraham?"

Small Boy (in whose home there has just been a Double Event):
"By giving him only one baby at a time!"

Mistress: "Why is a motor-car called 'She'?"

Small Boy: "Because it is driven by a man!"

Teacher: "Now, Frank, if you are not a good boy you won't go to
heaven."

Frank: "Oh, well! I went with father in Mr. B.'s yacht, and I went
to the circus. A little boy can't expect to go everywhere!"
H.M. Inspector: "If I dig right down through the earth, where shall
I come to?"

Small Boy (who has been commended at the Diocesan


Examination): "The devil and all his works!"

Teacher: "What is a Mediator?"

Small Boy: "A chap who says hit me instead!"

JUVENILE COMPLAINTS.

(AS DESCRIBED IN PARENTAL EXCUSE NOTES.)

"New Roger"—Neuralgia.

"Real Raw Jaw"—Neuralgia.

"Piper's Dance"—St. Vitus Dance.

"Haricot Veins"—Varicose Veins.

"Double Demoniacks"—Double Pneumonia.

"Scarlet Concertina"—Scarletina.

"Illustrated Throat"—Ulcerated Throat.

"Information of the Eye"—Inflammation of the Eye.


[AND SO ON.]

Teacher: "What is luke-warm water?"

Small Girl: "Water that lukes warm but isn't!"

Teacher: "Now, little ones, you can take off your warm overcoats.
Can the bear take his off?"

Little Ones: "No, miss!"

Teacher: "Why not?"

Delighted Little One: "Because only God knows where the buttons
are!"

"The anshent Britons painted themselves all over blue with the
juce obtained from the tree o nolledge of Good and Evil."—From
Harry's Composition Exercise.

Teacher: "What is a widow?"

Little Girl: "A lady what marries the lodger!"


Teacher: "What is this?"

Young Hopeful: "A picture of a monkey."

Teacher: "Can any child tell me what a monkey can do?"

Young Hopeful: "Please, teacher, a monkey can climb up a tree."

Teacher: "Yes, and what else can a monkey do?"

Young Hopeful: "Please, teacher, climb down again!"

Boy (reading): "She threw herself into the river. Her husband,
horror-stricken, rushed to the bank——"

Teacher (interposing): "What did he run to the bank for?"

Boy: "To get the insurance money!"

H.M. Inspector: "If twenty feet of an iceberg be above the water,


about how much is below the water?"

Jim: "All the rest!"

Tommy: "Mamma, who made the lions and the elephants?"


Mamma: "God, my dear."

Tommy: "And did He make the flies, too?"

Mamma: "Yes, my dear."

Tommy (after a period of profound reflection): "Fiddlin' work


making flies!"

Teacher: "Why cannot we hear the bear walk about?"

Child in Lancashire Town: "Because it hasn't got no clogs on!"

H.M. Inspector was examining a class of infants on the value of


money. He held up a threepenny-piece and a penny. "Now, my
children, which would you rather have, this small piece of money or
the large one?" A little one held up her hand. "Well?" "Please, sir, the
large one." "And why would you rather have the large one?"
"Because my mother would make me put the threepenny-bit in my
money-box, but I could spend the penny."

Tommy is in the Second Standard, and aged eight. The class was
asked to write a short letter to teacher describing their doings on
Guy Fawkes night. He began in right good style with the orthodox
"Dear Miss C——." Everything went quietly till the close. It was then
that Tommy shone. He wound up: "I remain, your loving son in who
I am well pleased,——"
"Manners is a very good thing when you are trying for a
situation."—From James Henry's Composition.

The essay was upon "Dreams." One boy who has a great dread of
arithmetic dreamt he was in heaven, where his teacher kept calling
out, "No sums right, stand up!"

Teacher: "Well, well, James! Home lesson sums all wrong!"

James: "Yes, teacher. I knew they would be. Father would help
me!"

THE END.
PRINTING OFFICE OF THE PUBLISHERS

By the Author of "School-Room Humour."

The Gentle Golfer


With over 100 Pen-and-Ink Sketches by
ARTHUR MORELAND.
Fcap, 8vo, 180 pp. Paper Covers 1/-, Cloth 1/6.

"The humour is infectious."—Evening Standard and St. James's


Gazette.

"These lively sketches will appeal to every golfer."—Sheffield Daily


Telegraph.

"Written in a very racy style."—Liverpool Courier.

"Intensely amusing and not wholly uninstructive."—Field.

Bristol:
J. W. Arrowsmith.
London:
Simpkin, Marshall, Hamilton, Kent & Co. Ltd.

ARROWSMITH'S
POCKET
SERIES.
Fcap. 8vo, Leather, Gilt top and back, 3/6 net.
" Cloth "" 2/6 net.
The Westcotes.
By Sir Arthur Quiller-Couch.

From a Cornish Window.


By Sir Arthur Quiller-Couch.

The Prisoner of Zenda.


By Anthony Hope.

Rupert of Hentzau. Being a Sequel to "the prisoner of zenda."


By Anthony Hope.

Sophy of Kravonia.
By Anthony Hope.

The Diary of a Nobody.


By George and Weedon Grossmith.
(With an appreciative letter from LORD ROSEBERY.)

Home Life with Herbert Spencer. By "Two."

The Charm of the West Country. An Anthology.


Compiled and Edited by Thomas Burke.

Bristol: J. W. ARROWSMITH LTD.


London: Simpkin, Marshall & Co. Ltd.

Arrowsmith's 1/= net Series of


Cloth-bound Novels,
WITH PICTURE WRAPPERS.

Foolscap 8vo size.


Ziska. By Marie Corelli.

Called Back. By Hugh Conway.

The Tinted Venus. By F. Anstey.

Hetty Wesley. By Sir Arthur Quiller-Couch

Patricia at the Inn. By J. C. Snaith.

The Man who was Thursday. By G. K. Chesterton.

Johnny Fortnight. By Eden Phillpotts.

Two in a Tent—and Jane.


By Mabel Barnes-Grundy.

Pearla. By Miss Betham-Edwards.

Bristol: J. W. ARROWSMITH LTD.


London: Simpkin, Marshall & Co. Ltd.

A Selection of
Arrowsmith's 6/- Books.

The Prisoner of Zenda. By Anthony Hope.

Rupert Of Hentzau. By Anthony Hope.

Sophy of Kravonia. By Anthony Hope.

Ziska: The Problem of a Wicked Soul.


By Marie Corelli.
My Own Fairy Book. By Andrew Lang.

The Westcotes. By Sir Arthur Quiller-Couch.

Two Sides of the Face.


By Sir Arthur Quiller-Couch.

From a Cornish Window.


By Sir Arthur Quiller-Couch.

True Tilda. By Sir Arthur Quiller-Couch.

Brother Copas. By Sir Arthur Quiller-Couch.

The Man Who Was Thursday.


By G. K. Chesterton.

The Vacillations of Hazel. By M. Barnes-Grundy.

Marguerite's Wonderful Year.


By M. Barnes-Grundy.

A Close Ring. By M. Betham-Edwards.

Dromina. By John Ayscough.

A Roman Tragedy and Others. By John Ayscough.

Woodhays. By E. F. Pierce.

Suse O'Bushy. By W. A. Allan.

The Gentleman Help.


By Elizabeth Holland (Lady Owen.)

Bristol: J. W. ARROWSMITH LTD.


London: Simpkin, Marshall & Co. Ltd.
Transcriber Notes:
Throughout the dialogues, there were words used to mimic accents of the
speakers. Those words were retained as-is.

The illustrations have been moved so that they do not break up paragraphs
and so that they are next to the text they illustrate. Thus the page number of
the illustration might not match the page number in the List of Illustrations, and
the order of illustrations may not be the same in the List of Illustrations and in
the book.

Errors in punctuations and inconsistent hyphenation were not corrected


unless otherwise noted.

On page 9, a period was added after "CHAPTER I".

On page 19, "ithers" was replaced with "others".

On page 40, a period was added after "Standard VII".

On page 54, a period was added after "are grisle".

On page 64, "sanwiches" was replaced with "sandwiches".

On page 64, "apetites" was replaced with "appetites".

On page 71, a single quotation mark after "Cast out a devil, sir!" was
replaced with a double quotation mark.

On page 98, a period was added after "hot nor cold".

On page 107, a period was added after "B".

On page 119, a quotation mark was added before "is your favorite writer".

On page 120, a single quotation mark was added after "their lives".

On page 129, a single quotation mark after "sweet song" was replaced with
a double quotation mark.
On page 132, a single quotation mark before "How many" was replaced with
a double quotation mark.

On page 148, "an errand" was replaced with "on an errand".

On page 153, "November th 30" was replaced with "November 30th".

In the first advertisement, a period was added after "Field".


Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like