Stop 10 · Time IntelligenceTopics · 6/9

DATEADD

Part of the Power BI Roadmap

In short

SAMEPERIODLASTYEAR only goes back a year. Last month, last quarter, two years ago, next month: DATEADD handles them all with one number and one unit.

DATEADD shifts dates by a number of days, months, quarters or years, which makes it more flexible than SAMEPERIODLASTYEAR for previous-month or previous-quarter comparisons.

The jaadu nudges a toy train backwards along a long track divided into coloured sections, counting the sections on its fingers.

Think of it like this

Sliding along the railway track

Your toy train sits on a section of track marked July. Push it back one section and it's on June. Push it back three and it's on April. Push it forward and it's on August. DATEADD slides the selected dates along the calendar by however many steps you say, in days, months, quarters or years.

Watch it happen

Shifting the context with DATEADD

Apr
0
May
1
Jun
2
Jul
3
Aug
4
Sep
5

1/5The visual row is July.

The big ideas

What you need to know

Number and unit

DATEADD ( dates, number, interval ). Negative goes back, positive goes forward. Interval is DAY, MONTH, QUARTER or YEAR.

Shifts the whole range

Whatever dates are in context move together, so it works on days, months and quarters alike.

Same as SPLY for -1 YEAR

DATEADD ( 'Date'[Date], -1, YEAR ) gives the same result as SAMEPERIODLASTYEAR.

Edges of the table

Shifting past the first or last date in your date table returns nothing, so the measure goes blank.

See it in code

Walk through the code

dax
1Sales PM =2CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -1, MONTH ) )3 4Sales PQ =5CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -1, QUARTER ) )6 7Sales 2Y Ago =8CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -2, YEAR ) )9 10Sales Next Month =11CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], 1, MONTH ) )

1/4One month back. The basis for month-over-month comparisons.

Previous month, previous quarter, two years ago and next month from one function.

Save yourself the pain

Common mistakes

Oops

Using DATEADD on Sales[OrderDate].

Do this instead

Use 'Date'[Date]. Gaps in the fact column make the shifted range incomplete.

Oops

Expecting DATEADD ( ..., -30, DAY ) to equal last month.

Do this instead

Months have 28 to 31 days. Use -1, MONTH for month comparisons.

Your mission

Four shifts, one table

~15 min

Quick check

Which expression returns last quarter's sales?

Go deeper

  1. 1Create Sales PM using DATEADD with -1 and MONTH.
  2. 2Create Sales PQ with -1 and QUARTER.
  3. 3Compare DATEADD with -1 YEAR against SAMEPERIODLASTYEAR.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge