Business Intelligence Information Systems · Week 5 · Tableau lab 4 of 5
Why, and what if?
A 70-minute lab in 7 steps. So far every number came straight from a column. Today you create the numbers a manager actually asks for – cancellation rate, lead-time bands, occupancy, net revenue after commission – with calculated fields, and you let the user change the assumptions with parameters. Checkpoints as usual; progress is saved in this browser.
1. Start: two kinds of calculation (5 min)
Open Surname_Lab3.twbx (or reconnect to hotel_bookings.csv). Before the first formula, the one distinction that decides whether a calculation is right:
ROW-LEVELEvaluated once per booking, before aggregation. Uses plain fields: [ADR] * [Nights], IF [Lead Time (days)] <= 7 THEN … END. The result is a new column you can use as a dimension or a measure.
AGGREGATEEvaluated on the marks of the view, after aggregation. Uses SUM, AVG, COUNT…: SUM([Revenue]) / COUNT([Booking ID]). The result changes with what is on the shelves.
THE CLASSIC MISTAKEA ratio is the ratio of the sums, not the average of the ratios: SUM([Profit]) / SUM([Sales]), never AVG([Profit] / [Sales]). Tableau will not let you mix a row-level field with an aggregate in one formula (“cannot mix aggregate and non-aggregate”): that error usually means you forgot a SUM.
Every calculated field is created the same way: Analysis › Create Calculated Field (or right-click in the Data pane › Create › Calculated Field), name it, type the formula, check “The calculation is valid”, OK.
2. The cancellation rate as a field (12 min)
In Lab 2 the cancellation rate was a label on a stacked bar. Now it becomes a measure, so it can be a bar length, sorted, coloured, filtered.
Read it: for each booking 1 or 0 (row-level), summed (aggregate), divided by the number of bookings (aggregate). Valid → OK.
New worksheet. Customer Type to Rows, Cancellation rate to Columns. Sort descending.
Right-click the pill › Format › Numbers › Percentage, 1 decimal. Drag Cancellation rate to Label too.
Do not put a Canceled filter on this sheet – the rate needs both groups.
Swap Customer Type for Distribution Channel, then Deposit Type: the same measure answers three questions. Rename the sheet Cancellation rate and keep Customer Type.
Checkpoint 1
Cancellation rate of Transient customers?
3. Lead-time bands with IF / ELSEIF (10 min)
Lead time is a number with thousands of values. A manager thinks in bands: last minute, this month, this quarter, earlier. A row-level IF turns the number into a dimension.
Create Calculated Field Lead-time band:
IF [Lead Time (days)] <= 7 THEN "0–7 days"
ELSEIF [Lead Time (days)] <= 30 THEN "8–30 days"
ELSEIF [Lead Time (days)] <= 90 THEN "31–90 days"
ELSE "90+ days" END
It appears as a dimension (Abc) because the result is text.
New worksheet. Lead-time band to Rows, Cancellation rate to Columns and Label. The bands are in the wrong order (alphabetical): right-click the band pill › Sort › Manual and drag them into order.
Add Booking ID (Count) to Tooltip so the reader sees how many bookings each band holds.
Rename the sheet Cancellation by lead time. What is the relationship?
Checkpoint 2
Cancellation rate of bookings made more than 90 days ahead?
4. A date function: arrivals by weekday (8 min)
Create Calculated Field Arrival weekday:
DATENAME("weekday", [Arrival Date])
(DATEPART would give 1–7 as a number; DATENAME gives the name.)
New worksheet. Arrival weekday to Columns, Booking ID (Count) to Rows, Canceled to Filters keep No, Hotel to Color.
Tableau already knows the weekday order; if not, sort manually Monday → Sunday.
Rename the sheet Arrivals by weekday. Which day do most guests arrive? Is it the same for both hotels?
Checkpoint 3
How many non-cancelled arrivals were on a Saturday (both hotels)?
5. What if? Occupancy with a parameter (13 min)
Occupancy = room-nights sold ÷ room-nights available. The file has the nights sold, but not how many rooms each hotel has. Instead of guessing inside a formula, we make the number of rooms a parameter the user can change.
Data pane › Create › Parameter. Name Rooms, data type Integer, current value 230, allowable values Range 100–400, step 10. OK.
Nights sold in the mark, divided by rooms × number of distinct arrival days in the mark (≈ days in the month). Format as Percentage, 1 decimal.
New worksheet. Arrival Date to Columns as continuous Month (lower block), Occupancy to Rows, Hotel to Color, Canceled to Filters keep No.
Right-click the Rooms parameter › Show Parameter Control. Set it to 200 and watch the lines. Set it to 230 again.
Add a Reference Line at 1 (100 %) from the Analytics pane. Rename the sheet Occupancy (what-if).
Checkpoint 4
Occupancy of the City Hotel in May 2017 with Rooms = 230?
6. Net revenue after commission (10 min)
Bookings through travel agents and tour operators (channel TA/TO) cost a commission. What is the revenue net of commission, and how does it change if the rate changes?
Create › Parameter: name Commission, Float, current value 0.15, display format Percentage, range 0–0.30 step 0.01.
Create Calculated Field Net revenue:
SUM([Revenue] * (1 - IF [Distribution Channel] = "TA/TO" THEN [Commission] ELSE 0 END))
The IF is row-level (per booking), then everything is summed once. Writing SUM([Revenue]) * (1 - IF …) would mix aggregate and row-level and fail.
New worksheet. Distribution Channel to Rows; Revenue and Net revenue to Columns (two bars per channel, or use Measure Values). Canceled to Filters keep No. Show the Commission parameter control.
Format both as currency, 0 decimals. Rename the sheet Net revenue by channel. Move the slider to 20 %: how much does the hotel lose?
Checkpoint 5
Net revenue of the TA/TO channel at 15 % commission?
7. Groups and sets, then before you leave (12 min)
Two ways to reshape a dimension without a formula: a group merges members into new ones; a set splits members into In and Out by a rule.
Data pane › right-click Market Segment › Create › Group. Select Online TA, Offline TA/TO and Groups › Group › name it Intermediated. Select the rest › Group › Direct & corporate. Name the field Segment group. OK.
New worksheet: Segment group on Rows, Revenue on Columns and Label as Percent of Total (Quick Table Calculation), Canceled = No. Rename Revenue by segment group.
Right-click Country › Create › Set › tab Top › By field, Top 10 by Sum of Revenue › name Top 10 markets. OK.
New worksheet: Top 10 markets on Rows (In / Out), Revenue on Columns and Label as Percent of Total, Canceled = No. Rename Top markets share.
File › Save As › Surname_Lab4.twbx. Export Occupancy (what-if) as PNG. Upload both to eClass before you leave.
Checkpoint 6
Share of realised revenue that comes through intermediated segments?
Checkpoint 7
Share of realised revenue from the top 10 countries?
HOMEWORK (BY NEXT LECTURE, ~15 MIN)
One paragraph in eClass: (1) the occupancy of each hotel in its best month, with the Rooms value you assumed and why; (2) how much net revenue the hotel loses if TA/TO commission rises from 15 % to 20 %; (3) one calculated field you would add next, written as a formula.
Next lecture
Week 6: combine and tell. Relationships between tables (a real capacity table replaces the Rooms parameter; a countries table adds continents), then a dashboard with actions and a published story. Bring your .twbx.