Training - Power Query & Power Pivot 2024-04 - Slides - FINAL
Training - Power Query & Power Pivot 2024-04 - Slides - FINAL
Query
Power
Pivot
Training
April 2024 – Cloudia: 2301889
Learning outcomes
Learning outcomes
• Understand the capabilities and added value of Power Query
and Power Pivot
• Connect to a variety of data sources through Power Query
• Transform data through Power Query
• Build data model in Excel
• Analyze and visualize data through Excel by using Power Pivot
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 2
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Agenda
0 Introduction
1
0 Getting Started
2
0 Power Query
3
0 Power Pivot
4
0 Guidelines
5
0
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 3
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
0
1
Introductio
n
Excel vs. Power Pivot vs. Power BI
Excel
Spreadsheet software that organizes numbers and data using formulas and functions
Power Query
Data transformation and data preparation engine (ETL) used in Power Pivot and Power BI
Power Pivot
Excel add-in that performs powerful data analyses and creates sophisticated data models
Power BI
Business intelligence and data visualization tool that enables easy interaction and customization
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 5
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
From data to insights
Connect to Define relationships and
numerous sources Extract, Transform, Load (dynamic) calculations Analyze and visualize
Power Query
Data Model
in Power BI
Power BI
When enabling the add-in for the first time, do not click on Enable Content in the yellow bar
that has appeared but go to File > Info > Security Warning > Enable Content > Advanced
Options and select Enable all code published by this publisher twice. If this procedure is not
carried out, the Power Pivot add-in has to be re-enabled each time Excel is opened.
If Excel crashes, the Power Pivot add-in may not reload again automatically even though the
add-in may still be selected as being active. If this is the case, the add-in should be disabled
and re-enabled.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 9
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
0
3
Power
Query
From data to insights
Connect to Define relationships and
numerous sources Extract, Transform, Load (dynamic) calculations Analyze and visualize
Power Query
Data Model
in Power BI
Power BI
Note (a): A connection connects your workbook to a data source, like a highway connecting two cities. A query is the request
for actual data that you spell out, calling from your workbook via the connection into the data source. The data source then
sends the data back via the connection. The mechanics of asking for, receiving, and manipulating the received data is what the
query does, but it can't do this without the connection. The query is the actual traffic on the highway.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 13
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Query Editor Right-clicking a column header will show most of the transformation options that
can be applied to the selected column. Alternatively, transformations can be
applied by selecting one or more columns and clicking on the relevant
transformation functionalities in the ribbon.
Ribbon
Queries
Query steps
Most transformations can be performed using the graphical interfaces of the Power Query Editor functionalities. In some
cases, one may need the formula language Power Query M to perform desired transformations. In that case, Google
and the Microsoft community can be used to look up how to formulate the necessary Power Query M formulas.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 14
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Query Editor: Home (1)
1
Note that the preferred way for loading data is to Only Create Connection and to
select Add this data to the Data Model for those queries that need to be present in
the data model.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 15
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Query Editor: Home (2)
4
1 2 3 5
1. Query: Refresh output preview(s), adjust query properties, open Advanced Editor, delete/duplicate/reference query
- Refresh Preview does not refresh any data in Excel, it only refreshes the output preview in the Power Query Editor;
- Duplicate creates an exact copy of the query whereas Reference creates a new query that starts from current query’s output;
- Advanced Editor shows users the full M code for an entire query, which is handy for checking errors and copying large portions of a query
(note that the M code for a specific step can also be adjusted in the formula bar by selecting the relevant step in the right Query Settings
pane).
2. Manage Columns: Remove or select specific columns
3. Reduce Rows: Keep or remove specific rows
- Keep/Remove Rows is very useful to focus on or to exclude duplicates, blanks and errors
4. Sort: Sort selected column
5. Transform: Split columns, group columns, change data type of columns, use first row as headers (or headers as first row), replace values
- Split Column can be useful when relevant data is aggregated into one column (e.g. customer numbers and names are reported in one column)
- Data Type can be changed in either the column header in the output preview or in Home > Transform
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 16
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Query Editor: Home (3)
1 2 3 4
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 17
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Query Editor: Transform (1)
1 2 3
1. Table: Group columns(a), use first row as headers(a) (or headers as first - Move allows the moving of columns left and right (columns can also be
row(a)), transpose rows and columns, reverse row order, output the number dragged and dropped in order to move them)
of rows
3. Text Column: Perform transformations meant for text columns
2. Any Column: Perform transformations meant for all data types - Split column(a) can be useful when relevant data is aggregated into one
- Data Type(a) can be changed in either the column header in the output column (e.g. customer number and name are reported in one column)
preview, or in Home > Transform, or in Transform > Any Column - Format allows columns to be reformatted such as transforming into
- Detect Data Type enables the automatic detection of the data type (it is uppercase and trimming whitespaces
recommended to always check data types of each column afterwards) - Merge Columns allows the concatenation of two or more columns
- Fill Down/Up copies the value of the cell above/below when a cell is
- Extract pulls certain values from a column such as length, first character
empty
and text before delimiters
- Unpivot Columns translates columns into attribute-value pairs (e.g.
- Parse allows the extraction of data from XML- and JSON-formatted text
accounts as rows, months as columns and amounts as values can be
translated into a column for accounts, a column for months and a column
for amounts) Account Month Value
M1 M2 A1 M1 V11
A1 V11 V12 A1 M2 V12
A2 V21 V22 A2 M1 V21
Note: (a) Also available in the Home tab A2 M2 V22
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 18
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Query Editor: Transform (2)
1 2 3
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 19
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Query Editor: Add Column
1 2 2 2
1. General limitlessly without having to reconstruct the entire logic each time)
- Column From Examples guesses the Power Query M formula that should - Conditional Column opens a wizard that lets the user add a column that
be applied to create a new column based on examples the user inputs is dependent on values in other columns (this can also be realised in the
manually This function should be treated with care as the guessing Custom Column by applying if-then-else logic)
capability of the Power Query Editor has its limits and may provide - Index Column creates a column with index numbers starting at and
unwanted output
incrementing with customisable values
- Custom Column wizard allows the user to create a new column based on
- Duplicate Column copies the currently selected column’s values into a
a Power Query M formula constructed by the user. It has very useful
new column
features such as a syntax helper showing which parameters should be
filled in and which are mandatory/optional, automatic syntax error 2. From Text, From Number and From Date & Time contain the same
checking, as well as an overview of available columns which can be used functionalities as Transform > Text Column, Number Column, and Date &
as input for the formula Time Column but creates a new column instead of replacing the current
column
- Invoke Custom Function enables the application of a custom Power
Query M function created by the user (a custom function allows users to
create a custom logic containing one or more steps that can be applied
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 20
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Query Editor: View
1 2 3 4 5 6
1. Layout 3. Columns: Go to Column lets the user select a specific column in output
- Query settings enables/disables the Query Settings pane on the right preview
which contains the query properties and query steps 4. Parameters: Always allow parameterisation in data source and
- Formula Bar enables/disables the formula bar transformation dialogues without having to create a parameter beforehand
(parameters allow users to store and manage values that can be reused
2. Data Preview throughout all queries)
- Monospaced shows all output value characters in a monospaced font 5. Advanced: Open Advanced Editor to review and adjust the Power Query M
- Show whitespace makes whitespace and newline characters visible code of the selected query
- Column quality shows the percentage of valid values, error values and 6. Dependencies: Query Dependencies show interdependencies between
empty values per column queries
- Column distribution shows the distribution of the value occurrences per
column
- Column profile shows column statistics and column distribution in the
bottom details pane
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 21
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Query Editor: Right-click on
query 1. Copy/Paste/Delete/Rename/Duplicate query
2. Reference query: Use query output as input for a new query (a)
3. Move To Group: Move query to existing group or create new group and move query to that group
4. Move Up/Down: Reorder query list
1
5. Create Function: Create custom function containing the same steps as the current query
6. Convert To Parameter: Convert current value to a parameter
2 7. Advanced Editor: Review and adjust the Power Query M code of the selected query
3 8. Properties: Adjust query name, add query description and enable Fast Data Load
4
- Background Data Load (default): Queries are loading in the background while the user can still use
Excel
5 - Fast Data Load: Excel operation is halted and processing power is dedicated to data loading, which
6 results in faster data loading but which may make Excel unresponsive for some time
7
8
Note: (a) Pay attention when using this function. If you perform further manipulations on the initial query (the one being referenced),
it will also change the reference query (e.g. if you filter the initial query to contain only 2020, then the second query will also be
filtered).
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 22
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
0
4
Power
Pivot
Data
Model:
Relations
hips
What is a data model?
• Data models are collections of tables (cf. spreadsheets) consisting of attributes (columns) and
records (rows) similar to Excel.
• Structure is really important in data models which makes them really efficient in storing,
requesting and manipulating data, unlike Excel which is relatively free-format.
• Efficiency in a data model is achieved by eliminating data redundancy, amongst others.
• Data is generally stored in two types of tables:
- Fact tables record facts of a (business) process: typically denoted as ‘fName’ (e.g. fSales) e.g.
sale of product X to customer Y on date Z for € 100;
- Dimension tables store attributes (dimensions) of these facts: typically as ‘dName’ (e.g.
dCustomers) e.g. product X is red, weighs 10 kg and is supplied by supplier W; customer Y is
called John and lives in Amsterdam;
• Dimension tables should always contain unique values. Multiple customers can be called
John from Zaandam, but each customer must have a unique defining attribute, often a
customer ID number.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 25
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Dimension tables and fact tables are
linked through relationships
dProducts fSales dCustomer 2. One-to-many (1-to-*): Unique values (generally dimension
ProductID CustomerID CustomerID tables) at one end vs. recurring values (often fact tables) at the
Product name ProductID First name other end of the relationship e.g. one unique customer can
make multiple purchases: The customer dimension table has a
Product category Quantity Last name
list of unique values (cf. CustomerID in dCustomer), but there
Brand Sales Address
are multiple sales records allocated to that customer in the
Colour City sales fact table (cf. CustomerID in fSales)
Phone number
3. Many-to-many (*-to-*): non-unique values at both ends of the
relationship: This makes matching records of one table to
Relationships work similarly to VLOOKUP in Excel, linking tables another ambiguous and is not allowed in Power Pivot (it will
based on a unique identifier. However, in comparison to VLOOKUP, generate an error). Note that this is rarely used and generally
the related data is not actually stored in one combined table after beyond the scope e.g. ProductID occurs multiple times in
making a relationship but stays stored within the different source dProducts and multiple times in fSales: Product attributes such
tables. as brand and colour cannot be unambiguously linked to
There are three different types of relationships: products in fSales table
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 26
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
From data to insights
Connect to Define relationships and
numerous sources Extract, Transform, Load (dynamic) calculations Analyze and visualize
Power Query
Data Model
in Power BI
Power BI
1. Manage: Open Power Pivot for Excel window 5. Detect: Detect relationships automatically for selected
- This window can also be opened through Data > Manage Data PivotTable.
Model. - Better to manually link tables in the data model to make sure
2. Measures(a): Add new or manage existing measures. tables are related to one another correctly.
3. KPIs(b): Add new or manage existing KPIs. 6. Settings: Adjust Power Pivot settings.
4. Add to Data Model: Directly add Excel table from the worksheet - Does not contain any relevant settings.
to the data model without data transformation).
- Data > Get & Transform Data > From Table/Range (including Note (a): Measures are DAX formulas for which the calculated results are always changing
in response to interaction with the context to which they are applied, allowing for fast and
data transformation through Power Query). dynamic ad-hoc data exploration.
Note (b): KPIs are used to visually compare values against target values.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 28
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Pivot for Excel: Data View
Ribbon
Column
selector DAX formula
bar
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 29
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Pivot for Excel: Diagram View
Ribbon
Overview of all
tables in data
model including
relationships
between the New relationships can be created by
tables dragging and dropping
Existing relationships can be adjusted
by double-clicking the relationship
lines
1 2 3 4 5 6 7 8 9
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 31
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Pivot for Excel: Design
1 2 3 4 5 6
1. Columns: Add, Delete, Freeze columns or change column width. 4. Table properties: Change table properties for tables created
- Columns not added through Power Pivot cannot be deleted without Power Query intervention.
through Power Pivot, they should be adjusted/deleted through 5. Calendars: Create date table from existing table or create new
Power Query Editor instead. date table based on adjustable range and configuration.
2. Calculations: Insert DAX functions through wizard and change 6. Edit: Undo or redo DAX-related actions (e.g. undo last DAX
DAX function calculation from/to manual to/from automatic. function adjustment).
- Functions can also be added by typing in the DAX formula bar
(function suggestions and function information will appear
when typing).
3. Relationships: Create or adjust existing relationships between
tables.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 32
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Power Pivot for Excel: Advanced
1 2 3 4 5
1. Perspectives: Create and select different views of the available 3. Summarize By: Change the behaviour for automatic
data in Power Pivot through which only some of the implementation of implicit measures (e.g. DISTINCTCOUNT
tables/columns are shown. instead of SUM).
2. Show Implicit Measures: Show/hide measures that have been 4. Reporting Properties: Set default field order and behaviour for
implicitly created by Power Pivot when adding data to the Values Power View reports.
fields in PivotTable or PivotChart. - Power View reports in Excel have been discontinued, Power
- Best practice is to use explicit measures (i.e., measures BI reports should be used instead.
generated by user) instead of automatically calculated implicit 5. Language: Add synonyms for available columns and measures
measures in order to avoid unintended output (e.g. a field may which can be used in the Power BI Q&A feature.
be automatically implemented into a measure as COUNT
instead of SUM).
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 33
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Working
with
DAX
measures
Data Analysis Expressions (DAX)
Measures are the heart and soul of Power Pivot and Power BI measures. They enable to make
every calculation that you can imagine. Measures are written in DAX code. The language structure
is comparable to Excel formulas. You can write measures in the empty cells below the tables in the
Power Pivot Data View.
Measures are defined as follows:
The := identifies where the measure name ends and the calculations begin. As an example, to
calculate the sum of order quantity, the measure looks like:
sQuantity := SUM(fSales[quantity])
We can also make measures for sales, gross margin, average price, average GM and the average
GM percentage. We can use measures within subsequent measures (see color codes).
sSales := SUM(fSales[Sales])
sMargin := SUM(fSales[Margin])
avgPrice := DIVIDE([sSales];[sQuantity])
avgMargin := DIVIDE([sMargin];[sQuantity])
avgMargin% := DIVIDE([sMargin];[sSales])
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 35
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Evaluation context
Measures are calculated based on the evaluation context. This allows us to define a measure once and reuse it based on different slicing and dicing of the
data. Filters, Columns and Rows settings in your PivotTable settings define the evaluation context for the measures (Values).
Same measures,
different outcomes
sSales_USA:=CALCULATE([sSales];dRegions[Country]="United States")
As a result, every country will show the sales for the USA for this measure. We can now create a
new measure which compares the sales of the region with the sales of the USA:
sSales_%USA:=DIVIDE([sSales];[sSales_USA])
In the example, we can observe that in 2016, the UK sales were 16,1% of the USA sales while the
Australia sales were 22,5% of the USA sales.
The CALCULATE function can also be used for other purposes such as time intelligence which
comprise, amongst others, year-to-date, last-twelve-months and prior year calculations, by altering
the date evaluation context.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 37
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Time intelligence: PREVIOUSYEAR
function
Time intelligence allows us to make calculations for periods outside of our evaluation context. If we wish to calculate the
previous year’s sales, we can use the PREVIOUSYEAR function, which automatically filters the date table to the previous
year.
The syntax is as follows:
The date column in your date In case the fiscal year end does not match the calendar year,
dimension table you can provide a month and day manually, e.g. “30/9”.
Example:
sSales_LY:=CALCULATE([sSales];PREVIOUSYEAR(dDates[Date]))
sSales_Diff:=[sSales]-[sSales_LY]
sSales_Diff%:=DIVIDE([sSales_Diff];[sSales_LY])
Important to note is that the PREVIOUSYEAR function calculates the measures for the entire previous year. So if our current
evaluation context would be February 2017, the sSales_Diff formula would compare the sales of February 2017 with the
sales of entire 2016 which would not make a lot of sense.
Similar formulas exist for PREVIOUSMONTH and PREVIOUSQUARTER.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 38
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Time intelligence:
SAMEPERIODLASTYEAR function
Time intelligence allows us to make calculations for periods outside of our evaluation context. If we wish to calculate the
sales for the same period last year compared to the current evaluation context, we can use the SAMEPERIODLASTYEAR
function.
The syntax is as follows:
SAMEPERIODLASTYEAR(dateTable[DateColumn])
Example:
sSales_LY2:=CALCULATE([sSales];SAMEPERIODLASTYEAR(dDates[Date]))
sSales_Diff2:=[sSales]-[sSales_LY2]
sSales_Diff%2:=DIVIDE([sSales_Diff2];[sSales_LY2])
On a yearly basis, this DAX formula will give the same result as the PREVIOUSYEAR formula. However, when selecting a
specific period within a year, SAMEPERIODLASTYEAR will select the same period in the year before. For example, if the
sales of February 2017 are selected, SAMEPERIODLASTYEAR will give the sales for February 2016.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 39
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Time intelligence: DATESINPERIOD
function
In addition to the previous functions, DAX has various other functions to alter the date evaluation context. Another relevant example is the DATESINPERIOD
function. The function takes 4 parameters and the syntax is as follows:
DATESINPERIOD(dateTable[DateColumn]; base date; number of intervals; interval unit)
Example:
sSales_LTM:=CALCULATE([sSales];DATESINPERIOD(dDates[Date];MAX(dDates[Date]);-12;MONTH))
The example above allows us to calculate the sales for the last 12 months. The DATESINPERIOD function in the example above is applied on the Date column
of the dDates table, starts from the latest date of our current evaluation context and calculates back 12 months. For example, if March 2017 would be selected,
the formula would change the evaluation context to 1/04/2016 until 31/03/2017.
The number of intervals and the interval size can be changed as desired.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 40
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
SUMX function
SUMX is an iterator function that works on a row-by-row calculation for a given expression or equation. This function considers each row at a
time and applies a calculation. It then aggregates the row-by-row results through a SUM function without storing the individual row-by-row
results.
Syntax:
SUMX(Table; Calculation)
Example:
sSales_SUMX:=SUMX(fSales;fSales[quantity]*fSales[price])
The example above calculates for each row in the fSales table the expression that multiplies quantity with price, and then sums the results for
each row. This could be a useful formula if only the quantity and price columns are available in the dataset but no sales column. The example
is comparable to the Excel formula SUMPRODUCT.
Please note that SUMX requires a relatively high amount of processing power to calculate on a row-by-row basis and then aggregate the
results. Therefore, it is recommended to use the iterator functions sparingly.
Similar formulas exist for AVERAGEX, MINX, MAXX …
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 41
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Working
with
Power
Pivot
Data
PivotTables & PivotCharts
We can visualize data that has been loaded to the data model using
PivotTables and PivotCharts within Excel. Both columns and
measures that reside within the data model can be visualized.
You can search for tables, columns or measures via the search bar
The orange icon indicates that a table is loaded into the data model
You can change the layout of the PivotTable by playing around with the location of the ∑Values field (refer to next page).
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 43
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
PivotTable Structure
1 2 3
2 3
We can show different values next to each other or below each other by changing the position of the
∑Values field to the Columns or Rows section. There is no optimal presentation. The way the
PivotTable should be presented depends on the reporting requirements.
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 44
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
GetPivotData formulas
We can dynamically link to PivotTables with the GetPivotData formula in our worksheets
The syntax for this formula is GETPIVOTDATA(data_field, pivot_table, [field1, item1, field2, item2….]) for
a regular PivotTable. The arguments are
- data_field: The name of the PivotTable field that contains the data that you want to retrieve. This needs to be within
quotes.
- pivot_table: A reference to any cell, range of cells, or named range of cells in a PivotTable. This information is used
to determine which PivotTable contains the data that you want to retrieve.
- [field1, item1, field2, item2….]: 1 to 126 pairs of field names and item names that describe the data that you want
to retrieve. The pairs can be in any order. Field names and names for items other than dates and numbers need to
be enclosed in quotation marks.
You can have Excel create the GetPivotData formula automatically by typing an ‘=‘ sign
in an empty cell and selecting a value from the PivotTable that you want to show in that
cell. The automatic generation of GetPivotData formulas can be enabled/disabled by
clicking on a PivotTable and going to PivotTable Analyze > PivotTable > Options >
Generate GetPivotData
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 45
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
GetPivotData formulas: Data Model
For PivotTables based on the data model, the syntax for the
GetPivotData formula is slightly different
=GETPIVOTDATA(“[Measures].[measureName], pivot_table,
"[Table Name1].[Field Name1]","[Table Name1].[Field Name1].&[Item
Name1]“)
- In this formula, we have to define that from our measures, we
want a specific measure, sSales in the example on the left.
- We can specify for which year and which country we want to
show sSales by including optional arguments in the
GETPIVOTDATA formula. Note that since we are working with
multiple tables in our data model, we have to first specify the table
name, and then the field name in the formula (between square
brackets).
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 46
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Unintentional duplication in data model
A PivotTable based on data from a data model is directly linked to that data model. Moving or copying the PivotTable
to another workbook will also copy the related data model. Beware when integrating two versions of the same
workbook to avoid duplicate queries ( ). 1
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 47
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
0
5
Guidelines
Benefits and drawbacks
Power Query and Power Pivot are effective tools for handling big data and provide major advantages over
traditional Excel functions
Benefits of using Power Query and Power Pivot Drawbacks of using Power Query and Power Pivot
• Practically no limit to the amount of data used • Working with data becomes more abstract, so you have to
make sure you stay in control by incorporating checks
• Analyses become less sensitive to human errors
• Power Pivot is sensitive to data quality issues such as missing
• Data manipulation procedures become more important which
values and wrong data types, so data preparation becomes
reduces repetitive work
very important
• Refreshing updated input data more efficient
• Actions are performed on the entire dataset rather than on
• Relations between data files can be created easily individual cells (cf. free-formatting in Excel)
• Once a dataset is reconciled, reconciliations from detailed • Difficult for inexperienced team members to evaluate
analyses can be traced back easily (cf. single point of truth) transformations and DAX formulas
• Endless functionality to slice data and drill down
• Seamless integration with Power BI
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 49
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Guidelines: Power Query
• Use external sources instead of copying data into analysis files • Apply naming conventions for queries and columns
• Start with transforming data into a simple flat-file format (i.e. - Self-explanatory query naming (e.g. fSales2019 instead of
unpivot if applicable) f2019)
• Add columns through Power Query rather than Power Pivot - Self-explanatory column naming
• Delete redundant data as much as possible - Use same column names for columns that are linked in data
model relationships
• Apply correct data types for columns
• Use query groups, if relevant
• Minimize query steps
• Always select Close & Load To… instead of Close & Load
• Rename query steps to improve readability, if relevant
• Only Create Connections instead of loading to Tables,
• Use helper queries (i.e. queries that are loaded to a connection
PivotTables or PivotCharts
only but that are useful as input for other queries), if relevant
• Add queries to the data model only if needed (i.e. do not add
helper queries to the data model)
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 50
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
Guidelines: Power Pivot & Power BI
• Always first check the correctness of data model relationships • Use self-explanatory measure names
(linked columns, directions …)
• Make measure formulas easily readable by using multiple lines
• Use Hide from Client Tools / Hide in report view functionality to and indentation
disable columns that should not be used in output tables or
• Do not overcomplicate measures, use helper measures if
visuals
relevant
• Use measures instead of calculated columns, if possible
• Use DIVIDE() function instead of ‘/’ operator
• Use explicit measures rather than automatically calculated
• Explicitly mention table names in DAX formulas instead of only
implicit measures
mentioning column names, even if the formula resides in the
• Locate measures in the relevant tables (e.g. locate measure same table as the related columns
sSales in fSales table)
• Reconcile and perform sanity checks early and often
- Optional: Some users use a separate measure table which
contains all measures only and no columns
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 51
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
0
6
References
References
Official Microsoft documentation
Power BI documentation
YouTube tutorials
© 2024 KPMG Advisory, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms affiliated Document Classification: KPMG Confidential | 53
with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
kpmg.com/socialmedia
Throughout this document, ‘we’, ‘KPMG’, ‘us’ and ‘our’ refer to the network of independent member firms operating under the
KPMG name and affiliated with KPMG International or to one or more of these firms or to KPMG International.
Some or all of the services described herein may not be permissible for KPMG audit clients and their affiliates or related entities.
© 2024 KPMG Belgium, a Belgian BV/SRL and a member firm of the KPMG global organization of independent member firms
affiliated with KPMG International Limited, a private English company limited by guarantee. All rights reserved.
KPMG refers to the global organization or to one or more of the member firms of KPMG International Limited (KPMG International),
each of which is a separate legal entity. KPMG International Limited is a private English company limited by guarantee and does
not provide services to clients. For more detail about our structure please visit
https://home.kpmg/xx/en/home/misc/governance.html.
The KPMG name and logo are trademarks used under license by the independent member firms of the KPMG global organization.