WISE OWL EXERCISES
SSAS - TABULAR EXERCISES
- Creating a data model (2)
- Excel pivot tables (1)
- PowerView (2)
- Power BI Desktop overview (1)
- Other data sources (1)
- Calculated columns (4)
- Measures (3)
- Changing query context (2)
- The EARLIER Function (1)
- DAX queries (3)
- Date calculations (3)
- Hierarchies (1)
- KPIs (2)
- Perspectives (1)
- Prototyping using PowerPivot (1)
- Security (2)
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.
You can learn how to do this exercise if you attend the course listed below!
- Go into SQL Server Management Studio;
- Open the SQL file you've just unzipped (you can press CTRL + O to do this); then
- 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|
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:
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:
|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:
This can't be right, surely?
You should find that the results are wrong. Edit your relationships to make them filter in both directions:
Edit each relationship so that it shows the symbol shown here.
When you refresh your pivot table, it should show a more sensible result:
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.