SSAS - tabular | Calculated columns exercise | Use the SWITCH function to divide transactions into bands

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  (30 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). Once you've done this:
  1. Go into SQL Server Management Studio;
  2. Open the SQL file you've just unzipped (you can press CTRL + O to do this); then
  3. Execute this script.

This will generate the database that you'll need to use in order to do this exercise (note that the database and script are only to be used for exercises published on this website, and may not be reused or distributed in any form without the prior written permission of Wise Owl).

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.

The aim of this exercise is to categorise staff by age using the following bands:

Year of birth Band
Before the 1960s Has-been
1960s Peak age
1970s onwards Will-be

To start this slightly subjective categorisation, create a new project called Age categories and import the centre, purchase and staff tables.

You'll need to create a relationship manually between the Centre and Staff tables at this point.

Create 3 new calculated columns in the staff table:

3 new columns

The staff table, with 3 new columns giving the name of each member of staff, their birth year and a verdict on their age.

Here are some notes on how to create these columns:

Column Notes
StaffName Use the & symbol to join together the first name, a space and the last name.
YOB Use the YEAR function to get the year for each member of staff, given their date of birth.
Verdict Either use a nested IF function based on the table at the start of this exercise, or (better) use SWITCH.

Now use these columns to show the number of transactions for each age category:

Same count for all ages

This can't be right, surely?

 

You should find that the results are wrong.  Edit your relationships to make them filter in both directions:

Cross-filter direction

Edit each relationship so that it shows the symbol shown here.

When you refresh your pivot table, it should show a more sensible result:

Sales by staff

Because each shopping centre can have more than one member of staff attached to it, the results contain duplicates and don't sum correctly.

 

Save this workbook as But peak agers are still best, then close it down.

This page has 0 threads Add post