WiseOwl Training - Established 1992 Wise Owl Training

Established May 1992
30 years in business
Wise Owl Training
30 years in business
See 529 reviews for our classroom and online training
How to use DAX date-based functions in Analysis Services tabular model
Part six 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.

  1. Creating date-based functions in DAX in SSAS Tabular
  2. Cumulative totals (TotalYTD, DatesYTD, etc)
  3. The same period in a previous month, quarter or year
  4. Using PARALLELPERIOD to get the whole of the last period
  5. Moving averages using DAX date functions
  6. Semi-additive measures in DAX (this blog)

This blog is part of our online SSAS Tabular tutorial; we also offer lots of other Analysis Services training resources.

Posted by Andy Brown on 08 February 2016

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Semi-additive measures in DAX

This page shows how you can use DAX measures to extract opening and closing balances from tables of data.  You can try out the examples on this page by importing this file into your model, and linking the table created to the Species table and Calendar table:

Species balance table

The species balance table contains balances at particular dates.

Note that for the purposes of this blog, it doesn't matter what the balances are!

The problem with opening and closing balances

Nearly all DAX measures aggregate data:

Summing balances

What you get if you sum the balances from the species balance table.

Here's how the figure 66 for amphibians for January 2013 was reached, for example:

Summing individual values

26 + 40 = 66, but sadly your closing monthly bank balance isn't calculated in the same way.


A partial solution - the FIRSTDATE/LASTDATE functions

The FIRSTDATE and LASTDATE functions return the first and last days in any table of dates.  You could therefore use the LASTDATE function to give (for example) the closing balance for any given period:

Halfway closing balance:=CALCULATE(




Except that it doesn't often work!

Opening balances

The answers are a bit sparse! The problem is that for most of the balances there isn't a figure for the last day of the calendar month.


For example, for amphibians the only month for which we get a figure is July 2013, because there just happens to be a balance for this month for the final date in the month:

Closing balance figure for July

There is a balance for 31st July 2013 for amphibians.

A fuller answer using FIRSTNONBLANK and LASTNONBLANK

These two functions give - more usefully - the last non-blank value of a function for a range of dates:


The syntax of the LASTNONBLANK function, for example.


Here's how you could use this expression to get the closing balance for each month for each species:

Closing balance:=CALCULATE(







That is, get the balance from the last date in the calendar table for which there are corresponding rows in the SpeciesBalance table.  

If you're working a lot with opening and closing balances, investigate the ClosingBalanceYear function, and its equivalents for months and quarters (and for opening balances).

This blog has 0 threads Add post