564 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
How to use DAX date-based functions in Analysis Services tabular model Part four of a six-part series of blogs |
---|
There are some wonderful date functions in DAX, with evocative names like TotalYtd, SamePeriodLastYear and ParallelPeriod. This blog shows how to use DAX date functions to summarise data, assuming that you have already created a calendar table.
This blog is part of our online SSAS Tabular tutorial; we also offer lots of other Analysis Services training resources. |
The PARALLELPERIOD function returns a set of dates shifted forwards or backwards in time. The easiest way to understand this sentence is by example!
The shaded figures show cumulative sales to date for 2014 (1,490) as a percentage of total sales for the whole of 2013 (9,470).
Here's the formula for the PercentLastYear measure:
PercentLastYear2:=TOTALYTD(
sum('Transaction'[Quantity]),
Calendar[Date]
) /
CALCULATE(
sum('Transaction'[Quantity]),
PARALLELPERIOD(
Calendar[Date],
-1,
YEAR)
)
That is, divide total year-to-date quantity sold by the total quantity sold one year ago.
The measure above shows a divide-by-zero error for 2013 figures, because the previous year's data doesn't exist. One way to get round this would be to use an IFERROR function to trap the error, and return blank:
PercentLastYear:=IFERROR(
TOTALYTD(
sum('Transaction'[Quantity]),
Calendar[Date]
) /
CALCULATE(
sum('Transaction'[Quantity]),
PARALLELPERIOD(
Calendar[Date],
-1,
YEAR
)
),
BLANK()
)
That is, if dividing the year-to-date total sales by the previous year's total sales returns an error, show a blank instead. This would give:
Much better!
Having gone through 3 relatively straightforward tasks, let's now look at something a bit more challenging: displaying moving averages.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.