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 Wise Owl course listed below!

Category ==> SSAS - tabular  (29 exercises)
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.

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 and model containing the transaction, pos and staff tables.

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

Create 3 new calculated columns in the staff table:

Staff table with 3 new columns

The staff table in id order, with the 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:

Number of transactions by age

The pivot table shows that (unsurprisingly) the post 1970 generation have processed most sales.

 

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

This page has 0 threads Add post