Sie sind auf Seite 1von 134

Copyright Gilly Dow 2016

Table of Contents

Setup & Preparation


Step 1 – Running Totals
Total Sales YEARTODATE
Total Sales FISCAL 31 MARCH
Practice Ex1
DATESMTD()
Total Sales MONTHTODATE
DATESQTD()
Total Sales QUARTERTODATE
Total Sales FISCAL 30 June
Step 2 – Date Intervals
Total Sales PREVIOUSYEAR
% Growth YOY
Total Sales DATEADD -1 YEAR
Practice Ex2
Total Sales PREVIOUSMONTH
% Growth MoM
Total Sales PREVIOUSDAY
% Growth DoD
Step 2 – More on Intervals
Total Sales PREVIOUSQUARTER
% Growth QoQ
Step 3 – First and Last
Dates FIRSTDATE
Dates LASTDATE
Dates ENDOFMONTH
Dates STARTOFYEAR
Practice Ex3
CLOSINGBALANCEMONTH()
Total Sales CLOSINGBALANCEMONTH
CLOSINGBALANCEQUARTER()
Total Sales CLOSINGBALANCEQUARTER
CLOSINGBALANCEYEAR()
Total Sales CLOSINGBALANCEYEAR
Step 4 Dates Between
Total Sales DATESBETWEEN Last Half 2002
Total Sales RUNNING TOTAL
Total Sales RUNNING TOTAL
Practice Ex4
Total Sales BETWEEN JUL 2001 – JUN 2002
% Monthly Sales Growth (First Year)
Step 5 - FILTER()
No of Customers
No of Customers Earning Over £50000 with FILTER
Customers with 5 or more Orders
Total Order Quantity
Customers with 5 or more Orders FIXED
Customers with Sales Greater than £5,000
Practice Ex5
Total Sales of Products with Sales but Less than £20,000
Count of Products with Sales but Less than £20,000
Custom Calendars - Setup & Preparation
Step 6 – Filter Context and Behind the Scenes
PeriodStart
PeriodEnd
Total Days in Period
Sales per Day in Period
Step 7 – DAX Patterns
Prior Period Sales
Practice Ex7
Sales YOY
Step 8 – Navigation Maths
YTD Sales
Practice Ex8
Step 9 – Suppressing & Fixing Totals
Prior Period Sales Subtotals Suppressed with HASONEVALUE
Sales YOY TOTALS FIXED
Step 10 – % Growth Measures
Sales per Prior Period Growth
Sales per Prior Period Growth %
Sales YOY Growth
Sales YOY Growth %
Conclusion
Solutions
Introduction
This course builds upon the skills learned in the first course in this series
DAX Power Pivot – 10 Easy Steps for Beginners. I’m going to assume you
are up-to-speed with the basics but I highly recommend you check out my
first eBook course first if you haven’t.
You have already gotten your hands dirty with Power Pivot and DAX
functions so you know how awesome it is. Now you are ready to take your
skills to the next level by delving deeper and acquiring a more thorough
understanding of how Power Pivot handles Time data.
Data Analysis Expressions (DAX) includes Time Intelligence functions to
support the needs of Business Intelligence analysis by enabling you to
manipulate data using time periods, including days, months, quarters, and
years, and then build and compare calculations over those periods.
The first part of the course concentrates on DAX time-ready functions ideal
for a standard calendar – the kind you hang on your wall. So, if that’s how
you roll at work – this is perfect for you.
The second half raises the stakes and you will learn how to manipulate DAX
to generate your own custom functions to work with 4-4-5 custom calendars
used in many different industries including retail.
In order to do this, I’ll introduce you to some new DAX functions that will
elevate your skills enabling you to build custom DAX functions for those
pesky non-standard calendars.
Even if this doesn’t fit your remit – DO IT ANYWAY! Your level of
understanding will increase leaps and bounds and your confidence will
soarrrrr!!! Plus, it’s GREAT fun and you’ll learn heaps along the way!
What you will learn in this course:
Performing Date Calculations in DAX with a Standard Calendar
Building a standard Calendar table
Running Totals with: Month-to-Date (MTD), Quarter-to-Date (QTD) and
Year-to-Date (YTD)
Computing the moving annual total for Fiscal Year Ends
Aggregating and Comparing Growth %’s over time
Time intelligence with CALCULATE()
Computing periods from the Prior Year
Closing Balance, End-of-Month, First Date, Last Date, End of Month and
Start of Year
Computing values Between Dates
Performing Date Calculations in DAX with a 4-4-5 Custom Calendar
Building a custom Calendar table
Working with multiple Calendar tables
Manipulating DAX Patterns
Custom Time intelligence with CALCULATE()
Custom Time intelligence with CALCULATE(), FILTER() and ALL()
Aggregating and Comparing Growth %’s over time
Will it be easy? Yes and no – the first half of the course – the DAX “time-
ready” functions are intuitive and straightforward.
The custom Time Intelligence functions you create can be challenging but if
it were easy where’s the satisfaction in that??
I provide examples that we work through together. Then it’s over to you with
practice exercises for you to help embed and consolidate your skills. I always
provide the solutions – so, you’re never on your own. What’s not to love?
Files to Download
Please visit www.gdteach.co.uk – just click on the DAX Time
Intelligence page to download the files to complete the steps and practice
exercises – scroll to the bottom of the web page to see how to download
them. The AdventureWorks database is included in the download.
I have included an email grabber so that I can send you the files and let
you know about new releases in this series. This information is for my
purposes only and I will never pass on your information to any other party
or supplier – that’s a promise!
If you are a visual learner and would prefer to view as I complete the steps
and practice exercises, the accompanying online course is available on
Udemy from late July 2017 and comes with a screenshot packed
supporting pdf user guide!
Head on over to my website and click the link to get a super 67%
discount on the full price.
There’ a no questions asked, 30-day money back guarantee! This gives
you access to ask me questions directly if you’re not sure about something
or if you need help with an exercise or task that’s just not working as you
would expect. Your own personal DAX Power Pivot support gal. The
online course is packed with additional tips and tricks that comes with
viewing rather than reading and there’s quizzes that help you to embed and
consolidate your learning and understanding.
To Connect to the AdventureWorks database on your own pc/laptop:
1. On the Power Pivot ribbon, click the Manage option
2. Select Existing Connections on the Home ribbon in the Power Pivot
Data Model window
3. Click Edit in the Existing Connections window and browse to the
downloaded AdventureWorks database (unzipped and saved locally on
your pc/laptop)
4. Click Save to return to the Existing Connections window, select
Refresh to re-load the tables
Conventions Used in the eBook
I have used the following to represent the “drop-zones” in the Pivot Table
Fields list:

Solutions
You will notice at the end of each Practice Exercise a hyperlink to take you
directly to the solutions. Click on any of the Solutions headings to take you
back to where you were.
So, with no further ado, let’s get going. Welcome the wonders of
DAX Power Pivot Time Intelligence – 10 Easy Steps
SETUP & PREPARATION
To take full advantage of the DAX Time Intelligence functions, you will add
date columns to the existing basic Calendar table and ensure a One-to-Many
relationship exists with the Sales table
1. Open the Sales Report TI workbook
2. Ensure you are connected to the AdventureWorks database, see
instructions in the Introduction
3. On the Calendar sheet select cell F1 add the column label Week No, press
Enter
4. In cell F2, enter the formula =WEEKNUM(
5. Select cell A2

6. The calendar list has been formatted as a table, therefore regular Excel cell
addressing i.e. A2 is not available – just like DAX functions, tables in
Excel operate with table columns

Note: To turn this


off, select File > Options > Formulas > Working with formulas
deselect Use table names in formulas. Cell addressing will display
with subsequent formulas in the table. This feature cannot be turned
off for Power Pivot and DAX functions – only Excel tables.

7. Once this has feature has been turned off, start the formula
again in cell F2

8. Press Enter – the corresponding Week No for the date in column A will
populate the column, see the screenshot below
9. Select cell G1, enter the column header DayNoOfMonth
10. Enter the formula =DAY(A2)

11. Press
Enter – the corresponding DayNoOfMonth for the date in column A will
populate the column, see the screenshot below

12. From the Table Tools contextual tab Design > Properties group
edit the table name from ExcelCalendar to Calendar (this is just a
reminder of how to name a table in Excel)
13. Select PowerPivot tab > Manage, the Calendar table has updated
automatically i.e. the new columns display, however the sheet name has
not
14. Right click the ExcelCalendar sheet – or double-click the sheet
name – rename Calendar (the table name can also be edited in the
Diagram View window by double-clicking the table name)
15. In Diagram View ensure the Calendar table name is correct and a
One-to-Many relationship exists between it and the Sales table
16. Finally, the Calendar table has to marked as a Date Table – ensure
the Calendar table is selected
17. On the Design ribbon in the Diagram View window, select Mark
as Data Table

18. The Mark as Date Table window displays, accept the Date as the
unique field, click Ok
19. That’s it guys – you’re all set to continue with the course!
STEP 1 – RUNNING TOTALS
In this series of DAX functions, you will create running totals for the time
period specified. By using the optional arguments in some of the functions,
Fiscal Year End can be added. All the results can be manipulated with the use
of slicers. The following DAX functions act as a filter argument to
CALCULATE().
Total Sales YEARTODATE
1. From the Power Pivot window, insert a new pivot into a new worksheet

2. Rename the sheet DATEYTD()


3. Setup the pivot:
F
R Calendar - Month
C
V Total Sales
4. The Months are listed alphabetically, sort the Month by Month No in the
Power Pivot window
5. The filter context of the pivot is currently displaying Total Sales for all
months across 2001 – 2004
6. Move the pivot to cell C6 – press Ctrl/Shift * to select the pivot table
7. Add a Calendar – Year slicer, position above the pivot approx. C2:E5
8. Increase the columns on the Slicer to 4 and slice on 2003
9. Ensure the cursor is in the pivot, add a new measure in the Sales table
named Total Sales YEARTODATE
10. The DATESYTD() function displays a “running total” for the
Year sliced
11. To achieve this, the CALCULATE() function is used to calculate
the Total Sales and the DATESYTD() function pulls in the Date field
from the Calendar table
12. Format as Currency to 0 decimal places – (this will be standard
for all measures unless otherwise stated)
Note: The DATESYTD() DAX function has an optional
YearEndDate i.e. 31/3 or 30/6 for Fiscal year end usage (for US
3/31 or 6/30)
Presentation
1. Text Wrap the pivot column headers
2. Centre align both vertically and horizontally
3. Show in Outline Form
4. Ensure Autofit column widths on update is deselected in PivotTable
Options

13. Slice the pivot to see running totals for each year!
With minor adjustments to the pivot table layout, new
insights can be displayed:
1. Copy and Paste the pivot (not the Slicer) to H6
2. Notice when the Year slicer is sliced on the original pivot, the newly
copied pivot is affected too
3. Remove all filtering from the slicer i.e. select the Clear Filter option in the
top right corner of the Slicer

4. Ensure the cursor is in the new pivot, on the PivotTable Tools contextual
tab > Analyze >PivotTable group, note the default name of the pivot table,
i.e. PivotTable5
5. Right click the Slicer, select Report Connections or select the same on
Slicer Tools contextual tab > Options > Slicer group
6. In the Report Connections (Year) window, scroll down to find the sheet
DATEYTD, uncheck the copied pivot table i.e. PivotTable5, click Ok
7. The Year slicer connection is broken between the two pivots – test it out
i.e. slice the original pivot – the copied pivot is unaffected
8. In the copied pivot, remove Total Sales from the Values drop-zone in the
pivot table field list
9. Add Calendar – Year to the Columns drop-zone
10. Adjust the column widths accordingly

11. Right click column


Grand Total, select Remove Grand Total
12. Copy & Paste this pivot to cell O6
13. Notice the Paste Options box when you paste the pivot
14. Select it to choose, Keep Source Columns Widths

15. Add Territories – Country to the Rows drop-zone, above Month


16. Add a Calendar – Year slicer, sliced on 2002 & 2003
17. Select formatting options of your choice from the PivotTable
Tools Contextual Design tab > PivotTable Styles group and Slicer Tools
contextual Options tab > Slicer Styles group
18. On the PivotTable Tools Contextual Design ribbon > Layout
group > Subtotals drop-down choose Show all Subtotals at Bottom of
Group

FISCAL YEAR TO DATE


Total Sales FISCAL 31 MARCH
The DATESYTD() optional argument enables you to customise the calendar
if your year end is not 31 December
1. Insert a new pivot into cell C26
2. Setup the pivot:
F
R Calendar – Month
Calendar – Week No
C
V Total Sales

3. Add a Calendar – Year slicer, sliced on 2002


4. Position the slicer above the pivot approx. C22:E25 – increase the slicer
columns to 4
5. Add a new measure in the Sales table named Total Sales FISCAL 31
MARCH
6. The arguments for this measure are similar to the previous
example,however the optional argument for YearEndDate will be provided

Note: You can include a year i.e. “30/3/2002”. However, the year
will be ignored if you include it – the DATESYTD() function only
looks at the day and month
Presentation
1. Use the Format Painter tool to copy the formatting for column headings
from another pivot
2. Select PivotTable Tools Contextual Design ribbon > Layout group >
Subtotals drop-down > Do Not Show Subtotals
3. Adjust the columns and slicer window as required
4. Apply Conditional Formatting to both Total Sales and Total Sales
FISCAL 31 MARCH to see the end of the Fiscal year approaching in
March

5. Save your work

PRACTICE EX1
DATESMTD()
Total Sales MONTHTODATE
1. In a new worksheet select cell D7
2. Insert a new pivot into this cell, rename the sheet Ex1
3. Setup the pivot:
F
R Calendar - DayNoOfMonth
C
V Total Sales
4. Create a new measure in the Sales table named Total Sales
MONTHTODATE
Hint: This is the same as the DATESYTD function structure – just
substitute DATESMTD() – no optional arguments are available
5. Text Wrap the headings, centre align both horizontally and vertically and
show in Outline Form
6. Ensure the column widths do not autofit on update
7. Add a Calendar – Year slicer, sliced on 2001 – increase columns to 6
8. Add a Calendar – Month slicer, sliced on July

9. AdventureWorks first month’s global daily sales AND the running total–
brilliant!
DATESQTD()
Total Sales QUARTERTODATE
1. In a new pivot into cell K7
2. Setup the pivot:
F
R Calendar - Month
C
V Total Sales
3. Create a new measure in the Sales table named Total Sales
QUARTERTODATE
4. Apply all the presentation formats as above, Outline Form, Text Wrap
etc….
5. Add a Calendar – Year slicer, sliced on 2003
6. Add a Calendar – Month slicer, not sliced
7. Apply Conditional Formatting to Total Sales QUARTERTODATE

8. Notice I have applied Bold to highlight the running totals of the previous 3
months (Qtrs) in the Total Sales QUARTERTODATE column
Recap - The Grand Total row can be a bit confusing. Remember, it
represents the absence of one or more filters – it’s an area where one
or more of the pivot fields does not apply. Therefore, the current filter
context for cell M20 is the last qtr in the year 2003 – it has no way of
summing all the qtrs. The Grand Total for the Total Sales is different –
its measure is uses the SUM function, therefore, its filter context is sum
total sales for year 2003
Presentation
1. Insert a new pivot into cell Q7
Note: Don’t copy and paste this time as this can cause confusion
when slicing with multiple slicers, try it by all means but it’s
probably easier and quicker to start with a new pivot!
2. Set up the new pivot:
F
R Calendar - Month
C
V Total Sales QUARTERTODATE
Total Sales YEARTODATE

3. Apply all the presentation formats as above, Outline Form, Text Wrap
etc….
4. Add a Calendar – Year slicer, sliced on 2003
5. Add a Calendar – Month slicer
6. Experiment by slicing January – March or holding the Multi-Select key
and selecting March, June, September and December

Note: You may be wondering why you are creating so many new
pivots when you could just swap out measures and slice accordingly?
Well, my thinking is that you can go back and compare what your
pivot was like in the beginning and how it can be presented
differently. However, it’s up to you how you like to work – it’s just
for training purposes really

WORKING WITH FISCAL YEAR TO DATE


Total Sales FISCAL 30 June
1. Insert a new pivot into cell U7
2. Setup the pivot:
F
R Calendar – Month
C
V Total Sales
3. Create a new measure in the Sales table named Total Sales FISCAL 30
JUNE
4. Remove Subtotals and apply Text Wrap etc…
5. Add a Calendar – Year slicer, sliced on 2002
6. Apply Conditional Formatting to see the year end approaching June

7. Save your work


Solution Ex1
STEP 2 – DATE INTERVALS
The following series of Time Intelligence functions don’t require
explanations, their purpose is described in their naming conventions.
However, you can start to “build” your own time intelligence measures with
these as the basis to gain some further, very useful, insights and projections.
Intrigued…?
PREVIOUSYEAR()
Total Sales PREVIOUSYEAR
1. On a new worksheet, select cell D6
2. Insert a new pivot, rename the sheet INTERVALS
3. Setup the pivot:
F
R Calendar - Year
C
V Total Sales
4. Create a new measure in the Sales table named Total Sales
PREVIOUSYEAR
5. As you complete the measure and add the PREVIOUSYEAR function
notice the other options in this series of Time Intelligence functions

6. The “PREVIOUS…()” family of DAX functions are filter arguments to


CALCULATE() and just require the DATE field in the CALENDAR
table
7. The resulting pivot table should be
fairly instinctive
NOTE: It’s a brave and committed person who remembers all of the
DAX functions – after a while, you’ll get a hunch that a function
exists because you’ll be using others in the same “family” and it will
just feel right that what you’re looking for or needing will be there.
Trust me on this – as your experience and confidence grows, you’ll
knowledge of the functions available will come together
% Growth YOY
By utilising 2 base measures, to create a third measure, you can provide
Year-on-Year (or Year-over-Year if you prefer), % growth
1. Create a new measure in the Sales table named % Growth YOY
2. Format as a % to 1 decimal place – this will be standard unless otherwise
stated

3. The #NUM! is a result of dividing by 0 i.e. there is no Year 2000

DIVIDE()
DAX has a DIVIDE function that takes care of #NUM! errors and displays
the results without messing up your pivot tables
1. Edit the % Growth YOY
2. Insert the DIVIDE function, which consists of a Numerator and a
Denominator separated by a column i.e. no requirement for brackets
around the Numerator

3. The edited
measure should read like this:

4. The measure displays


without errors
Presentation - Portability
DAX functions are totally portable – that’s why we love them so much! To
drive this home, setup the following pivot and just sit back and glory at what
you have just created!
1. Insert a new pivot into cell J6
2. Setup the pivot:
F
R Calendar – Year
Territory - Country
C
V Total Sales
% Growth YOY

3. Sort % Growth YOY Largest to Smallest


4. As an alternative to Showing in Outline Form - which will create a new
column for Country - just edit cell J6 to read Country
5. Show all Subtotals at Bottom of Group from the Subtotals drop-down in
the Layout group on the Design ribbon
6. Apply Conditional Formatting to % Growth YOY
DATEADD()
Total Sales DATEADD -1 YEAR
As an “alternative” to PREVIOUSYEAR(), another DAX function called
DATEADD() has a similar outcome. However, care must be taken as all it
not as it seems…
1. Insert a new pivot into cell O6
2. Setup the pivot:
F
R Calendar - Year
C
V Totals Sales
Total Sales PREVIOUSYEAR

3. Create a new measure in the Sales table named Total Sales DATEADD
-1 YEAR

4. As displayed, the DATEADD() enables you to specify an interval


5. The DATEADD function requires:

6. The potential and scope for “building” your own custom Time Intelligence
measures is vast

7. Format to Currency,
0 decimal places
8. The measure displays in the pivot and replicates, in this example, almost
the same results as Total Sales PREVIOUSYEAR

9. There are only the months January – July in 2004, therefore, only the sales
for January – July 2003 are being displayed in the Total Sales DATEADD
-1 Year column
10. To visually understand what is going on in the background, insert a
new pivot into cell U6
11. Copy the pivot in cell O6 to cell O13
12. Add Calendar – Month under Year in the Rows drop-zone
13. Edit T6 to read Year
14. Apply the usual formatting, wrap text, show subtotals at bottom of
group etc…
15. The results can only display back 1 year from the latest date in the
data
SAMEPERIODLASTYEAR()
This function provides exactly the same result as DATEADD and acts as a
filter argument to CALCULATE()
CALCULATE….SAMEPERIODLASTYEAR (<Date Column>)
I’m showing it to you so that you have choices and you are aware of the most
widely used Time Intelligence functions.
1. Copy both pivots in O6 and O13 to cells T6 and T13
2. Remove the Total Sales DATEADD -1 YEAR measure from the copied
pivots
3. Create a new measure in the Sales table as follows and add it to both
copied pivots for comparison

…is exactly the same as:


CALCULATE….DATEADD(CALENDAR[DATE], -1, YEAR)
4. Save your work

PRACTICE EX2
Total Sales PREVIOUSMONTH
1. Rename a new worksheet Ex2
2. Insert a new pivot into cell D6
3. Setup the pivot:
F
R Territories - Country
C
V Total Sales
4. Create a new measure in the Sales table named Total Sales
PREVIOUSMONTH
(Don’t worry if it doesn’t appear on the pivot – think about it – there are no
dates for a filter context – YET)
% Growth MoM
1. Create a new measure in the Sales table name % Growth MoM – ensure
the dividing by 0 error is avoided
2. Format to a Percentage, 1 decimal place
3. Add a Calendar – Month sliced on August
4. Calendar – Year slicer sliced on 2001
5. Apply your chosen formatting options, i.e. Wrap Text, AutoFit Column
Widths on Update….
6. Apply Conditional Formatting on % Growth MoM
In the screenshot below, I have placed the pivot just created below a copy to
demo the change from the first month trading (July 2001), with no
PREVIOUSMONTH sales, to the second month trading (August 2001),
with data to display
Total Sales PREVIOUSDAY
1. Select cell J6, insert a new pivot into this cell
2. Setup the pivot:
F
R Calendar - DayNoOfMonth
C
V Total Sales

3. Create a new measure in the Sales table named Total Sales


PREVIOUSDAY
% Growth DoD
1. Create a new measure in the Sales table, % Growth DoD – ensure the
dividing by 0 error is avoided
Hint: all sales minus new measure divided by new measure
2. Format to Percentage, 1 decimal place
3. Add a Territories – Country slicer
4. Position above the pivot, increase to 4 columns and sliced on France
5. In the PivotTable Tools contextual tab > Analyze tab > PivotTable group
note the current PivotTable Name
6. Right click the Month slicer, on the first pivot table
7. Select Report Connections OR you can access Report Connections from
the Slicer Tools contextual tab
8. Ensure the second pivot is selected for the Month slicer
9. Repeat for the Year slicer

10. This action ensures both pivots will update as the slicers are sliced
11. Test it out – slice both the Month and Year slicers and watch as
both pivots update, however the second pivot displays results for the
currently selected Country as the Country slicer is only connected to the
second pivot NOT the first
12. Ensure the pivots are sliced on August 2001 and all filters are off
on the Country slicer
13. Apply Conditional Formatting on the % Growth DoD
14. Sort % Growth DoD Largest to Smallest
15. It is clear to see that the United Kingdom has performed well in
terms of sales in the second month of trading. However, France has not
16. Slicing by Country can reveal more insights into daily sales %
growth and how individual countries are performing – things get more
interesting as AdventureWorks ages and more products are brought to
market
Note: The Grand Total row on the Countries pivot can be
confusing. The Total Sales is correct, the Total Sales
PREVIOUSDAY is sometimes blank due to no sales recorded on the
last day of the previous month. The % Growth DoD is blank also for
the same reason. Remember, whenever there are issues with the
Grand Total row, this is always due to the absence of a Filter
Context. Sometimes the Grand Total row is not needed.
17. Save your work
Solutions Ex2
STEP 2 – MORE ON INTERVALS
This next exercise highlights the importance of setting up the pivot table
fields correctly and how, occasionally, you will think DAX is not working as
you might expect only to realise the choice of fields and how they are
arranged, on the pivot, can make all the difference. Trust me on this, I have
spent many wasted hours trying to work out what’s wrong with my
calculations when all I needed to do was rearrange the pivot – doh!!!
Total Sales PREVIOUSQUARTER
1. On a new worksheet insert a new pivot into cell D16
2. Rename the sheet QUARTERS, setup the pivot:
F
R Territories – Country
Calendar - Qtr
C
V Total Sales
3. Create a new measure in the Sales table named Total Sales
PREVIOUSQUARTER
Note: You may receive an error message when you try to add the
new measure to the pivot regarding contiguous dates ranges – this is
due to the fact there are currently no years selected and remember,
there are 4 years currently being displayed in the pivot. Sometimes I
get this error, sometimes not? Go figure??
4. Text wrap headings but don’t select Show In Outline Form – this will
insert a new column for Qtrs – instead, edit the name of the Row Labels in
cell D16 to read Country & Qtr’s
5. Ensure the pivot doesn’t Autofit widths on update (pivot table Options)
6. Add a Calendar – Year and Calendar – Month slicer
7. Ensure December and 2001 are currently sliced, Qrt4 will immediately
display under Country in the Rows area of the new pivot
8. Do Not Show Subtotals
The Total Sales figure doesn’t look/feel right – the Grand Total is very low
for an entire Quarter results
9. Select cell H6 – insert a new pivot into this cell
10. Set up the pivot:
F
R Territories – Country
Calendar – Year
Calendar - Month
C
V Total Sales
18. The Total Sales for Australia, Qtr4 in cell E8 is correct based on
the slicers i.e. the pivot table’s current filter context is reporting correctly
but the Qtr label is misleading and it’s not the correct figure to create an
accurate % comparison of Total Sales QoQ (Quarter over Quarter),
which is the next measure you will create
19. The result required in cell Total Sales is the SUM of Qtr4 i.e.
October – December – not just December
20. In order to display the correct figure, on the Month slicer select
October, November and December
21. Remember, it’s probably going to be the end-users manipulating
this data – better still, swap out the Month slicer for a Qtr slicer instead

11. Rearrange the pivot in cell H6 as follows:


F
R Calendar – Year
Calendar - Quarter
C
V Total Sales
Total Sales PREVIOUSQUARTER

12. Insert a Territories – Country slicer – increase columns to 4 –


sliced on Australia
13. Position the slicer above the pivot in cell range H1:J5 approx.
14. Do not show subtotals

15. The Total Sales column is now reporting the SUM of the Qtr –
perfect for the % comparison measure to follow
% Growth QoQ
1. Create a new measure in the Sales table name % Growth QoQ

2. Format to %, to 1 decimal place


3. Present to ensure the report doesn’t change size on update, all column
headings are descriptive and text wrapping is applied
4. Apply Conditional Formatting to Total Sales QoQ

5. As an alternative display, select column G, insert a new column


6. Add the % Growth QoQ measure to the first pivot
7. Remove the Qtr field from Rows
8. Add Conditional Formatting to % Growth QoQ
9. Save your work
Note: Most of the measures for [Total Sales PREVIOUS***] aren’t
really required on the pivots once the percentage measures are
displayed – I’m just keeping them on for now as a reminder to you
when you come back during your studies how you achieved the
results

STEP 3 – FIRST AND LAST


In this section, you are about to create measures that belong in the Calendar
table since their “logic” operates on the Calendar table itself – they return
dates rather than sales amounts or product data and therefore do not require
the CALCULATE() function.
Whilst at first it may seem unclear as to their usefulness, they provide the
“base” logic for other Time Intelligence functions.
FIRSTDATE()
Dates FIRSTDATE
1. Rename a new worksheet First & Last Dates
2. Select cell D6, insert a new pivot
3. Setup the pivot:
F
R Calendar – Month
Calendar – Week No
C
V
4. Add a Calendar – Year slicer, sliced on 2002
5. Design tab > Layout group > Subtotals drop-down Show All Subtotals at
Top of Group
6. Create a new measure in the Calendar table named Dates FIRSTDATE
7. The only argument required is a Date i.e. Calendar[Date]
8. Format as a Short Date

LASTDATE()
Dates LASTDATE
1. Create a new measure in the Calendar table named Dates LASTDATE

2. Format as a Short Date

3. Edit cell D6 to read Month


WeekNoOfYear and text wrap headers
ENDOFMONTH()
Dates ENDOFMONTH
1. Insert a new pivot into cell H5
2. Setup the pivot:
F
R Calendar – Month
C Calendar - Year
V

3. Create a new measure in the Calendar


table named Dates ENDOFMONTH
ENDOFQUARTER() & ENDOFYEAR() are also available
4. The only argument required is a Date i.e. Calendar[Date]
5. Format as a Short Date
6. Show in Outline Form, text wrap headers

7. Remove Grand Totals – they serve no purpose


8. Copy & Paste the pivot to cell N6
9. Swap out Month on Rows for Calendar – Qtr

STARTOFYEAR()
Dates STARTOFYEAR
1. Copy & Paste ENDOFMONTH() pivot to cell T6
2. Remove Dates ENDOFMONTH from the Values drop-zone
3. Create a new measure in the Calendar table named Dates
STARTOFYEAR

STARTOFMONTH() &
STARTOFQUARTER() are also available
4. Format as a short date

5. Save your work


(You will utilise some of these Date functions in upcoming exercises to
highlight their usefulness)

PRACTICE EX3
The following practice exercise introduces 3 new Time Intelligence
functions and although you haven’t used them previously, their purpose
should be intuitive.
AUTOMATIC DATE GROUPING
Before you continue, I want to remind students who have taken the DAX
Power Pivot – 10 Easy Steps for Beginners course, and any newbies about
a date grouping feature in Excel 2016.
1. On a new sheet, select cell B6
2. Insert a new pivot
3. Add Calendar – Date to the Rows drop-zone

4. The automatic grouping feature in Excel 2016 will add:


Date (Month)
Date (Quarter)
Date (Year)
…as fields in the Calendar table in the Pivot Table Field List when the
Calendar – Date field is added, for the first time, into a pivot and in the
Rows drop-zone
5. This can be a good thing in some circumstances but for now, it’s not
6. To turn this “feature” off, follow these steps:
1. Select the File tab > Options > Advanced
2. Scroll down to the Data section – select Disable automatic grouping of
Date/Time columns in Pivot Tables
7. In the Power Pivot window, 4 new columns have also been added:

8. Delete all 4 columns, return to the worksheet


9. The automatic grouping has been removed
10. Continue with the practice exercises
CLOSINGBALANCEMONTH()
CLOSINGBALANCEQUARTER(),
CLOSINGBALANCEYEAR() are also available
Total Sales CLOSINGBALANCEMONTH
1. Rename the worksheet Ex3
2. Setup the pivot:
F Calendar – Week No
R Calendar – Month
Calendar - Date
C
V Total Sales

3. Add a Calendar – Year slicer, sliced on 2002


4. Create a new measure in the Sales table named Total Sales
CLOSINGBALANCEMONTH
1. Expression – Total Sales
2. Dates – Calendar[Date]
3. The optional [Filter] will not be used in the following exercise
5. Format to Currency, 0 decimal places

6. Do not show
Subtotals
7. Format with Text Wrapping, do not Autofit column widths on update…
8. Edit cell D6 to read Month
9. To present the data as in the screenshot above, in the Week No filter,
deselect weeks 1 – 4
10. I also collapsed the entire Month field, i.e. right click a Month
label and select Expand/Collapse > Collapse Entire Field
11. Finally, I expanded just January

Note: The only data you have to work with is based on Sales. For
this to work in reality, data from an Inventory or Cash Balance would
be more realistic – but it demonstrates the principle perfectly

CLOSINGBALANCEQUARTER()
Total Sales CLOSINGBALANCEQUARTER
1. Select cell J6, insert a new pivot
2. Setup a new pivot:
F
R Calendar – Month
C
V
3. Insert a Calendar – Year slicer, sliced on 2002
4. Create a new measure in the Sales table named Total Sales
CLOSINGBALANCEQUARTER
5. Format to Currency, 0 decimal places

6. It’s ok – but the presentation could be better - turn off all filters on the
slicer
7. Remove Calendar – Month, setup the pivot:
F
R Calendar – Year
Calendar – Qtr
C
V Total Sales CLOSINGBALANCEQUARTER
The only data you have to work with is based on Sales. For this to work in reality, data
from an Inventory or Cash Balance would be more realistic – but it demonstrates the
principle perfectly

CLOSINGBALANCEYEAR()
Total Sales CLOSINGBALANCEYEAR
1. Select cell O6, insert a new pivot
2. Setup the pivot:
F
R Calendar – Year
Territories - Country
C
V

3. Insert a Calendar – Year slicer


4. Create a new measure in the Sales table named Total Sales
CLOSINGBALANCEYEAR
5. Format to Currency, 0 decimal places
6. Do not Show Subtotals
7. Edit cell O6 to read Year
8. Save your work
Solutions Ex3
STEP 4 DATES BETWEEN
When you need to take control and nothing else will do….
DATESBETWEEN()
Total Sales DATESBETWEEN Last Half 2002
1. Rename a new worksheet Dates Between
2. Insert a new pivot into cell D6
3. Setup the pivot:
F
R Calendar - Month
C
V Total Sales

4. Insert a Calendar – Year slicer, sliced on 2002


5. Create a new measure in the Sales table named Total Sales
DATESBETWEEN Last Half 2002

6. Apply custom formatting


i.e. Text Wrap, Outline Form etc….
Notice how DATESBETWEEN completely overrides the current filter
context for the whole year 2002
Total Sales RUNNING TOTAL
You know how to create a measure that displays the running total of sales for
a whole year. You can also create a measure that crosses this “natural”
boundary and just keeps going and going….
In the previous exercise, Step 3 – First and Last, you used the
FIRSTDATE() and LASTDATE() functions. In this next example, you will
see now how you can put these functions to good use.
Total Sales RUNNING TOTAL
1. Insert a new pivot into cell I6
2. Setup the pivot:
F
R Calendar - Year
C
V Total Sales

3. Create a new
measure in the Sales table named Total Sales RUNNING TOTAL
4. Format to Currency, 0 decimal places
Note: Recap from the Beginners course about ALL() – it removes a
filter from the current filter context i.e. it’s over-riding the incoming
Date from the pivot table cell and finding the first date in the
Calendar table. ALL() is not needed on the LASTDATE() function
otherwise it would return total sales for all time – every time! ALL()
is an iterator – it has a row context – it starts at the top of a table and
works it way down (theoretically anyway, it may not do this
technically BUT it helps to think of it this way).
5. As the expressions in DAX functions develop in complexity, it can be
useful to place the “components” onto separate lines to make the
expression a little more readable.
6. Remember, the opening parenthesis to each function will bold as you add
its associated closing parenthesis to help guide you
7. The results are as you would expect i.e. a Running Total
8. Add Calendar – Months under Year in the Rows drop-zone
9. Apply the usual formatting to the headers
10. Edit cell I6 to read Year & Month
11. Do not show Subtotals OR if you prefer Show at Bottom of
Group

Presentation
1. Copy the last pivot into cell N6
2. Setup the pivot:
F
R Calendar - Month
C Calendar - Year
V Total Sales RUNNING TOTAL
3. Show in Outline Form
4. Remove the Grand Totals

5. Save your work

PRACTICE EX4
You want to produce a report that details the Total Sales and % Monthly
Sales Growth for the first operating year i.e. July 2001 – June 2002

Reproduce the report above with your knowledge of Time Intelligence


functions and ratio calculations
1. Rename a new worksheet Ex4
2. Select cell B6, insert a new pivot
3. Setup the pivot:
F
R Calendar - Year
Calendar - Month
C
V Total Sales
Total Sales RUNNING TOTAL
4. Apply the usual header formatting, edit cell B6 to read Year Month and
Do not Show Subtotals
5. Create the following new measures in the Sales table:
Total Sales BETWEEN JUL 2001 – JUN 2002

6. To display only the dates July 2001 – June 2002 in the pivot, select the
Field Filter drop-down on the Year Month column
7. Select Date Filters > Between… option
Note: If Date Filters doesn’t appear, ensure the Calendar table has
been Marked as a Date Table, see Setup & Preparation

8. Set the display criteria i.e. 1/7/2001 30/6/2002 (US & Canada: 7/1/2001
6/30/2002)
% Monthly Sales Growth (First Year)
Hint: This is just a straight-forward division between the [Total Sale]s
and the “[Between Dates]” measure just created
9. The results should look like the screenshot below:

Presentation
1. It isn’t necessary to display all the base measures needed to create the final
report – remove unnecessary measures and apply Conditional Formatting
2. Try adding a slicer to provide instant demographic analysis – it’s almost
limitless….
3. Save your work
Solutions Ex4
STEP 5 - FILTER()
I’ll dive straight in with a simple example measure and explain why the DAX
FILTER() function knocks spots off the “simple filters” provided with
CALCULATE()
No of Customers
You will need a No of Customers measure for this exercise – 10 Easy Steps
for Beginners will know to use either DISTINCTCOUNT() or COUNT() –
depending on what table you use - to create this easy measure (Answers on the
Solutions if needed).
1. Rename a new sheet FILTER(), select cell B6
2. Insert a new pivot and setup as follows:
F
R Customers - Occupation
C
V No of Customers

Let’s take a step back and revist the anatomy of the CALCULATE()
function:
CALCULATE()

Look at the second parameter in CALCULATE() - the [Filter1] part of the


function is a simple filter or “raw” filter where there is a column name on
the right i.e. Customers[YearlyIncome], and a value on the left i.e.
> 50000
This simple [Filter] alters the original meaning of the expression – in this
case, without the [Filter] it would return the total number of customers in the
customers table BUT the simple [Filter] filters the customers table to just
those who earn yearly incomes above £50,000.
So, just to drive that home, the [Filter] alters the original meaning of the
expression and the [Filter] is a simple [Filter]. What do I mean by “simple
filter”?

EXAMPLES OF SIMPLE FILTERS (RAW FILTERS)

Taking a filter from a lookup table and propagating it to the data table is what
Power Pivot is optimised to do and it works at lightening speed.
So, that’s our recap on CALCULATE() and its use of simple Filters, let’s
get to the good stuff!
FILTER()
The FILTER() DAX function is a standalone function independent of
CALCULATE(). Do not confuse it with the second argument in
CALCULATE() i.e. [Filter1], [Filter 2…] etc which as discussed above, are
“simple filters”.
However, FILTER() can be combined with CALCUATE() to perform some
very powerful calculations. First, you’ll have a look at FILTER() on its own
and how it works.
FILTER() SYNTAX

FILTER() returns a table – not a single value. It is an iterator, in English this


means it steps row by row through a table i.e. it has a row context, to evaluate
the second condition i.e. the FilterExpression.

Note: There are a whole family of X functions i.e. SUMX(), MINX(),


MAXX(), COUNTX(), COUNTAX() and ALL() that return a table,
so it’s not on its own in this respect.
The pivot table above contains the No of Customers Earning over £50000
measure created with CALCULATE()

You can create the same measure, without CALCUALTE() using the DAX
FILTER() function

However, if you went ahead and tried to evaluate this measure now, it
wouldn’t work. I’ll explain why:
1. The FILTER() goes to the Customers table and creates a row context -
let's say it starts at row 1 - and this CustomerID is 1.
2. It then filters through all the rows so that all the YearlyIncome row/s for
CustomerID 1 are unfiltered i.e. the Customers table is now just filtered
on all CustomerID 1 row/s.
3. FILTER() argument "asks" - "is the value of YearlyIncome for
CustomerID 1 greater than 50000?"
4. If yes, the results are kept in the final table result. If no, it is discarded
5. FILTER() then moves to CustomerID 2 in the row context of the
Customers table and starts all over again and proceeds through every row
in the Customers table.
6. FILTER() then returns a table of customers that passed the "test"
(FilterExpression) and returns the table of customers to FILTER().
7. This filtered table of customers is now a “virtual” table hanging about
with not a clue what to do or where to go
8. FILTER() returns a table – you cannot put the results of a table into a
single cell i.e. a pivot table single cell. It has to be evaluated to a single
value via an aggregator function such as COUNT(), COUNTROWS(),
SUM() etc…

Now we know that – let’s crack on with some examples


No of Customers Earning Over £50000 with FILTER
1. Create the following measure in the Customers table, formatted as a
number, 0 decimal places and with a 1000 separator

2. Wrapping the FILTER() function with a COUNTROWS() function takes


care of the “virtual” table created from the FILTER() function i.e.
COUNTROWS() counts the rows in the “virtual” table and a single value
is returned – YAY!

You have seen it’s possible to create 2 different measures to return the same
results using CALCULATE() or FILTER():
=CALCULATE([No of Customers],
Customers[YearlyIncome] > 50000)
=COUNTROWS(FILTER(Customers,
Customers[YearlyIncome] > 50000))
This is due to the fact there is a column name on the left and a value on the
right in the simple filter argument of the CALCULATE() function.
So why bother I hear you ask? Well, as mentioned earlier, the
CALCULATE() function is optimised to perform these simple filter
functions at lightning speed and you really should use CALCULATE()
wherever and whenever possible.
FILTER() comes at a cost in terms of speed and processing. Therefore, if
your data model is large, FILTER() in place of CALCULATE() can be
“expensive”.
There is another reason. We all love CALCULATE() right? HOWEVER,
with its simple filter limitation, what do you do when you need something a
little more complicated… I’m thinking custom Time Intelligence here and
that’s where we’re heading. But, before we get there, let’s do some more with
FILTER() and get really comfortable with it.
CALCULATE() AND FILTER() TOGETHER! – SAY
WHAT?!?
Customers with 5 or more Orders
The objective here is to determine if there are any customers who have
purchased more than 5 items – not in one transaction, but over the course of
time.
1. Select cell G6, insert a new pivot table
2. Setup the pivot:
F
R Territories - Country
C
V Total Sales

3. Create a measure to SUM the OrderQuantity column in the Sales table i.e.
Total Order Quantity
=SUM(Sales[OrderQuantity])
4. Format as a whole number with a 1000 separator and show in Outline
form

5. First, let’s have a go at creating Customers with 5 or more Orders


measure using CALCULATE()

6. The results, well – this is clearly incorrect


7. Power Pivot has interpreted this as:
“Sum up the No of Customers THEN filter all the
Sales[OrderQuantity] that’s greater than 5”
8. Well the Sales[OrderQuantity] in total is 60,398 which is greater than 5
and there are 18,484– so, all of the customers are returned
9. Remember, CALCULATE() uses a “simple filter” – there’s no row
context here
10. Power Pivot isn’t iterating through each row of the OrderQuantity
column and assessing whether it’s greater than 5 – it doesn’t know what to
do with this. Hence, it’s a “simple filter”!
THE FIX WITH FILTER()
Customers with 5 or more Orders FIXED
1. Remove the Customers with 5 or more Orders measure from the pivot
2. Create a new measure named Customers with 5 or more Orders FIXED
as follows:

Let’s step through what is happening here:

1. FILTER() is performed first within the CALCULATE() function – so


it’s working inside out!
2. The FILTER() goes to the Customer table and creates a row context -
let's say it starts at row 1 - and this CustomerID is 1.
3. It then - via the relationship with the Sales table - filters through all the
rows so that all the OrderQuantity rows for CustomerID 1 are unfiltered
i.e. the Sales table is now just filtered on all CustomerID 1 rows.
4. The measure [Total Order Quantity] is then evaluated for CustomerID
1
5. FILTER() argument "asks" - "is the value of [Total Order Quantity]
for CustomerID 1 greater than 5?"
6. If yes, the result is kept in the final table result. If no, it is discarded
7. FILTER() then moves to CustomerID 2 in the row context of the
Customer table and starts all over again keeping or discarding the results
in the final table result. It proceeds through every customer in the
Customer table.
8. FILTER() then returns a table of customers that passed the "test"
(condition) and returns the table of customers to CALCULATE(). This
filtered table of customers is accepted and applied as a filter by
CALCULATE() before it evaluates the COUNTROWS(Customers)
part.
9. There are 1,657 customers who passed the "test" i.e. have made 5 or
more purchases out of a possible 18,484 customers

3. The results should look the same as the screenshot below:


Customers with Sales Greater than £5,000
1. This measure is similar – let’s have a go
2. I have written the measure so that it’s clearer to read – or perhaps not – it’s
your choice remember how you write your functions BUT it’s good
practice, especially if you are collaborating with others and you can all
read each other’s logic a little better

Let’s step through what is happening again…

1. FILTER() is performed first within the CALCULATE() function – so


it’s working inside out!
2. The FILTER() goes to the Customer table and creates a row context -
let's say it starts at row 1 - and this CustomerID is 1.
3. It then - via the relationship with the Sales table - filters through all the
rows so that all the SalesAmount rows for CustomerID 1 are unfiltered
i.e. the Sales table is now just filtered on all CustomerID 1 rows.
4. The measure [Total Sales] is then evaluated for CustomerID 1
5. FILTER() argument "asks" - "is the value of [Total Sales] for
CustomerID 1 greater than 5000?"
6. If yes, the result is kept in the final table result. If no, it is discarded
7. FILTER() then moves to CustomerID 2 in the row context of the
Customer table and starts all over again keeping or discarding the results
in the final table result. It proceeds through every customer in the
Customer table.
8. FILTER() then returns a table of customers that passed the "test"
(condition) and returns the table of customers to CALCULATE(). This
filtered table of customers is accepted and applied as a filter by
CALCULATE() before it evaluates the COUNTROWS(Customers)
part.
9. There are 1,732 customers who passed the "test" i.e. have purchased
more than 5000 worth of purchases out of a possible 18,484 customers

Just before the practice exercises, I want to allay some doubts you may be
having. When I first learned about FILTER() I wasn’t entirely convinced I
wasn’t just going around the houses - recreating the wheel in some respects. I
was fairly sure I could jog along quite nicely without it (in a lot of cases, not
all), and it seemed a bit of a long haul for not much reward.
But, I was wrong. FILTER() - when used in the right way - brings great
rewards and in the previous examples I am merely setting the scene. Bear
with my friends…bear with!
3. Save your work

PRACTICE EX5
1. Rename a new worksheet Ex5
2. Select cell B3, insert a new pivot
3. Setup the pivot:
F
R Products - Category
C
V Total Sales
4. Create the following new measure in the Sales table:
Total Sales of Products with Sales but Less than £20,000
Hint:
1. You are not counting rows, therefore no additional DAX functions are
required after CALCULATE() – what’s needed here is the total sales
figure.
2. The logical operators work with FILTER() too i.e. && for AND works
perfectly for this measure – remember what you’re asking to return i.e.
greater than 0 but less than 20,000
3. Format to Currency, 0 decimal places

5. Create the following new measure in the Sales table:


Count of Products with Sales but Less than £20,000
Hint:
1. You are counting rows this time
2. Format as a Whole number

6. Add the Products – ProductName field to rows, under Category


7. Remove the Total Sales measure

8. Save your work


Solutions Ex5

CUSTOM CALENDARS - SETUP & PREPARATION

When out-of-the-box Time Intelligence DAX functions just don’t cut it…
Sometimes your needs aren’t covered in the fantastic DAX functions
available to you and you have to impress with your know-how.
In this exercise, and with the introduction of MIN(), MAX() and our new
friend FILTER(), custom Time Intelligence functions can be created to help
you out of a tight spot.
CUSTOM CALENDARS
It is very common for many industries such as manufacturing, as well as
education, sports bodies and especially retail, to favour a Custom Calendar.
Retail for example most often use a 4-4-5 calendar. This refers to the number
of weeks in each period i.e. where a period is approximately a month, rotate
through 4 quarters in a year, naturally, and each quarter consists of 13 weeks.
The reasoning is that accounting periods are based on weeks instead of
months. One month and one quarter are a number of weeks and any week
cannot be split between different months, quarter or years. All of this enables
accurate comparisons of growth, versus last year, versus prior periods etc.
Many of the Time Intelligence functions you have created in this course i.e.
DATESYTD(), DATEADD(), SAMEPERIODLASTYEAR(), YOY() and
others simplify writing DAX expressions because they respect and are based
around the structure of the standard calendar. Therefore, they will not work
with a custom calendar and that’s where you and your DAX skills come to
the fore!
Even if you never intend using a custom calendar PLEASE, PLEASE
DON’T SKIP THIS SECTION!
When I first taught myself how to write DAX, I skipped it until the end
because, like you, I thought I’m unlikely to need this but I know it’s
important to my development and I’ll come back to it, later. DON’T DO
THAT!
Custom Time Intelligence is GREAT! It really makes you think about all
the fundamentals you have learned so far and will give you such a lift and
drive your confidence and understanding to new heights – trust me on this!
You’re going to love it and be thankful you did it.
RELATING THE CUSTOM CALENDAR
You are now going to add a Custom Calendar to the existing data model.
First, let’s take a look at it and see what’s different about it.
1. Right click any existing worksheet
2. Select Unhide…
3. The CustomCal is the only option available – click OK
I have left all the formulas in place, so that you can have a look through and
see how the columns are created. It’s all pretty straightforward and you can
substitute your own starting date in B2 to use for your own data model, no
really that’s ok – you’re welcome!
The only “strange” one is the last column FirstPeriodInYear. You will see
later, you need a column that identifies the year in terms of the period ending
date and this is the only way I could think of doing it. Why 1, 7, 19 and 31 –
well, they are the first PeriodID’s in the Year.
The Calendar and the CustomCal will have a One-to-Many relationship. A
new PeriodID will be added to the Calendar table to facilitate this. This might
seem convoluted – so forgive me – but I thought long and hard about how to
show you this and if there were any shortcuts – I couldn’t think of any and I
don’t have a magic formula that generates this final column. I confess, I did it
manually – to a degree. If you’re watching the online video tutorials, I show
you what I used to help me in the Bonus Lecture.
4. Select the Calendar sheet
5. Select cell H1, label it PeriodID, press Enter
6. The periods are in the 4-4-5 week sequence which is 28-28-35 days
7. For ease, I have supplied the PeriodID’s in a separate workbook to be
Copied & Pasted into the Calendar table
8. Open the PeriodID workbook
9. Select cell A2, hold down the CTRL/SHIFT & Down Arrow to highlight
the range to cell A1128
10. Copy the range (CTRL C), close the PeriodID workbook – don’t
save the change and confirm Yes to copy the Clipboard contents
11. Select cell H2, in the Sales Report TI Calendar sheet, Paste
(CTRL V)
12. Ensure the range is in alignment with the other columns in row
1128 of the Calendar table
13. The PeriodID column in the CustomCal table will be used as the
basis of a One-to-Many relationship with the PeriodID column in the
Calendar table
14. Select the CustomCal sheet
15. Ensure the table is named CustomCal on the Table Tools
contextual tab Design ribbon under the Properties group

16. Select the Power Pivot tab > Tables group > Add to Data Model
option

17. The CustomCal table is Linked to the Data Model

18. In the Data Model window select Diagram View


19. Postion the CustomCal above the Calendar table and create a
relationship with the PeriodID fields – from CustomCal PeriodID “One”
to Calendar PeriodID “Many”
20. …and breathe out – you’re there – you did it. You have related the
CustomCal to the existing Calendar without too much pain!
WHY THOUGH?
First things first – why have I related the Calendar and CustomCal? Well, the
short answer is – I conceded I had to – for this course to run as smoothly as
possible.
It was easier for me to start with a standard calendar – very straightforward.
Then I had to think about whether to rearrange the standard and add lots of
columns to it to, chop and change it around and, frankly, I thought better of it.
Instead, I added a PeriodID column to the standard Calendar, linked the
CustomCal to the data model and related the 2 tables via the PeriodID field.
Doing it this way, let’s you see a couple of ways of laying out the calendars
i.e. standard and custom. Take a moment to have a look at the differences.
Adding the PeriodID to the standard was the biggest headache for me. As I
mentioned previously , if I knew of a magic Excel formula, (i.e. a simple and
straightforward formula I mean), to do this, I would show you. But, I had to
do it manually in the end – not very exciting and I’ve taken the liberty of just
supplying it to you to add it in. Basically, it follows a 28-28-35 day pattern
i.e. 4-4-5 week pattern.
An alternative approach, when using just a custom calendar, could be to build
the calendar at a daily level and connect it directly with the Sales table. You
would still require the “Period*” columns in this calendar but all the
following formulas would work. So, basically, what I’m saying is – instead of
the Start and End columns in the custom calendar, you would have a Date
column – hope that’s clear. You’ll have to weigh up what’s best/easiest for
you and you’ll only be able to figure that out with lots of practice!
NOTE: There are probably many ways of adding a custom calendar
and if you know of an easier, quicker way – great! I know there are
many offering on the web for creating custom calendars using SQL,
PowerQuery etc. Each one of you will have a bespoke calendar that
you need for starting/ending dates, periods, column ids etc.
Therefore, it would be impossible for me to provide a one-size-fits-
all solution.
Right, let’s get down to business and continue our DAX wizardry with some
custom formulas and measures for 4-4-5 calendars!
STEP 6 – FILTER CONTEXT AND BEHIND THE SCENES
The following examples, are just that – examples and although they may not
make much commercial sense, they demonstrate how to utilise DAX
functions to build your own solutions.
1. Insert a new worksheet, rename it Filter Context
2. Select cell B3 – insert a new pivot into this cell
3. Setup the pivot:

F
R CustomCal - Year
C
V Total Sales

4. Focus on cell C5 in the pivot table


5. This figure is a result of the CustomCal table, in the data model behind the
scenes - being “virtually” filtered on Year column to 2002
6. Switch to the Power Pivot window – select the CustomCal sheet
7. To replicate what is going on in the background to display this result,
manually filter the Year column to show only 2002
8. This results in a total of 12 rows

9. The CustomCal table isn’t physically being filtered – all the filtering goes
on virtually on the fly and held in a “virtual” table
10. Since the filters flow “downhill” via the relationships i.e. from
CustomCal to Calendar to Sales, the Sales table is “virtually” filtered to
only the sales in 2002, which are then calculated and cell C5 displays
Total Sales for 2002
11. The rub here is to get you thinking about what is going on behind
the scenes and in particular, getting you to think in terms of the whole
table/s, in the background, when you’re looking at a pivot table cell result
i.e. the current filter context.
MIN() & MAX()
You’re coming from an Excel background – right? Even if you’re not, the
concepts of MIN and MAX aren’t too challenging. Let’s test this out with a
few questions based on the screenshot above:
What are the values for the following:
1=MIN(CustomCal[Start]) =
2=MAX(CustomCal[End]) =
3=MIN(CustomCal[PeriodID]) =
4=MAX(CustomCal[PeriodID]) =

12. The MIN Start is 30/12/2001 and the MAX END is 28/12/2002
13. The MIN PeriodID is 7 and the MAX PeriodID is 18
14. I bring this to your attention because when MIN() and MAX() are
combined with FILTER(), you are on your way to building some pretty
powerful measures in DAX, essentially needed skills for custom Time
Intelligence functions!
15. This information is very useful indeed – keep it in mind for the
following Custom Time Intelligence exercises – you’re gonna need it!
CUSTOMCAL FUN WITH THE BASICS
1. On the Filter Context sheet, select cell F3
2. Insert a new pivot, set up as follows:
F
R CustomCal – Year
CustomCal - QtrLabel
CustomCal - PeriodLabel
C
V Total Sales

Note: You could setup an Hierarchy of fields that you intend using
frequently, as shown below. For the purposes of this training course I
have chosen not to. But, it’s your call and a handy tool to pull out
when you need to
3. Edit cell F3 to read Year Qtr Period

4. Insert a new measure into the CustomCal table named PeriodStart, format
as a short Date
PeriodStart

5. Insert a new measure into the CustomCal table named PeriodEnd, format
as a short Date
PeriodEnd

6. Insert a new measure into the CustomCal table named Total Days in
Period, format as a number, 0 decimal places
Total Days in Period

7. With some Conditional Formatting applied, patterns are easily identified


– don’t select the Subtotal cells to apply the Conditional Formatting i.e.
select cells I6 and J6

8. Notice the “spikes” due to the extra 7 days or week of sales!


9. To rectify this in order to fairly compare sales, a new measure that
compares sales per day, or sales per week is needed
10. Create a new measure in the CustomCal table, named Sales per
Day in Period formatted to Currency, 0 decimal places
Sales per Day in Period

11. Apply Conditional Formatting to compare the results

Note: You may wonder at the disparity in the Grand Total for Total
Sales and Sales per Day in Period. This is due to the CustomCal’s
last End is set to 21/08/2004 and the Calendar last date is
31/07/2004. The Grand Total for Sales per Day in Period is
dividing by a greater number of days than actual selling days in this
example.
12. Remove the Grand Total row – it doesn’t make sense in this
context, see below
13. Save your work
STEP 7 – DAX PATTERNS
As your journey continues and your understanding of the advanced working
of DAX continues, you will come to rely on patterns. These are DAX
“structures” that you can adapt to meet your needs.
I am going to introduce a Time Intelligence DAX pattern using the concepts
of FILTER() and ALL()
Note: I covered the ALL() DAX function in the 10 Easy Step for
Beginners course, therefore, I will not cover it again here. All I will
remind you of is that ALL() is used with CALCULATE(), as one it
the filter arguments, to remove a filter from the filter context.
Let’s just get on with it with some cool examples.
Prior Period Sales
This measure is similar to the PREVIOUSMONTH() function for a
standard calendar. It can be adapted for quarters and years
1. Rename a new worksheet PRIOR PERIODS
2. Select cell B3, insert a new pivot
3. Setup the pivot:
F
R CustomCal – Year
CustomCal - QtrLabel
CustomCal - PeriodLabel
C
V Total Sales

4. Select cell B3, edit to read Year Qtr Period


5. Ensure the Subtotals drop-down has Show All Subtotals at Bottom of
Group selected
6. The objective is to create the following:

7. Create a new measure in the CustomCal table named Prior Period Sales
formatted to currency with 0 decimal places – this will be the norm unless
otherwise stated
8. Whoa… too fast, too fast!! What the heck is this??
9. Bit by bit – first the “Pattern” - which is just about to become your new
best friend forever or BFF

Step 1
This first line IS the “pattern” essentially – it doesn’t change – as long as the
base measure is called [Total Sales] and the calendar table is called
CustomCal

Remember, the initial filter context is coming in from the pivot table. So, if
cell D7 is the focus:
If you don’t have a column on which to perform the “navigation maths”, you
won’t be able to navigate the CustomCal table effectively – for this data
model, it’s the PeriodID column
The FILTER(), on its own, will “home-in” on the row highlighted above i.e.
P8 – due to the current filter context coming in from the pivot table.
BUT, it’s P7 in the row above that is required for our measure result.
So, what is needed is a way of iterating through the table. (This concept is for
us humans – it might not work like this in reality – but it helps to think of it
this way).
That’s where the ALL() function comes in. Remember, ALL() removes the
filter from the filter context enabling you to iterate through the entire
CustomCal table and if there weren’t an ALL() function included we would
be stuck on the incoming filter context row with no way of moving from it -
genius!
Step 2
So, you’re starting in the PeriodID column, because that’s the unique
identifier row used in the navigation maths, and MAX() DOES observe the
original filter context coming in from the pivot table. Therefore, in our pivot
table example cell D7 is where MAX() will begin and would return the value
of PeriodID 2.

By substracting 1, the result comes from the row above which is PeriodID 1
which is P7 for the benefit of the pivot table.
This might seem confusing – you have a filter context, that’s overwritten by
ALL(). Then the FILTER(), which is an iterator, generates a row context.
Then the MAX() function applies the original filter context.
If all seems a bit chaotic – does it really matter? I mean really? You have the
pattern – it’s just the maths bit at the end you really have to contend with.
Don’t get too lost in the detail right now – just accept it for the time being
and when you give yourself a bit more time, practice and experience, come
back to this and re-read. Don’t beat yourself up or STOP – just keep going.
Trust me, it will all come together in the end. The most important thing is
NEVER, NEVER, NEVER give up!

PRACTICE EX7
Sales YOY
This is straight-forward enough. Now that you have a pattern to follow, all
you have to think about is the navigation maths at the end. If you’re really
smart, copy and pasting the pattern part of the formula from the previous
measure and editing is even better!
1. Create the following measure in the CustomCal table

2. Your results should look like the screenshot below:


1. If you have struggled with this, a full explanation is given below.
2. Save your work
Just like before, the “pattern” is there - CALCULATE(), base measure i.e.
Total Sales, FILTER() and ALL() – then it’s just the maths. In this
example, you want the previous year’s result, therefore it’s -12.
It really helps me to visualise what’s going on and get the maths right:

1 – Is the first result in the pivot under Sales YOY. The filter context from
the pivot are P7 – Q3 – 2002. However, the FILTER() function provides the
row text needed and the ALL() function clears the filters – so, it starts at the
top. The MAX() function and the logic states, “match the filter coordinates of
the original filter, then -12” and iterates through the table. When it gets to
PeriodID 13, there is a “match” for all the coordinates BUT the navigation
maths says -12.
2 – By subtracting 12, the result, 12 rows up i.e. 1 year, is PeriodID 1 which
happens to be coordinates P7 – Q3 – 2001 which is equates to total sales 12
months ago.
Therefore, the result is £426,286 i.e. the result of the sales 1 year back
If you have spotted the Sub Totals as being off, don’t worry. You’ll be to
fixing those soon!
It can be tricky to get your head around the navigation maths – it was for me
and still is sometimes. I’ve got to think about what I want DAX to do. I think
I’ve got it, then I make a blunder. I’m a lot better now, but that has come with
patience, practice and urmmm…. more practice!
Don’t sweat it – if it doesn’t work out – try again. That’s what it’s all about. I
haven’t met anyone – yet – that just “gets it”. Some are good at it – but you
know what- it’s because they’ve practiced and/or had years of experience.
So, my message is – don’t give up. We all get the lightbulb moment where
we say “Oooohhhhh – I get it! That’s how it works – yeahhhhh – I’ve got
it”!!! Then you feel GREAT for the rest of the day/week/month because
you’ve learnt something new and you feel invincible – I’m right aren’t I?
Yep, thought so – we’ve all been there!
STEP 8 – NAVIGATION MATHS
Let’s build on your skills and delve a little deeper with navigation maths in
the pattern we’ve been using in the custom calendar.
Until now the measures you have created have referenced another single
value to be “substituted” for another i.e. shift back 1 place or shift back 12
places and retrieve the figure. This next measure is the total for last year’s
sales i.e. “summing”12 rows worth of values in our custom calendar. This is a
little trickier to achieve but, again, a pattern will emerge that can be edited to
work at all levels i.e. Year, Quarter or Period.
YTD Sales
1. Rename a new worksheet Year To Date
2. Select cell B3, insert a new pivot
3. Setup the pivot:
F
R CustomCal – Year
CustomCal - PeriodLabel
C
V Total Sales
4. This is the objective – a running total of sales throughout the year

5. Create a new measure named YTD Sales, stored in the CustomCal table,
formatted to currency, 0 decimal places
6. The pattern is entered first followed by the navigation maths:
7. Ooops – the PeriodLabels are not sorted properly
8. In the Power Pivot window, sort the PeriodLabel column by the
PeriodOfYear
9. Let’s step through this visually, follow the selected cell in the pivot:

10. Save your work


Note: The FirstPeriodInYear is the best option to use within the
YTD Sales measure because of its granularity. What I mean by this
is that it is at the month level which is less granularity than at the
year level i.e. small “chunks”. For example, if the
CustomCal([Year]) column is substituted for
CustomCal([FirsPeriodInYear]) column the measure won’t work.
Any other columns in the CustomCal would be harder to write the
navigation maths, therefore, FirstPeriodInYear is the most suitable
option. In the meantime, just get comfortable with the pattern and
have fun with the examples and exercises. A deeper understanding
and confidence will follow.

PRACTICE EX8
Try it out for yourself – fill in the blanks for the highlighted cell in the pivot
and plot the filter coordinates in the CustomCal below and test the logic in
the navigation maths.
Here’s a reminder of the measure:
[YTD Sales] =

1. The filter context is PeriodID_____ and the corresponding


FirstPeriodInYear is__​___
2. We stated <= MAX([PeriodID]) which is all the way back to row __​‐
____. However, we also stated
>= MAX([FirstPeriodInYear]) and that is ___​​___
3. That cancels out PeriodID's ______ - _______ which are all Years
_______ & ______ and, for the highlighted cell in the pivot, we only want
sales from Year ______ PeriodLabel ______ - Year ______ PeriodLabel
______ perfect!
Solution Ex8
STEP 9 – SUPPRESSING & FIXING TOTALS
At the end of Practice Ex7 on the Prior Periods sheet when you completed
the Sales YOY measure, I mentioned I would address the issues of the
strange Subtotal results – here goes…
1. Just as a refresher look at the following screenshot from Practice Ex7
sheet:

2. The Subtotals are incorrect and unnecessary at this level for Prior Period
Sales
3. However, turning off Subtotals will remove them from the pivot entirely
and this would affect Total Sales too – not the solution!
4. Let’s take a look at what this measure result actually is…
5. Firstly, here’s the measure:
[Prior Period Sales]
=CALCULATE([Total Sales], FILTER(ALL(CustomCal),
CustomCal[PeriodID] = MAX(CustomCal[PeriodID])
-1))

6. Power Pivot V2 has a new function called HASONEVALUE() and it is


perfect for detecting when a cell is a subtotal or a grand total
7. The 2001 Total row specifically, the figure £516,537 IS the previous
period

8. The Total Sales figure, to the left, is the result of all the periods in that
year i.e. it has multiple values that make up the grand total
9. With the addition of the DAX HASONEVALUE() function, the existing
[Prior Period Sales] measure can be edited to suppress the subtotals
HASONEVALUE()
Prior Period Sales Subtotals Suppressed with
HASONEVALUE
1. Select the Prior Periods sheet
2. Edit the sheet name to Prior Periods & HASONEVALUE()
3. Select cell G3
4. Insert a new pivot
5. Setup the pivot:
F
R CustomCal – Year
CustomCal - QtrLabel
CustomCal - PeriodLabel
C
V Total Sales

6. Right click on the Prior Period Sales measure in the CustomCal table in
the Pivot Table Field List
7. Select Edit Measure…

8. Copy the code and cancel out of the window


9. Create a new measure in the CustomCal named Prior Period Sales
Subtotals Suppressed with HASONEVALUE – I know…., I know it’s
huge, but you’ll thank me when you come back and wonder how you did it!
10. Remove the existing = Paste the code into the window and edit it
to include the IF(HASONEVALUE(CustomCal[PeriodID]), statement at
the beginning AND ,BLANK() at the end:
11. Format as Currency, 0 decimal place
12. What this says is – “If PeriodID has only one value, go ahead and
show the measure on the pivot, otherwise return a blank cell”.
13. This is the result – much cleaner!

WAY TO GO YOY – WHAT’S WITH THE TOTALS?


Here’s a refresher of the earlier measure for Practice Ex7, [Sales YOY]. It’s
located on the same pivot you have been working on to suppress the subtotals
with HASONEVALUE() in the previous exercise:
For display purposes, I have selected Show in Tabular Form under Report
Layout on the Design tab
(If you are going to mimic this layout, first insert 2 new columns at column
F)

This is clearly incorrect, however it’s not as easy as suppressing the subtotal
with HASONEVALUE() – it’s different and doing that would just return a
blank cell – not the solution at all!
You are about to build upon the skills you have worked hard to acquire, just
dig a little deeper and you’ll be glad you did! Deep breath – let’s begin!
SALES YOY REVISITED
Here’s a recap of the [Sales YOY] measure:

…and it’s the highlighted section that’s needs to be looked at again.


Let’s select a cell, 2002 Total, to “home-in” on and follow its journey:
1. The pivot table filter context for this cell is CustomCal[Year] = 2002
2. So the MAX(CustomCal[PeriodID]) for Year 2002 is PeriodID 18
3. The current measure subtracts 12, therefore what is displayed in the
cell is the results of PeriodID 6 i.e. Year 2001, Q4 and P12.
Solution? Is to shift back 12 PeriodID’s from the:

I’ll explain through the medium of dance – no, only kidding – with a
diagram:
1. The pivot table filter context for this cell is CustomCal[Year] = 2002
2. So the MAX(CustomCal[PeriodID]) for Year 2002 is PeriodID 18 and the
MIN(CustomCal[PeriodID]) for Year 2002 is PeriodID 7
3. The current measure subtracts 12 from the
>=MIN(CustomCal[PeriodID]) therefore this is PeriodID 1 i.e. Year
2001, Q3 and P7 i.e. shift back 1 whole year from the beginning of the
incoming current filter context year or as far as there is data*(see Note
below)
4. The current measure subtracts 12 from the
<=MAX(CustomCal[PeriodID]) therefore this is PeriodID 6 i.e. Year
2001, Q4 and P12 i.e. shift back 1 whole year from the end of the
incoming current filter context year
*Note: In this example, Year 2001 started trading in July – we have
nothing before this in terms of Qtr’s or Periods. If there were, the
measure would take this into account and calculate these values. You
can see this working perfectly in the pivot when you complete the
exercise.
The logical operators can take a while to absorb. The best way is to think of
them is to pick a cell in the pivot table and trace it back to the CustomCal – it
helped me to work it out.
Remember to think of the cell pertaining to the current filter context. So for
the example in the pivot table, Total 2002 - >=MIN(CustomCal[PeriodID])
is the first PeriodID in the Year which is 7. Therefore, it’s >= to this i.e. 7
up… but the <=MAX(CustomCal[PeriodID]) is 18 – why? Because, it’s the
last PeriodID in the Year 2002. Therefore, the search results will come from
somewhere in-between these rows depending on the incoming filter context
on the pivot table for Year 2002.
Sales YOY TOTALS FIXED
1. Ensure the cursor is in the Prior Periods & HASONEVALUE() sheet and
in the second pivot
2. First, edit and copy the [Sales YOY] measure from the Pivot Table Fields
List and cancel out of the window
3. Create a new measure in the CustomCal table named Sales YOY
TOTALS FIXED
4. Format to Currency, 0 decimal places

5. The results should look like the screenshot below when subtotals are
shown the bottom of the group
HEY, I LIKE THE QUARTER TOTALS!
You can’t please everyone – for all you IT guys and gals out there you know
how that feels right? So, you manage to remove/suppress the subtotals –
great – then another manager says “but we need them in our department –
how are we supposed to know how we did last quarter”?
So, back to the drawing board and you have to come up with a way that
doesn’t mess with the existing pivot – cos that would upset some other
department, right?
Well, luckily there is a way to keep everybody happy and it can be applied
for Years and Periods too.
For clarity, setup a new pivot in cell N3 in the Prior Periods &
HASONEVALUE() sheet
1. Setup the pivot as follow:
F
R CustomCal – Year
CustomCal - QtrLabel
CustomCal - PeriodLabel
C
V Total Sales
Prior Period Sales
Prior Period Sales Subtotals Suppressed with HASONEVALUE()

2. Show in Tabular Form and text wrap the headings:

3. What’s being asked for is the Qtr totals for the prior period to display –
correctly – don’t just suppress them thank you very much!
4. Right click the Sales YOY TOTALS FIXED measure in the Pivot Table
Fields List and select Edit Measure…
5. Copy the code, Cancel the window
6. Create a new measure in the CustomCal table named Prior Period Sales
Fixed with COUNTROWS
7. Paste the copied code and edit to include - COUNTROWS(CustomCal)
in place of -12 in the FILTER() expression
8. Format as currency, 0 decimal places
9. The results should look like the screenshot below:

10. Scroll down to investigate further just how GREAT this measure is
– it’s not just working at the Quarter level
11. The new Prior Period Sale FIXED with COUNTROWS is
matching at the Period, Qtr and Year levels – great news for everyone!
Great, But Why…How??
By subtracting COUNTROWS(CustomCal), rather than a fixed number like
3 or 12, the current time selection i.e. Year, Qtr or Period is being subtracted
- in other words – if the filter context is on Years, it will go back 12 periods
automatically, if it’s on Qtr’s it will go back 3 etc….GENIUS!!! We love
you DAX ENGINE!!!
It took three attempts to get here but, I’m hoping along the way, you have
learned some useful concepts instead of me diving straight in with the
heavyweight stuff!
Not only that, it gives you options. Sometimes HASONEVALUE() is perfect
for what you want/need/require and other times, well, you have to please
everybody!
STEP 10 – % GROWTH MEASURES
Let’s take stock of what you have achieved and display all the new measures
in the last few steps.
1. Rename a new worksheet % Growth Measures
2. Select cell B3
3. Insert a new pivot
4. Setup the pivot:
F
R CustomCal – Year
CustomCal - QtrLabel
CustomCal - PeriodLabel
C
V Total Sales
Prior Period Sales
Prior Period Sales FIXED with COUNTROWS
YTD Sales
Sales YOY TOTALS FIXED

5. From the Pivot Table Design tab select Layout group > Report Layout
drop-down Show in Tabular Form
6. Text wrap the headers
(The measure names wouldn’t normally be this long and/or ugly – they’re just a
reminder of how you achieved the results)
Percentage growth formulas comes down to some straight-forward maths.
Just remember it’s “new subtract old, divided by old” and you won’t go far
wrong
Also, try to re-use existing measures where possible i.e. don’t re-invent the
wheel!
7. Create the following new measures in the Sales table as currency, 0
decimal places unless it’s a % growth measure – format as a percentage, 1
decimal place
Sales per Prior Period Growth
=[Total Sales] - [Prior Period Sales FIXED with COUNTROWS]
[Sales per Prior Period Growth] is a base measure for the next measure
and, in this example, it will not appear on the pivot
Sales per Prior Period Growth %
=DIVIDE([Sales Per Prior Period Growth], [Prior Period Sales
FIXED with COUNTROWS])
8. Apply Conditional Formatting for visual impact
9. To apply the Conditional Formatting to ALL cells in the column, apply
the formatting to the first cell only. Select the Format Options drop-down
– select the second option:

10. To re-order the measures in the Values drop-zone in the Pivot


Table Field List, select the drop-down to the right of the measure name:

11. Select an action to reposition the measure in the pivot table


12. The [Prior Period Sales] measure is no longer needed on the pivot
as the subtotals have been fixed with, firstly HASONEVALUE() and then
with COUNTROWS()
13. The pivot should look similar to the following screenshot:
14. Next, YOY growth measure and growth %
15. Create the following new measures in the Sales table as currency,
0 decimal places unless it’s a % growth measure – format as a percentage,
1 decimal place
Sales YOY Growth
=[Total Sales] - [Sales YOY TOTALS FIXED]
[Sales YOY Growth] is a base measure for the next measure and, in this
example, it will not appear on the pivot
Sales YOY Growth %
=DIVIDE([Sales YOY Growth], [Sales YOY TOTALS FIXED]
16. Apply Conditional Formatting for visual impact
17. The pivot should look similar to the following screenshot:

18. …and breathe out!!! Well done!!!!


19. Save your work
CONCLUSION
Well Done! You Did It!!!!
You have come a long way and you should be so proud of yourself.
Onwards and upwards my friend. Give yourself a little time to practice – I
highly recommend going through the whole course again BUT trying NOT to
refer to your notes until needs must.
Try to work out the problem first by thinking like the DAX engine and really
asking yourself what exactly you’re asking to be returned.
Cut and Paste an image of the Custom Calendar and working out what you
want your formula to do – just like you did in Ex8 – it really helped me to
consolidate my understanding!
Analysing data and gaining insights is crucial in all industry. DAX Power
Pivot enables Business Intelligence through Data Analysis quickly,
efficiently and, with a little flair and application, you can create dashboard
worthy reports that all managers and stakeholders covet most of all.
Until then, I can’t thank you enough for purchasing my eBook and
completing the course – it means the world to me and I’m SO looking
forward to taking you to the next level - DAX Power Pivot – 10 Easy Steps
for Advanced Users … here we come!
Best wishes
Gilly
SOLUTIONS
Practice Ex1
=CALCULATE([Total Sales],
Total Sales MONTHTODATE DATESMTD('Calendar'[Date]))
=CALCULATE([Total Sales],
Total Sales QUARTERTODATE DATESQTD('Calendar'[Date]))
=CALCULATE([Total Sales],
Total Sales FISCAL 30 June DATESYTD('Calendar'[Date], "30/6"

Practice Ex2
=CALCULATE([Total Sales],
Total Sales PREVIOUSMONTH PREVIOUSMONTH('Calendar'[Date]))
=DIVIDE([Total Sales] - [Total Sales
% Growth MoM PREVIOUSMONTH], [Total Sales
PREVIOUSMONTH])
=CALCULATE([Total Sales],
Total Sales PREVIOUSDAY PREVIOUSDAY('Calendar'[Date]))
=DIVIDE([Total Sales] - [Total Sales
% Growth DoD PREVIOUSDAY],
[Total Sales PREVIOUSDAY])
Practice Ex3
Total Sales =CLOSINGBALANCEMONTH([Total Sales],
'Calendar'[Date])
CLOSINGBALANCEMONTH
Total Sales =CLOSINGBALANCEQUARTER([Total
Sales], 'Calendar'[Date])
CLOSINGBALANCEQUARTER
Total Sales =CLOSINGBALANCEYEAR([Total
Sales],'Calendar'[Date])
CLOSINGBALANCEYEAR
Practice Ex4
Total Sales BETWEEN JUL 2001 =CALCULATE([Total Sales],
DATESBETWEEN('Calendar'[Date],
– JUN 2002 , "30/6/2002"))

% Monthly Sales Growth (First =[Total Sales] / [Total Sales BETWEEN Jul
2001 - Jun 2002]
Year)
Step 5
=COUNT(Customer[CustomerKey])
No of Customers =DISTINCTCOUNT(Sales[CustomerKey])

Practice Ex5
Total Sales of Products with Sales =CALCULATE([Total Sales], FILTER
[Total Sales] > 0 && [Total Sales] < 20000))
but Less than £20,000
Count of Products with Sales but =CALCULATE(COUNTROWS(Products),
FILTER(Products, [Total Sales] > 0 && [Total
Less than £20,000 Sales] < 20000))

Practice Ex8

Das könnte Ihnen auch gefallen