0% found this document useful (0 votes)
29 views131 pages

Manual Transforming Data Into Intelligence With Power BI and AI Integration

Uploaded by

Sumaira Ghouri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views131 pages

Manual Transforming Data Into Intelligence With Power BI and AI Integration

Uploaded by

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

DATA ANALYTICS

MICROSOFT EXCEL:
With
INTRO TO MSPOWER
EXCEL AND POWER BI
QUERY, POWER PIVOT
& DAX Two-Full days Training Program
Organized by NIBAF

With Best-Selling Excel instructor Chris Dutton


GETTING STARTED
COURSE OVERVIEW

Microsoft Excel is the world's most used and versatile business analysis, reporting
and strategy software. Having a deep practical knowledge of Excel will turn you
almost superhuman at work and increase your productivity.
This training is going to focus on making you highly proficient in the use of
Business Intelligence Tools of Excel which provide an expansive set of features
that enable to extract information from complex data, create dynamic reports and
presentations. In this training, learn how to manage, connect excel with different
data sources, compile huge data sets and create data model with Excel
PowerPivot, create a visually appealing Power View sheet, and use Power Map to
integrate the data with Bing Maps to
COURSE OVERVIEW
1 The “Power” Excel Landscape
• Power Query/Power Pivot workflow and key benefits vs. “traditional” Excel

2 Power Query
• Types of data connectors, query editing tools, loading options, etc.

3 Data Modeling
• Excel Data Model interface, normalization, table relationships, hierarchies, etc.

4 Power Pivot & DAX


• Power Pivots vs. “normal” pivots, calculated columns vs. measures, row & filter context, etc.

5 Common DAX Functions


• Basic syntax, math & stats functions, filter functions, time intelligence tools, etc.

6 Final Project
• Super Store Sales Data
VERSIONS &
COMPATIBILITY
IMPORTANT NOTE: Power Pivot is currently not available for Mac,
and is only available in certain versions of Excel for Windows/PC

For a full, current list of compatible versions, visit support.office.com (or Google “Where is Power Pivot?”):
https://support.office.com/en-us/article/Where-is-Power-Pivot-aa64e217-4b6e-410b-8337-20b87e1c2a4b (or use: bit.ly/2yd80rd)

Other considerations:
• Power Pivot works best with 64-bit Excel, which can access more processing power and memory (not critical)
• Note: make sure you’re running a 64-bit operating system and that you’ve updated Office to the 64-bit version

• Power Pivot menus, features and tools have evolved over time; what you see on your screen may differ
from what you see on mine, but the fundamental skills and concepts covered are universally applicable
• Even if you have a compatible version of Excel, you may need to enable the Power Pivot or Power
Query plug-ins to access the tools in this course (File > Options > Add-Ins > Manage: COM Add-Ins)
COURSE RATINGS &
REVIEWS
• Throughout the course, we’ll be using sample data from a fictitious super market
chain called “FoodMart”*
• In addition to daily transactional records from 1997-1998, our data set
includes information about products, customers, stores, and regions
• All files are available for download in the course resources section of your
course dashboard (Course Dashboard > Course Content > All Resources)

Transactions Returns Customer Lookup Calendar Lookup Product Lookup Store Lookup Region Lookup
-transaction_date -return_date customer_id date product_id store_id region_id
-stock_date -product_id customer_acct_num month_num product_brand region_id sales_district
-product_id -store_id first_name quarter product_name store_type sales_region
-customer_id -quantity last_name year product_sku store_name
-store_id customer_address weekday_num product_retail_price store_street_address
-quantity etc.. etc… etc… etc…

“Data” Tables “Lookup” Tables

*This data is provided by Microsoft for informational purposes only as an aid to illustrate a concept. These samples are provided “as is” without warranty of any kind. The example companies, organizations, products, domain names,
e-mail addresses, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, person, place, or event is intended or should be inferred.
LET’S DO THIS.
INTRO TO “POWER EXCEL”
THE “POWER EXCEL”
WORKFLOW
These are Excel’s Business Intelligence tools, all of which are available directly in Excel
(provided you have a compatible version); no additional software is required!

RAW DATA POWER QUERY DATA MODEL POWER PIVOT & DAX
Flat files (csv, txt), Excel tables, (aka “Get & Explore and analyze the entire
Create table relationships, add
databases (SQL, Azure), folders, Transform”) calculated columns, define data model, and create
streaming sources, web data, Connect to sources, import hierarchies and perspectives, powerful measures using Data
etc. data, and apply shaping etc. Analysis Expressions (DAX)
and transformation tools
(ETL)
“THE BEST THING TO HAPPEN TO EXCEL IN 20
YEARS”
• Import and analyze MILLIONS of rows of data in Excel
• Access data from virtually anywhere (database tables, flat files, cloud services, folders, etc.)

• Quickly build models to blend and analyze data across sources


• Instantly connect sources and analyze holistic performance across your entire data model

• Create fully automated data shaping and loading procedures


• Connect to databases and watch data flow through your model with the click of a button

• Define calculated measures using Data Analysis Expressions (DAX)


• No more redundant A1-style “grid” formulas; DAX expressions are flexible, powerful and portable

*Quote by Bill Jelen (aka “Mr. Excel”)


#1: IMPORT & ANALYZE MILLIONS OF
ROWS

When was the last time you loaded


25,000,000 rows of data into Excel?
When you connect to data with Power
Query and load it to Excel’s Data Model, the
data is compressed and stored in memory,
NOT in worksheets (no more 1,048,576 row
limit!)
#2: BUILD DATA MODELS TO BLEND
SOURCES

This is an example of a Data Model


in “Diagram View”, which allows you
to create connections between
tables

Instead of manually stitching


tables together with cell formulas,
you create relationships to blend
data based on common fields
#3: AUTOMATE YOUR DATA
PROCESSING

With Power Query, you can


filter, shape and transform
your raw data before
loading it into the data
model

Each step is automatically


recorded and saved with
the query, and applied
whenever the source data is
refreshed – like a macro!
#4: CREATE POWERFUL MEASURES WITH
DAX

Measures are flexible and powerful


calculations defined using Data
Analysis Expressions (DAX)

In this case we’re using a DAX


time intelligence formula to
calculate a 10-day rolling average
WHEN TO USE POWER QUERY & POWER
PIVOT
Use Power Query and Power Pivot when you want to…

Analyze more data than can fit into a worksheet

Create connections to databases or external

sources Blend data across multiple large tables

Automate the process of loading and shaping your data

Unleash the full business intelligence capabilities of Excel


POWER QUERY
MEET POWER QUERY

Power Query (aka “Get & Transform”) allows you to:


• Connect to data across a wide range of sources
• Filter, shape, append and transform raw data for further analysis and modeling
• Create stored procedures to automate your data prep (like a macro!)

The Power Query tools live in the Data tab,


under the “Get & Transform” section (Excel
2016)
TYPES OF DATA
CONNECTIONS

From File From FromAzur From Online Services From Other Sources
Database e
THE QUERY
EDITOR
Quer
y
Editin
g Formula Bar
(this is “M” code)
Tools
Name
your
table!

Dat Applie
a d Steps
Previe
w
THE QUERY
EDITOR
Access the Query Editor by creating a new query and choosing the “Edit” option, or by launching
the Workbook Queries pane (Data > Show Queries) and right-clicking an existing query to edit
QUERY EDITOR
TOOLS
The HOME tab includes general settings and common table transformation
tools

The TRANSFORM tab includes tools to modify existing columns (splitting/grouping, transposing, extracting text, etc.

The ADD COLUMN tools create new columns based on conditional rules, text operations, calculations, dates, etc.
DATA LOADING
OPTIONS

When you load data from Power Query, you have several options:
• Table
• Stores the data in a new or existing worksheet
• Requires relatively small data sets (<1mm rows)

• Connection Only
• Saves the data connection settings and applied steps
• Data does not load to a worksheet

• Add to Data Model


• Compresses and loads data to Excel’s Data Model
• Makes data accessible to Power Pivot for further analysis
BASIC TABLE
TRANSFORMATIONS
Sort values Change data Promote header row
(A-Z, Low-High, types
etc.) (date, $, %, text, etc.)

Duplicates” option to create a new lookup table from scratch

Keep or remove columns


Tip: use the “Remove Other
Columns” option if you
always want a specific set
Keep or remove rows
Tip: use the “Remove
BASIC TABLE
Duplicate, move &
rename columns
TRANSFORMATIONS
o
l
mmon tools

u
T m
i n
p
: h
e
R a
i d
g e
h r
t
- t
c o
l
i a
c c
k c
e
t s
h s
e
c
c o
TEXT-SPECIFIC TOOLS

Extract characters from a text


column using a fixed length,
first or last, or a defined
Split a text column based range
on either a specific delimiter Tip: Select two or more columns to
or a number of characters merge or concatenate fields

HEY THIS IS IMPORTANT!


You can access many of these tools in both
the “Transform” and “Add Column” menus -- Format a text column to upper, lower
the difference is whether you want to add a or proper case, or add a prefix or suffix
new column or modify an existing one Tip: Use “Trim” to eliminate leading & trailing
spaces, or “Clean” to remove non-printable
characters
NUMBER-SPECIFIC TOOLS

Information tools allow


you to define binary flags
(TRUE/FALSE or 1/0) to
Standard Scientific Trigonometry mark each row in a
Statistics functions allow you to column as even, odd,
evaluate basic stats for the Standard, Scientific and Trigonometry tools allow you
positive or negative
selected column (sum, min/max, to apply standard operations (addition, multiplication,
average, count, countdistinct, etc) division, etc.) or more advanced calculations (power,
logarithm, sine, tangent, etc) to each value in a
Note: These tools return a SINGLE value, column
and are commonly used to explore a
table rather than prepare it for loading Note: Unlike the Statistics options, these tools are applied to
each individual row in the table
DATE-SPECIFIC
TOOLS

Date & Time tools are relatively straight-forward, and include the following options:
• Age: Difference between the current time and the date in each row
• Date Only: Removes the time component of a date/time field
• Year/Month/Quarter/Week/Day: Extracts individual components from a date
field (Time-specific options include Hour, Minute, Second, etc.)
• Earliest/Latest: Evaluates the earliest or latest date from a column as a single value
(can only be accessed from the “Transform” menu)

Note: You will almost always want to perform these operations from the “Add Column” menu to
build out new fields, rather than transforming an individual date/time column
CREATING A BASIC CALENDAR
TABLE

Use pre-defined Date options


in the “Add Column” menu to
quickly build out a calendar
table from a list of dates
PRO TIP: CREATING A ROLLING
CALENDAR
1) Create a new, blank query (Data > New Query > From Other Sources > Blank Query)

2) In the formula bar, generate a starting date by entering a “literal” (1/1/2013 shown below):

3) Click the fX icon to add a new custom step, and enter the following formula exactly as shown:

4) Convert the resulting list into a Table (List Tools > To Table) and format the column as a Date

5) Add calculated Date columns (Year, Month, Week, etc.) as necessary using the Add Column tools
ADDING AN INDEX COLUMN

Index Columns contain a list of


sequential values that can be used to
identify each unique row in a table
(typically starting from 0 or 1)

These columns are often used to


create unique IDs that can be used
to form relationships between tables
(more on that later!)
ADDING A CONDITIONAL
COLUMN
Conditional Columns allow you to define new fields based
on logical rules and conditions (IF/THEN statements)

In this case we’re creating a new conditional column


called “Order Size”, which depends on the values in the
“quantity” column, as follows:

• If quantity >5, Order Size = “Large”


• If quantity is from 2-5, Order Size = “Medium”
• If quantity =1, Order Size = “Small”
• Otherwise Order Size = “Other”
GROUPING & AGGREGATING
DATA
Group By allows you to aggregate your data at a different level
(i.e. transform daily data into monthly, roll up transaction-level data by store, etc.)

In this case we’re transforming a daily, transaction-level table into


a summary of “quantity” by “product_id”

Note that we lose any field not specified in the Group By settings
PIVOTING &
UNPIVOTING
“Pivoting” is a fancy way to describe the process of turning distinct row
values into columns (“pivoting”) or turning columns into rows (“unpivoting”)

Imagine that the table is on a hinge; pivoting is like


rotating it from a vertical to a horizontal layout, and
unpivoting is like rotating it from horizontal to vertical

NOTE: Transpose works very similarly, but doesn’t


recognize unique values; instead, the entire table is
transformed so that each row becomes a column and vice
versa
MODIFYING WORKBOOK QUERIES

Click on Show Queries to launch the Workbook


Queries pane

Right-click any individual query to access


common options and tools:
• Edit (launches the Query Editor)
• Delete
• Rename
• Refresh
• Duplicate
• Merge
• Append
MERGING QUERIES

• Merging queries allows you to join tables


based on a common column (like VLOOKUP)

• In this case we’re merging the


FoodMart_Transactions_1997 table with
the Product_Lookup table, which share
a “product_id” column

TIP: Merging adds columns to an existing table

HEY THIS IS IMPORTANT!


Just because you can merge
tables, doesn’t mean you should.
In general, it’s better to keep tables
separate and define relationships
between them (more on that later!)
APPENDING QUERIES

• Appending queries allows you to combine (or


stack) tables that share a common structure
and set of columns

• In this case we’re appending the


FoodMart_Transactions_1998 table to the
FoodMart_Transactions_1997 table, since they
contain the same set of columns and data
types

TIP: Appending adds rows to an existing table

PRO TIP:
Use the “From Folder” query option to automatically append all files from within the same folder
POWER QUERY BEST
PRACTICES
Give your queries clear and intuitive names, before loading the data
• Define names immediately; updating query & table names later can be a
headache, especially if you’ve already referenced them in calculated measures
• Don’t use spaces in table names (otherwise you have surround them with single quotes)

Do as much shaping as possible at the source of the data


• Shaping data at the source (i.e. SQL, Access) minimizes the need for complex procedures
in Power Query, and allows you to create new models without replicating the same
process

When working with large tables, only load the data you need
• Don’t include hourly data when you only need daily, or product-level transactions
POWER QUERY BEST
PRACTICES
when you only care about store-level performance; extra data will only slow you down
DATA MODELING
MEET EXCEL’S DATA
MODEL
The Data Model provides simple and intuitive tools for building
relational databases directly in Excel. With the data model you can:
• Manage massive datasets that can’t fit into worksheets
• Create table relationships to blend data across multiple sources
• Define custom hierarchies and perspectives

Access the Data Model through the


Power Pivot tab or the Data tab
(Note: you may need to enable the Power Pivot tab via
File > Options > Add-Ins > Manage COM Add-Ins)
THE DATA MODEL
WINDOW
The Data Model opens in a separate Excel window, where you can view
your data tables, calculate new measures, and define table relationships
Note: Closing the Data Model window does NOT close your Excel workbook
DATA VIEW VS. DIAGRAM
VIEW
DATA VIEW DIAGRAM VIEW

Tables organized in tabs Tables organized as


DATABASE
NORMALIZATION
Normalization is the process of organizing the tables and columns in a relational database to reduce
redundancy and preserve data integrity. It is commonly used to:
• Eliminate redundant data to decrease table sizes and improve processing speed & efficiency
• Minimize errors and anomalies from data modifications (inserting, updating or deleting records)
• Simplify queries and structure the database for meaningful analysis

In a normalized database, each table should serve a distinct and specific purpose (i.e. product information, calendar
fields, transaction records, customer attributes, etc.)

When you don’t normalize, you end up with tables like


this; all of the duplicate product records could be
eliminated with a lookup table based on product_id

This may not seem critical now, but minor inefficiencies


can become major problems as databases scale in size
DATA TABLES VS. LOOKUP
TABLES
Models generally contain two types of tables: data (or “fact”) tables, and lookup (or “dimension”) tables
• Data tables contain numbers or values, typically at the most granular level possible, with ID or “key”
columns that can be used to connect to each lookup table
• Lookup tables provide descriptive, often text-based attributes about each dimension in a table

This Calendar Lookup table provides additional attributes about each date (month, year, weekday, quarter,
etc.)

This Product Lookup table provides additional attributes about each product (brand, product name, sku, price,
etc.)
This Data Table contains “quantity” values, and connects
to lookup tables via the “date” and “product_id” columns
PRIMARY & FOREIGN
KEYS

These columns are foreign keys; tables


they contain multiple instances of
each value, and are used to match
the primary keys in related lookup
PRIMARY & FOREIGN
These columns are KEYS
primary keys; they
uniquely identify each
row of a table, and
match the foreign keys
in related data tables
RELATIONSHIPS VS. MERGED
TABLES
Can’t I just merge queries or use LOOKUP or RELATED functions to pull those
attributes into the fact table itself, so that I have everything in one place??
-Anonymous confused man

Original Fact Table fields Attributes from Calendar Lookup table Attributes from Product Lookup table

Sure, but it’s extremely inefficient.


• Merging data in this way creates redundant data and utilizes significantly more memory
and processing power than creating relationships between multiple small tables
CREATING TABLE
RELATIONSHIPS
Option 1: Click and drag relationships in Diagram View Option 2: Use “Create Relationship” in the Design tab

Tip: Always drag relationships from the Data table to the Lookup tables

*Note: In Excel 2010/2013 the diagram view looks a bit different, and arrows point in the opposite direction by default
CONNECTING LOOKUPS TO
LOOKUPS
PRO
TIP:
Models with multiple related lookup
tables are called “snowflake” schemas
Models with a single table for each

This Transactions data table can connect to Store_Lookup using store_id,


but does not contain a region_id to connect to the Region_Lookup table

By creating a relationship between Store_Lookup and Region_Lookup


(using region_id), we have essentially connected Transactions with
Region_Lookup; filter context will now flow all the way down the chain
MODIFYING TABLE
RELATIONSHIPS

The Manage Relationships


window allows you to create, edit
or delete any connection in the
data model
• Use this to see all table
relationships, as well as
table names, cardinality and
filter direction
• Note: double-click a single
connection in diagram view
MODIFYING TABLE
to edit an individual RELATIONSHIPS
relationship
ACTIVE VS. INACTIVE
RELATIONSHIPS

We can connect the Calendar_Lookup and FoodMart_Transactions tables on both


transaction_date and stock_date; however, only one can be active at a time

To make a connection active or inactive, double-click the connection and check the box, or
right-click the relationship line itself (Note: must deactivate one before activating
ACTIVE VS. INACTIVE
RELATIONSHIPS
another!)
RELATIONSHIP
CARDINALITY
Cardinality refers to the uniqueness of values in a column
In Power Pivot, all relationships in a data model should
follow a “one-to-many” cardinality
• Each column (or “key”) used to join tables can only have one
instance of each unique value in the lookup table (these are
the primary keys), but may have many instances of each
unique value in the data table (these are the foreign keys)

In this case we’re joining the Calendar_Lookup table to the FoodMart_Transactions data table
using the date column as our key

There is only one instance of each date in the lookup table (noted by the “1”), but many instances of
each date in the data table (noted by the asterisk “*”), since multiple transactions occur each day

*Note: In Excel 2010/2013 the diagram view looks a bit different, and arrows point in the opposite direction by default
BAD CARDINALITY: MANY-TO-
MANY

• If we try to connect these tables using the product_id field, we’ll have a many-to-many
relationship since there are multiple instances of each ID in both tables
• Even if we could create this relationship in Power Pivot, how would you know which product
was actually sold on each date – Cream Soda or Diet Cream Soda?
BAD CARDINALITY: ONE-TO-
ONE

• In this case, connecting the tables above using the product_id field creates a one-to-one
relationship, since each ID only appears once in each table
• Unlike many-to-many, there is nothing illegal about this relationship; it’s just inefficient

To eliminate the inefficiency, you could simply


merge the two tables into a single, valid lookup

Note: this still respects the laws of normalization, since


all rows are unique and directly related to the primary
key
CONNECTING MULTIPLE DATA
TABLES
Here we’ve loaded a second data table
named Returns, containing records of
returns by date, product and store
• This table connects to each lookup
exactly like the Transactions table did,
except that there is no way to connect
the Returns table to
Customer_Lookup
• This allows us to analyze data across
both tables in the same pivot, as long as
we only filter or segment the data
using lookups that are common to both
• In other words, we know which
product was returned, which store it
HEY THIS IS IMPORTANT! was returned to, and which date the
NEVER try to connect data tables directly to each other; return occurred, but NOT which
ALWAYS connect them indirectly via shared lookup tables! customer was responsible
FILTER DIRECTION IS
IMPORTANT
This model includes two data tables (Transactions and Returns),
both connected to the Calendar_Lookup
Note the filter directions (shown as arrows) in each relationship;
in Power Pivot (2016) these will always point from the “one”
side of the relationship (lookups) to the “many” side (data
tables)*
• Filtering a table will impact any tables “downstream” of it, as
defined by the filter relationship (i.e the direction of the arrow)
• Let’s say we’re analyzing both Transactions and Returns in the
same PivotTable; filtering by the Calendar_Lookup date field
will return correctly filtered data from both data tables, but
PRO TIP: filtering by the Transactions date field will yield unfiltered
Arrange your lookup tables above your Returns values
data tables in diagram view to remind
you that filters always flow “downstream”
FILTER DIRECTION IS
IMPORTANT
*Note: In Excel 2010/2013 the diagram view looks a bit different, and arrows point in the opposite direction by default
FILTER DIRECTION IS IMPORTANT
(CONT.)

Calendar_Lookup filters flow Filtering by date in the


“down” to both the Transactions Transactions table yields incorrect,
and Returns tables, so we can unfiltered values from the Returns
filter or segment those metrics table, since filter context cannot
using any field from the Calendar flow “upstream” to the Calendar
table table
HIDING FIELDS FROM CLIENT TOOLS

When you hide a field from Client Tools,


you make it invisible to tools outside of
the data model (i.e. Power Pivot)
This can be used to prevent users from
filtering or segmenting on invalid
fields, or to hide irrelevant metrics
from view

PRO TIP:
Always hide the foreign key columns in your data tables to prevent users from accidentally filtering on them!
DEFINING HIERARCHIES

Hierarchies are groups of nested columns that reflect multiple levels of granularity
• For example, a “Geography” hierarchy might include Country, State, and City columns
• Each hierarchy is treated as a single item in PivotTables and PivotCharts, allowing users to “drill
up” and “drill down” through different levels of the hierarchy in a meaningful way

Drag fields to create a


hierarchy
Right-click a field to see the hierarchy options
Hierarchies appear in Power Pivot
DATA MODEL BEST
PRACTICES

Normalize your data model before you do anything else


• Make sure that each table in your model serves a single, distinct purpose
• Use relationships vs. merged tables; long & narrow tables are better than short & wide

Organize lookup tables above data tables in the diagram view


• This serves as a visual reminder that filters always flow “downstream”

Hide fields from client tools to prevent invalid filter context


• All foreign key columns should be hidden from data tables, so that users are only able
to use valid fields for filtering and segmentation
POWER PIVOT & DAX
MEET POWER
PIVOT
A “Power” Pivot is just like a normal PivotTable, except it sits on top of an
entire data model rather than a single table or range. This allows you to:
• Explore massive datasets consisting of multiple sources and tables,
using familiar, user-friendly PivotTable tools and options
• Create powerful and flexible calculations using Data Analysis Expressions (DAX)

The Power Pivot tab


includes tools to manage the
data model and define new
measures

(Note: you may need to enable this tab by selecting


File > Options > Add-Ins > Manage COM Add-Ins)
CREATING A “POWER” PIVOT
TABLE
Option #1: From the Data Model Option #2: From the Insert > PivotTable dialog box
“NORMAL” PIVOTS VS. “POWER”
PIVOTS

NORMAL PIVOT POWER PIVOT


• Can analyze data from one table at a • Can analyze an entire data model, consisting
time; multiple tables must be flattened or of multiple tables connected via
“stitched” together with cell functions relationships rather than cell functions

• Restricted to the data capacity of a • Virtually unlimited data capacity as tables


single Excel worksheet (1,048,576 rows) are compressed outside of normal
worksheets
• Limited to relatively basic calculated
fields, using a sub-set of Excel functions • Performs complex calculations using
Data Analysis Expressions (DAX)
“NORMAL” PIVOTS VS. “POWER”
NOTE: It’sPIVOTS
not the PivotTable itself that’s different; it’s the data behind it
“NORMAL” PIVOTS VS. “POWER”
PIVOTS
Normal Pivot Power Pivot

More
Tables!
NO MORE “CALCULATED
FIELDS”
Oh rats, where are my calculated fields??

One of the key Power Pivot features is the


ability to create much more robust calculated
fields, known as measures*
Because these measures interact directly with
the data model (including tables stored in
memory), traditional cell formulas won’t do the
trick
• Instead, we’ll use a new (but familiar) formula
language called Data Analysis Expressions
(DAX)
NO MORE “CALCULATED
FIELDS”
*Note: Depending on the version of Excel you’re using, you might see these referred to as either “Measures” (Excel 2010, 2016) or “Calculated Fields” (Excel 2013)
DATA ANALYSIS EXPRESSIONS
(DAX)
Data Analysis Expressions, commonly known as DAX, is the formula
language that drives Power Pivot. With DAX, you can:
• Add calculated columns and measures to your model, using intuitive syntax
• Go beyond the capabilities of traditional “grid-style” formulas, with
powerful functions built specifically to work with relational data

Two places to use DAX:

2) Adding Measures

1) Adding Calculated Columns


CALCULATED
COLUMNS
PRO TIP:
Calculated columns are typically placed in the Filters, Slicers, Rows or Columns areas of a pivot

Calculated columns allow you to add new, formula-based columns to tables


• No “A1-style” references; calculated columns refer to HEY THIS IS IMPORTANT!
entire tables or columns As a rule of thumb, ONLY use
calculated columns if you want to
• Calculated columns are computed at the row-level, and “stamp” static, fixed values to each
values are stored with the table (this eats up memory) row in a table (or use Power Query!)
DO NOT use calculated columns for
• Calculated columns understand row context; they’re great aggregation formulas, or to
for defining new properties based on information in each calculate fields for the “Values” area
row, but generally useless for aggregation (SUM, of a pivot (use measures instead)
AVERAGE, COUNT, etc.)
CREATING CALCULATED
COLUMNS

Step 1: In the data model “Data View”,


choose a table and then select any cell in
the “Add Column” section

Step 2: Enter a DAX function in


the formula bar (we’ll cover specific
functions in the next section)

Step 3: Press “Enter”, and all


cells in the column will update
CALCULATED COLUMNS: GOOD &
BAD
In this case we’ve added a calculated column called
price_category, which equals “High” if the retail price is >$2,
and “Low” otherwise (just like you would write in Excel!)
• Since calculated columns understand row context, a
new value is calculated in each row based on that row’s
price
• This is a valid use of calculated columns; it creates a new
row “property” that we can now use to filter or segment any
related data within the model

Here we’re using an aggregation function (SUM) to


calculate a new column named total_revenue
• Since calculated columns do not understand
filter context, the same grand total is returned in
every single row of the table
• This is not a valid use of calculated columns;
these values are statically “stamped” onto the
table and can’t be filtered, sliced, subdivided,
CALCULATED COLUMNS: GOOD &
etc.
BAD
DAX
MEASURES
Measures are DAX formulas used to generate dynamic values within a PivotTable
• Like calculated columns, measures reference entire tables
or columns (no A1-style or “grid” references) HEY THIS IS IMPORTANT!
As a rule of thumb, use measures
• Unlike calculated columns, measures don’t actually live in (vs. calculated columns) when a
the table; they get placed in the values area of a single row can’t give you the
PivotTable and dynamically calculated in each individual answer (i.e. requires
cell aggregation)
Measures can ONLY be placed
• Measures are evaluated based on the filter context of in the values area of a
each cell, which is determined by the PivotTable layout
(filters, slicers, rows and columns)

PRO TIP:
Use measures to create values that users can explore with a pivot (Power Pivot version of a “Calculated Field”)
CREATING IMPLICIT
MEASURES
STEP 1: Check the box next to a value field in a data
table, or manually drag it into the “Values” box

STEP 2: Pat yourself on the back, you just created a measure!

HEY THIS IS IMPORTANT!


Before you pop the champagne, there’s a catch. When you drag a raw data
field into the values section of a pivot, you create what’s called an implicit
measure. While there’s nothing wrong with implicit measures, they are
extremely limited.
Explicit measures (defined using DAX) will give us much more flexibility, as
well as the ability to reuse measures in multiple places (measure trees!)

FROM NOW ON, JUST SAY “NO” TO IMPLICIT MEASURES


CREATING EXPLICIT MEASURES
(AUTOSUM)
AutoSum is a shortcut for creating
simple DAX formulas (Sum,
Average, Count, Distinct Count,
Max and Min)
To use AutoSum:
• Click on a cell in the Measures
Pane (see below), within the
column you want to evaluate
• Select the AutoSum menu
and choose an option from
the list

The Measures Pane sits beneath the


data in the “Data View” of the model

PRO TIP:
AutoSum is a nice way to get comfortable with basic DAX and quickly add measures;
just don’t rely on them when things start to get more complicated!
CREATING EXPLICIT MEASURES (POWER
PIVOT)

The Measure Dialog Box

Each measure is
The Formula assigned to a table and
pane contains the given a measure name
actual DAX code, as (as well as an optional
well as options to description)
browse the formula
library or check syntax

Note: just start typing,


and “Intellisense” will kick
in to help you auto- Use the Formatting
populate formula names
Options to specify a
and tables
format for each
measure
PRO TIP:
Ctrl+scroll
adjusts formula
text size
UNDERSTANDING FILTER
CONTEXT
Measures are calculated based on filter context, which is the set of filters (or “coordinates”)
determined by the PivotTable layout (filters, slicers, row labels and column labels)

HEY THIS IS IMPORTANT!


Each measure cell in the pivot calculates independently, based on its coordinates (think of each cell as an island)
When you change the pivot layout (by updating filters/slicers, row labels or column labels), each measure cell
detects its new coordinates and then recalculates its value

The coordinate for this measure cell is Customer_Lookup[customer_city] = “Hidalgo”


• Given this coordinate, Excel filters down to the “Hidalgo” rows in the Customer_Lookup table, filters all
related tables (based on the relationships in data model), then evaluates the arithmetic in the table defined
by the measure (in this case Total Quantity equals the sum of quantity from the transactions data table)

This cell does NOT add up the values above it (it’s an island, remember?)
• Total rows represent a lack of filters; since this cell does not have a customer_city coordinate,
it evaluates the Total Quantity measure across the entire, unfiltered Customer_Lookup table
FILTER CONTEXT
EXAMPLES

Cell coordinates:
• Calendar_Lookup[Year] = 1997
• Customer_Lookup[customer_country] = “USA”
• Customer_Lookup[customer_city] = “Altadena”

Cell coordinates: Cell coordinates:


• Calendar_Lookup[Year] = 1997 • Store_Lookup[store_country] = “Canada”
• Customer_Lookup[customer_country] = “USA” • Store_Lookup[store_city] = “Vancouver”
• Product_Lookup[product_brand] = “Akron”

Cell coordinates:
• Calendar_Lookup[Year] = 1998 Cell coordinates:
• Calendar_Lookup[Quarter] = 1 • Store_Lookup[store_country] = “Canada”
• Customer_Lookup[customer_country] = “USA” • Product_Lookup[product_brand] = “Amigo”

Cell coordinates:
• Customer_Lookup[customer_country] = “USA”
STEP-BY-STEP MEASURE
CALCULATION
How exactly is this measure calculated?
• REMEMBER: This all happens instantly behind the scenes, every time a measure cell calculates

STEP 1 STEP 2 STEP 3


Detect pivot Carry filters “downstream” Evaluate the measure
coordinates & formula
& apply filter context apply to all related tables against the filtered table

Store_Lookup Table USA

Store_Lookup[store_country] = “USA” 1 1
FoodMart_Transactions
Store_Lookup Table USA *
* USA
FoodMart Returns

USA Sum of
Transactions[quantity] = 555,899
when store_country =
“USA”
STEP-BY-STEP MEASURE
CALCULATION
RECAP: CALCULATED COLUMNS VS.
MEASURES
CALCULATED COLUMNS MEASURES
• Evaluated in the context of each row of the table • Evaluated in the context of each cell of the
to which it belongs (has row context) PivotTable in which it is displayed (has filter context)
• Appends static values to each row in a table • Does not create new data in the tables
and stores them in the model, increasing file themselves, and does not increase file size
size
• Recalculated in response to any change in
• Only recalculated on data source refresh or the PivotTable view
changes to component columns
• Can only be used as PivotTable values
• Primarily used as rows, columns, slicers or filters

Calculated columns “live” in tables Measures “live” in PivotTables


*

*Note: Calculated columns CAN be placed in the values area of a pivot, but you can (and should) use a measure instead
POWER PIVOT BEST
PRACTICES
Avoid using implicit measures whenever possible
• Implicit measures are limited in functionality and restricted to the pivot in
which they were created; explicit measures are more portable and powerful

Don’t use a calculated column when a measure will do the trick


• Only use calculated columns to “stamp” static, fixed values to each row in a table
• Use measures when aggregation is necessary, or to create dynamic values in a pivot

Know your data model inside and out!


• It’s easy to produce incorrect results in Power Pivot if you don’t respect the
model’s table relationships, and errors are often difficult to spot without a
POWER PIVOT BEST
thorough QA PRACTICES
COMMON DAX FUNCTIONS
DAX
SYNTAX
MEASURE NAME
• Note: Measures are always surrounded
Referenced Referenced
in brackets (i.e. [Total Quantity]) when TABLE COLUMN NAME
referenced in formulas, so spaces are NAME
OK

Total Quantity: =SUM(Transactions[quantity])

FUNCTION NAME to evaluate that as a single value in a pivot (you need some sort of
aggregation)
• Calculated columns don’t always use functions,
but measures do:
• In a calculated column,
=Transactions[quantity] returns the value from
the quantity column in each row (since it
evaluates for each row)

• In a measure, =Transactions[quantity] will


return an error since Excel doesn’t know how
DAX
This is a “fully qualified” column, since it’s preceeded by
the table name
SYNTAX
Note: Table names with spaces must be surrounded by
single quotes:
• Without a space: Transactions[quantity]
• With a space: ‘Transactions Table’[quantity]

PRO TIP:
For column references, use the fully qualified name (i.e. Table[Column])
For measure references, just use the measure name (i.e. [Measure])
DAX
OPERATORS
Arithmetic Comparison
Meaning Example Meaning Example
Operator Operator

+ Addition 2+7 = Equal to [City]=“Boston”

- Subtraction 5–3 > Greater than [Quantity]>10

* Multiplication 2*6 < Less than [Quantity]<10

/ Division 4/2 >= Greater than or equal to [Unit_Price]>=2.5

^ Exponent 2^5 <= Less than or equal to [Unit_Price]<=2.5

<> Not equal to [Country]<>”Mexico”


Hey! Pay attention to these!

Text/Logical Operator Meaning Example

& Concatenates two values to produce one text string [City] & “ “ & [State]

&& Create an AND condition between two logical expressions ([State]=“MA”) && ([Quantity]>10)

|| (double pipe) Create an OR condition between two logical expressions ([State]=“MA”) || ([State]=“CT”)

IN Creates a logical OR condition based on a given list (using curly ‘Store Lookup’[State] IN { “MA”, “CT”, “NY”
brackets) }

*Head to www.msdn.microsoft.com for more information about DAX syntax, operators, troubleshooting, etc.
COMMON FUNCTION
CATEGORIES
MATH & LOGICAL TEXT FILTER DATE & TIME
STATS Functions Functions Functions Functions
Functions
Basic aggregation Functions for returning Functions to Lookup functions based Basic date and time
functions as well as information about manipulate text strings on related tables and functions as well as
“iterators” evaluated values in a given or control formats for filtering functions for advanced time
at the row-level conditional expression dates, times or dynamic calculations intelligence
numbers operations
Common Examples: Common Examples: Common Examples: Common Examples: Common Examples:
• SUM • IF • CONCATENATE • CALCULATE • DATEDIFF
• AVERAGE • IFERROR • FORMAT • FILTER • YEARFRAC
• MAX/MIN • AND • LEFT/MID/RIGHT • ALL • YEAR/MONTH/DAY
• DIVIDE • OR • UPPER/LOWER • ALLEXCEPT • HOUR/MINUTE/SECOND
• COUNT/COUNTA • NOT • PROPER • RELATED • TODAY/NOW
• COUNTROWS • SWITCH • LEN • RELATEDTABLE • WEEKDAY/WEEKNUM
• DISTINCTCOUNT • TRUE • SEARCH/FIND • DISTINCT
• FALSE • REPLACE • VALUES Time Intelligence Functions:
Iterator Functions: • REPT • EARLIER/EARLIEST • DATESYTD
• SUMX • SUBSTITUTE • HASONEVALUE • DATESQTD
• AVERAGEX • TRIM • HASONEFILTER • DATESMTD
• MAXX/MINX • UNICHAR • ISFILTERED • DATEADD
• RANKX • USERELATIONSHIP • DATESINPERIOD
• COUNTX

*Note: This is NOT a comprehensive list (does not include trigonometry functions, parent/child functions, information functions, or other less common functions)
BASIC MATH & STATS
FUNCTIONS
SUM() Evaluates the sum of a column =SUM(<column>)

Returns the average (arithmetic


AVERAGE() mean) of all the numbers in a
=AVERAGE(<column>)
column

Returns the largest value in a


MAX() column or between two scalar
=MAX(<column>) or =MAX(<exp1>, <exp2>)
expressions

Returns the smallest value in a


MIN() column or between two scalar
=MIN(<column>) or =MIN(<exp1>, <exp2>)
expressions

Performs division and returns


DIVIDE() the alternate result (or blank) if
=DIVIDE(<numerator>, <denominator>, <other>)
div/0
BASIC MATH & STATS FUNCTIONS
(EXAMPLES)
Sum of quantity from the Transactions table Average of product_retail_price Quantity Returned divided by Total Quantity

PRO TIP:
Even though it might seem unnecessary, creating measures for even simple calculations (like the sum of a column)
allows you to use those measures within other calculations, anywhere in the workbook
COUNT, COUNTA, DISTINCTCOUNT &
COUNTROWS
Counts the number of rows in the
COUNTROWS() specified table, or a table defined by an =COUNTROWS(<table>)
expression

Counts the number of cells in a column


COUNT() that contain numbers =COUNT(<column>)

Counts the number of non-empty cells in


COUNTA() a column (numerical and non- =COUNTA(<column>)
numerical)

Counts the number of different cells in


DISTINCTCOUNT() a column of numbers =DISTINCTCOUNT(<column>)
COUNT FUNCTIONS (EXAMPLES)

Count of all rows in the Transactions table Count of non-empty cells in the recyclable
column

Count of unique values in the product_id column


BASIC LOGICAL FUNCTIONS
(IF/AND/OR)
Checks if a given condition is met, and
IF() returns one value if the condition is =IF(<logical test>, <value_if_true>, <value_if_false>)
TRUE, and another if the condition is
FALSE

Evaluates an expression and returns a


IFERROR() specified value if the expression returns an =IFERROR(value, value_if_error)
error, otherwise returns the expression
itself

Checks whether both arguments are


AND() TRUE, and returns TRUE if both arguments =AND(<logical1>,
are TRUE, otherwise returns FALSE Note: Use the && and
<logical2>) || operators if you
want to include
more than two
conditions!
Checks whether one of the arguments is
OR() TRUE to return TRUE, and returns FALSE =OR (<logical1>, <logical2>)
if both arguments are FALSE
BASIC LOGICAL FUNCTIONS (EXAMPLES)
Education level equals “Grad” if customer has a bachelors degree or a graduate degree, otherwise “Non-Grad”

Supermarket_size equals “Large” if sq ft >30,000, otherwise “Small”


SWITCH &
SWITCH(TRUE)
SWITCH() Evaluates an expression against a list of values and returns one of multiple possible result expressions

=SWITCH(<expression>, <value1>, <result1>, <value2>, <result2>, … <else>)

Any DAX expression that returns a List of values produced by the expression, each Price”
single scalar value, evaluated paired with a result to return for rows/cases that “Premium
multiple times (for each match Price”)
row/constant) Examples:
Examples:
• Calendar_Lookup[month_num]
=SWITCH(Calendar_Lookup[month_num],
• Product_Lookup[product_brand] 1, “January”,
2,
“February”,
etc…
PRO TIP:
Use the SWITCH(TRUE() combo to =SWITCH(TRUE(),
generate results based on Boolean [retail_price]<5, “Low Price”,
(True/False) expressions (instead
AND([retail_price>=5, [retail_price]<20), “Med Price”,
of those pesky nested IF
statements!) AND([retail_price>=20, [retail_price]<50), “High
SWITCH &
Value returned if the expression
doesn’t match any value argument
SWITCH(TRUE)
SWITCH & SWITCH(TRUE)
(EXAMPLES)
Switch quarter 1 with “Q1”, quarter 2 with “Q2”, quarter 3 = “Q3”, else “Q4”

Set product_price_category to “High” if retail price > $3, “Medium”


if price is between $2 and $3, “Low” if price is <=$2, else “Other”
TEXT FUNCTIONS

LEN() Returns the number of characters in a string


=LEN(<text>) Note: Use the & operator as a
shortcut, or to combine more than two
strings!

CONCATENATE() Joins two text strings into one =CONCATENATE(<text1>, <text2>)

LEFT/MID/ Returns a number of characters from the =LEFT/RIGHT(<text>, <num_chars>)


RIGHT() start/middle/end of a text string
=MID(<text>, <start_num>, <num_chars>)

UPPER/LOWER/ Converts letters in a string


PROPER() to upper/lower/proper =UPPER/LOWER/PROPER(<text>)
case

Replaces an instance of existing text with =SUBSTITUTE(<text>, <old_text>,


SUBSTITUTE() new text in a string
<new_text>, <instance>)

Returns the position where a specified string =SEARCH(<find_text>, <within_text>,


SEARCH() or character is found, reading left to right
<start_num>, <NotFoundValue>)
TEXT FUNCTIONS (EXAMPLES)
Extract the left 3 characters from each value in the store_country column

Concatenate the values from the year and month columns

Extract characters from the left of the customer_address column, up to the space
CALCULATE

CALCULATE() Evaluates a given expression or formula under a set of defined filters

=CALCULATE(<expression>, <filter1>, <filter2>,…)

Name of an existing measure or


List of simple Boolean (True/False) filter expressions
a formula for a valid measure
(note: these require simple, fixed values; you
Examples: cannot create filters based on measures)
• [Total Transactions]
• SUM(Transactions[quantity]) Examples:
• Store_Lookup[store_country]=“USA”
• Calendar[Year]=1998
• Transactions[quantity]>=5

PRO TIP:
CALCULATE works just like SUMIF or COUNTIF, except it can evaluate measures based on ANY sort of
calculation (not just a sum, count, etc); it may help to think of it like “CALCULATEIF”
CALCULATE
(EXAMPLE)

Why do we see the same repeating value when we add store_country to


rows? Shouldn’t these cells have filter contexts for Canada and Mexico?

HEY THIS IS IMPORTANT!


The CALCULATE function modifies filters and overrules any
competing ones defined by the PivotTable coordinates!
In this example, the MEXICO cell has a filter context of
store_country= “MEXICO” (defined by the row label) AND
In this case we’ve defined a new measure named “USA story_country= “USA” (defined by the CALCULATE function)
Transactions”, which evaluates the “Total Both cannot be true at the same time, so the MEXICO filter
Transactions” measure when the store country equals is overwritten and CALCULATE takes priority
“USA”
CALCULATE CHANGES THE FILTER
CONTEXT
CALCULATE
If the measure being evaluated contains a CALCULATE
Modify filters if
function, filter context is modified between Step 1 & Step 2
measure contains
CALCULATE
Store_Lookup[store_country] = “USA”

STEP 1 STEP 2 STEP 3


Detect pivot Carry the filters Evaluate the formula
coordinates & apply across all table against the filtered
filter context Store_Lookup Table relationships table
USA

Store_Lookup Table

USA
Store_Lookup[store_country] = “MEXICO”

Store_Lookup Table
1 1
MEXICO
* Transactions
*
FoodMart Returns USA Total Transactions
USA where store_country
= “USA”
= 180,823
CALCULATE CHANGES THE FILTER CONTEXT

FILTER() Returns a table that represents a subset of another table or expression

=FILTER(<table>, <filter expression>) HEY THIS IS IMPORTANT!


FILTER is used to add filter context
on top of what’s already defined by
Table to be filtered A Boolean (True/False) filter expression the PivotTable layout.

Examples:
to be evaluated for each row of the table Since FILTER returns a table (as opposed
• Store_Lookup to a scalar), it’s almost always used as
Examples: an input to other functions, like
• Product_Looku • Store_Lookup[store_country]=“USA”
p enabling more complex filtering
• Calendar[Year]=1998 options within a CALCULATE function
• [retail_price]>AVERAGE[retail_price] (or passing a filtered table to an iterator
like SUMX)

PRO TIP:
Since FILTER iterates through each row in a table, it can be slow and processor-intensive; never use FILTER
when a normal CALCULATE function will accomplish the same thing!
PRO TIP: FILTERING WITH DISCONNECTED SLICERS (PART ) 1

STEP 1: Create an Excel table containing a STEP 3: Make sure that your table loaded, and is
list of values to use as thresholds or NOT connected to any other table in the model:
parameters:

STEP 2: Add the table to the Data Model


(from Power Pivot tab):
PRO TIP: FILTERING WITH DISCONNECTED SLICERS (PART ) 2

STEP 4: Place your new table on the pivot as a slicer:

STEP 5: Create a measure to capture the slicer selection,


then reference it in a FILTER statement within CALCULATE:

The Transactions Under Price Threshold measure calculates Total


Transactions when the product price is below the selected threshold
FILTER
(EXAMPLES)

Calculate Total Transactions only for cases where the product price is below a selected threshold Calculate Total Revenue, but only for USA stores
ALL

ALL() Returns all rows in a table, or all values in a column, ignoring any filters that have been applied

=ALL(<table> or <column>, [column1], [column2],…)

The table or column that List of columns that you want to clear filters on (optional)
you want to clear filters on
Notes:
Examples: • If your first parameter is a table, you can’t specify additional columns
• Transactions • All columns must include the table name, and come from the same table
• Product_Lookup[product_brand
Examples:
]
• Customer_Lookup[customer_city], Customer_Lookup[customer_country]
• Product_Lookup[product_name]
ALL
PRO TIP:
ALL is like the opposite of FILTER; instead of adding filter context, ALL removes filter context. This is often used when
you need unfiltered values that won’t be skewed by the PivotTable layout (i.e. Category sales as % of Total)
ALL (EXAMPLE)

• In this example, we use ALL to calculate total transactions across all rows in
the Transactions table, ignoring any filter context from the PivotTable
• By dividing the original [Total Transaction] measure (which responds to PivotTable filter context
as expected) by the new [All Transactions] measure, we can correctly calculate the percentage of
the total no matter how the PivotTable is filtered
RELATED

RELATED() Returns related values in each row of a table using relationships with other tables

=RELATED(<column>)
HEY THIS IS IMPORTANT!
RELATED works almost exactly like a VLOOKUP function – it uses
The column that contains the relationship between tables (defined by primary and foreign
the values you want to keys) to pull values from one table into a new column of
retrieve another.
Since this function requires row context, it can only be used as a
Examples: calculated column or as part of an iterator function that cycles
• Product_Lookup[product_brand] through all rows in a table (FILTER, SUMX, MAXX, etc.)
• Store_Lookup[store_country]

PRO TIP:
Avoid using RELATED to create redundant calculated columns unless you absolutely need them, since those
extra columns increase file size; instead, use RELATED within a measure like FILTER or SUMX
RELATED
(EXAMPLES)
Retrieve the retail price from the Product_Lookup table and append it to the Transactions table

Multiply the quantity in each row of the Transactions table with the
related retail price from the Product_Lookup table, and sum the results
ITERATOR (“X”)
FUNCTIONS
Iterator (or “X”) functions allow you to loop through the same calculation or expression on
each row of a table, and then apply some sort of aggregation to the results (SUM, MAX, etc.)

=SUMX(<table>, <expression>)
Aggregation to Table in which the Expression to be evaluated
apply to calculated expression will be for each row of the given
rows* evaluated table
Examples: Examples: Examples:
• SUMX • Transactions • [Total Transactions]
• COUNTX • FILTER(Transactions, • Transactions[price] * Transactions[quantity]
• AVERAGEX RELATED(Store_Lookup[country])=“USA”)
• RANKX
• MAXX/MINX

PRO TIP:
Imagine the function adding a temporary new column to the table, calculating the value in each row
(based on the expression) and then applying the aggregation to that new column (like SUMPRODUCT)
ITERATOR (“X”)
FUNCTIONS
*In this example we’re looking at SUMX, but all “X” functions follow a similar syntax
ITERATOR (“X”) FUNCTIONS
(EXAMPLES)

Multiply quantity and retail price for each row in the Transactions table, and sum the results Calculate the rank of each product brand, based on total revenue
BASIC DATE & TIME
FUNCTIONS
DAY/MONTH/ Returns the day of the month (1-31), month
=DAY/MONTH/YEAR(<date>)
YEAR() of the year (1-12), or year of a given date

HOUR/MINUTE/ Returns the hour (0-23), minute (0-59), or


second (0-59) of a given datetime value =HOUR/MINUTE/SECOND(<datetime>)
SECOND()

TODAY/NOW() Returns the current date or exact time =TODAY/NOW()

WEEKDAY/ Returns a weekday number from 1 (Sunday)


to 7 (Sunday), or the week # of the year =WEEKDAY/WEEKNUM(<date>, <type>)
WEEKNUM()
Returns the date of the last day of the
EOMONTH() month, +/- a specified number of =EOMONTH(<start_date>, <months>)
months
Returns the difference between two dates,
DATEDIFF() based on a selected interval =DATEDIFF(<start_date>, <end_date>, <interval>)
BASIC DATE & TIME FUNCTIONS
(EXAMPLES)
Calculate the time difference between the customer birthdate and current date, in years

Calculate the end date of the month, for each row in the Calendar_Lookup table
TIME INTELLIGENCE FORMULAS

Time Intelligence functions allow you to easily calculate common time comparisons:

Performance =CALCULATE(<measure>, DATESYTD(Calendar[Date]))


To-Date Use DATESQTD for Quarters or DATESMTD for Months

Previous =CALCULATE(<measure>, DATEADD(Calendar[Date],-1,MONTH))


Period
Select an interval (DAY, MONTH, QUARTER, or YEAR) and the
# of intervals to compare (i.e. previous month, rolling 10-day)
Running =CALCULATE(<measure>,
Total DATESINPERIOD(Calendar[Date], MAX(Calendar[Date]),-10,DAY))

PRO TIP:
To calculate a moving average, use the running total calculation above and divide by the # of intervals!
SPEED & PERFORMANCE
CONSIDERATIONS
Avoid using unnecessary slicers, or consider disabling cross-filtering
• When you use multiple slicers, they “cross-filter” by default; in other words, options in Slicer B
are automatically grayed out if they aren’t relevant given a selected value in Slicer A
• To disable, select Slicer Tools > Slicer Settings and uncheck “Visually indicate items with no data”

Eliminate redundant columns; keep data tables narrow


• Data tables should ideally only contain quantitative values and foreign keys; any extra
descriptive columns should live in a related lookup table

Imported columns are better than calculated columns


• When possible, create calculated columns at the source (i.e. in your raw database) or using
Power Query; this is more efficient than processing those calculations in the Data Model/Power
Pivot

Minimize iterator functions (FILTER, SUMX, etc.)


• Functions that cycle through each row in a table are “expensive”, meaning that they
SPEED & PERFORMANCE
takeCONSIDERATIONS
time and consume processing power
DAX BEST
PRACTICES
Write measures for even the simplest calculations (i.e. Sum of Sales)
• Once you create a measure it can be used anywhere in the workbook and as
an input to other, more complex calculations

Break measures down into simple, component parts


• DAX is a difficult language to master; focus on practicing and understanding
simple components at first, then assemble them into more advanced formulas

Reference columns with the table name, and measures alone


• Using “fully qualified” column references (preceeded by the table name) helps make
formulas more readable and intuitive, and differentiates them from measure
DAX BEST
references PRACTICES
WRAPPING UP
DATA VISUALIZATION
OPTIONS
There are several options for building visuals and reports from a data model:

1 PivotCharts & Conditional Formatting


• Check out my Data Analysis with Excel PivotTables course for a deep dive

Available
within Excel
2 Spreadsheet-based dashboards built with CUBE functions
• Use CUBE functions to pull values from the data model for custom Excel reports (no pivots)

3 Power View, Power Map, etc.


• Excel plug-in with Power Pivot and other BI tools; recommend PowerBI as a better option

Standalone
4 Microsoft PowerBI
product
(desktop + online) • Brand new (free!) self-service BI product for loading, shaping, modeling, and visualizing
data
SNEAK PEEK: POWERBI

PowerBI is a standalone Microsoft business intelligence


product, which includes both desktop and web-based
applications for loading, modeling, and visualizing data

For info about plans & pricing: powerbi.microsoft.com


“POWER EXCEL” VS.
POWERBI
“POWER EXCEL” POWERBI
“Power Excel” and
PowerBI are built on top
PivotTables Drag & Drop
Reports of the exact same
Data Shaping & Dashboards engine!
(Power Query)
PivotCharts
PowerBI takes the same
Data Modeling data shaping, modeling
Custom Visuals
(Power Pivot) (cards, maps, R, and analytics capabilities
etc.) and adds new reporting
Power Map/ Calculated Measures
Power View (DAX) and visualization tools

Cloud collaboration Transitioning is easy; you


CUBE Functions and publishing tools can import an entire data
model directly from
Excel!
RESOURCES & NEXT
STEPS
Looking to become an absolute Excel ROCK STAR? Try the full stack:
• Microsoft Excel – Data Analysis with Excel PivotTables
• Microsoft Excel – Advanced Excel Formulas & Functions
• Microsoft Excel – Data Viz with Excel Charts & Graphs
• Microsoft PowerBI Essentials (COMING SOON!)

Check out these awesome resources for additional support:


• msdn.microsoft.com for DAX documentation and support
• powerpivotpro.com for blogs, articles, and additional Power Pivot resources
• Power Query & Power BI by Rob Collie (paperback, available on Amazon)

Ratings and reviews mean the world to me, so please share feedback!
• Feel free to post to the Q&A section or message me directly if you need any support, or if
there’s anything I can do to improve your course experience!
THANK YOU!

You might also like