SSAS - tabular | Calculated columns exercise | Using COUNTROWS and RELATEDTABLE in calculated columns

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

The answer to the exercise will be included and explained if you attend the course listed below!

Software ==> SSAS - tabular  (29 exercises)
Version ==> SSAS 2012 and later
Topic ==> Calculated columns  (4 exercises)
Level ==> Average difficulty
Course ==> SSAS - Tabular Model
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. 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.

If you haven't already done so, run the SQL script in the above folder in SQL Server Management Studio to generate a database (not for commercial use or copying) called MAM.

Create a new project and model, importing the tables tblCentreType, tblCentre and tblStore.  Create a calculated column in the centre type table to show how many rows there are in the centre table for each type:

Number of stores

The calculated column gives the same answer for every row.

The reason the answer is the same for every centre type is that no account is being taken of the relationship between the tables.  To solve this, use the RELATEDTABLE function to get:

Correct total number stores

The RELATEDTABLE function returns the centres for each centre type which match up by centre type id.

Create another calculated column giving the number of stores for each centre type:

Number of stores

The number of stores for each centre type.


That's it!

This page has 0 threads Add post