Learn how to create calculated columns in a tabular model using DAX
Part two of a three-part series of blogs

Creating calculated columns in tabular models is deceptively similar to creating formulae in Excel. Deceptively, because the underlying language (DAX) is completely different, and you can make use of functions like SWITCH which have no Excel equivalent. This blog shows what calculated columns are, and how to create them.

  1. Calculated columns
  2. Using the function wizard (this blog)
  3. Making choices (the IF and the SWITCH functions)

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 05 January 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.

Using the function wizard

Suppose that you want to be able to aggregate transaction volumes by the year in which they occur:

New column

We'll create a column to show the month corresponding to any particular  date.

 

Note that this is actually a bad idea, as it would be much better to do this using a calendar, but a) we haven't covered them in this blog yet and b) this would ruin a nice simple example!

To start with, click on the function wizard tool:

Function wizard tool

Click on the tool shown here.

 

To help you choose the right function, choose a category (it's usually pretty obvious what this should be):

Date and time category

Choose this category to find a function giving the year for any given date.

Find the function you want, and double-click on it:

The YEAR function

Often it isn't as obvious as this!

SSAS Tabular puts the function name in your formula:

The YEAR function

You can now complete the formula by choosing the PosDate field:

 

Here's the final formula you should get:

Final formula for year

I've renamed the column too.

 

For the final part of this blog, I'll show how you can make choices using the IF or the SWITCH functions.

This blog has 0 threads Add post