Webbo3 Power BI · Cohort 1 · Day 11 of 16 · Lab
Day 11 Lab: CALCULATE Together
Yesterday you learned what CALCULATE does. Today the class builds the measures a manager actually asks for, and checks every one of them.
By the end of today you can
- Build a share-of-total measure with ALL and DIVIDE
- Compare two years with CALCULATE on the Date table
- Work out a growth percentage from two measures
- Answer "how much of it was cash?" for every station at once
- Start the Solo Project with CALCULATE ready to use
A manager never asks for "CALCULATE". She asks: "Which station matters most? Did we grow? How do people pay?" Each question below is one of hers, and each answer is one or two measures.
Same lab rules as Day 4 and Day 9: every number on the checkpoint tables must match your laptop before the class moves on. If yours differs, check the measure first, then the relationships.
1. "Which Station Matters Most?" Share of Total
Definition
A share of total is one part divided by the whole: this station's revenue divided by every station's revenue. The part is [Total Revenue] as the row filters it. The whole is the same measure with the station filter removed, which is exactly what ALL ( Station_Master ) does.
Real-Life Example
Your class scores 400 marks between you and you scored 40. Your share is 40 out of 400, 10%. To work it out you need your own score and the class total at the same time. ALL is how a measure sees the class total while it is standing on your row.
The class build
GRA Filling Station earns 14.8% of everything. The total row says 100%, which is your proof the measure is right: the whole divided by the whole.
Your ALL is on the wrong table. It must match the table the rows come from. If the rows are Sales[StationName] instead of Station_Master[StationName], ALL ( Station_Master ) does not remove that filter. Use the dimension column on your rows, as the star schema intends.
Picture your score beside the class total on the same line of the report card.
2. "Did We Grow?" One Year Against Another
Definition
A year measure is Total Revenue with the year fixed by CALCULATE. Two of them side by side, and a third that divides the difference by the older year, give a growth percentage.
Real-Life Example
Last year you sold 100 loaves a week; this year 120. You grew by 20, and 20 out of the old 100 is 20%. Always divide by the old number: that is what you grew from.
The table is called Date, which is also the name of a DAX function, so Power BI writes it in single quotes: 'Date'[Year]. Type it that way yourself and the formula bar will not complain.
Independence Layout Filling Station grew fastest and Lekki Filling Station slowest. The year filter is on the Date table and the rows are on Station_Master: different columns, so both filters apply, as Day 10's rule says.
Typing the year into the measure works, but next January somebody has to change 2024 to 2025 in every formula. Day 12 teaches time intelligence functions that work out "last year" by themselves.
Picture the loaves: 100 last year, 120 this year, and the 20 divided by the old 100.
3. "How Do People Pay?" A Share Inside Each Row
Definition
This time the whole is not the business, it is the row. Cash revenue at Lekki divided by all revenue at Lekki. No ALL is needed: [Total Revenue] on the row is already "all payment methods at this station".
Real-Life Example
Asking each shop on a street what fraction of today's takings came in cash. Each shop divides by its own takings, not the street's.
POS Share shows that a CALCULATE can sit directly inside DIVIDE. Both styles are correct. The two-measure style is easier to check, because Cash Revenue can go on a card by itself.
Picture each shop on the street dividing its cash by its own takings.
4. "How Many Litres?" CALCULATE on a Different Measure
CALCULATE works on any expression, not only revenue. The operations manager thinks in litres.
Litres grew -5.9% while revenue grew 55.6%. Most of the growth was the price, not more petrol, the same finding as Day 9, now proved in litres.
Summing Quantity across products would add litres of fuel to tins of engine oil, which means nothing. That is why this measure is filtered to one product.
Write Lubricant Share: the share of each station's revenue that comes from lubricants (Product_Master[Category] = "Lubricant"). Put it in the station table. This is the first number behind Alhaji Musa Bello's question about his oil and grease push: which station sells the most alongside the fuel?
Check the total row: it should show 4.5%.
5. "Which Stations Are Dead Weight?" Revenue Against Target
Definition
A target measure works out how much a station should have earned in whatever period the reader is looking at. Station_Master holds a yearly target per station (Day 5), so the target for any period is the yearly figure times the number of days in that period, divided by 365.
Real-Life Example
A savings goal of ₦365,000 a year is ₦1,000 a day. Ask how you are doing after 30 days and the fair comparison is ₦30,000, not the whole year's goal.
COUNTROWS ( 'Date' ) counts the days in the current filter: 365 for 2023, 366 for 2024, 731 for both. That is why the Date table must have every day, not only days with sales.
In 2024, 3 stations beat their target and 4 fell short. The three with the biggest targets are not the ones beating them: a big target is a big expectation, not a big result. That is the first answer to Alhaji Musa Bello's question about dead weight, and it is more careful than "which station earns least".
If the rows came from Sales[Date] instead of the Date table, COUNTROWS ( 'Date' ) would not change with the year and every target would be for two years. Put Date[Year] on the slicer, from the Date table.
6. The Solo Project Is Released
Today you get the Solo Project: PayLink Nigeria, a mobile money network of 41 agents in 10 states. You will clean, model, measure and build its dashboard entirely on your own. It is due on Day 14.
The full brief, the dataset and the marking are on the Solo Project page, the next lesson in this course. Start the Power Query part tonight; Day 12 and Day 13 add what you need for the measures and visuals.
Do This Now
- Build All Stations Revenue and % of All Stations, and check the total row says 100%.
- Build Target and % of Target, set a Year slicer to 2024, and check the table.
- Build Revenue 2023, Revenue 2024 and Growth %, then the growth-by-station table.
- Build Cash Revenue, Cash Share and POS Share, and the payment table.
- Build Petrol Litres by year.
- Do the Try This.
- Download the PayLink dataset and read the Solo Project brief.
Checkpoint
Q1. Why does % of All Stations need ALL, but Cash Share does not?
Share of all stations divides by the business total, so the row's station filter must be removed. Cash Share divides by the row's own revenue, which the row already gives.
Q2. Why is the table written 'Date'[Year] with quotes?
Date is also the name of a DAX function. The quotes tell DAX it is the table.
Q3. Growth is (new minus old) divided by what?
By the old year. Growth is measured from where you started.
Q4. Revenue grew much faster than petrol litres. What does that tell the manager?
Most of the growth came from higher prices, not from selling more.
Tick Before You Move On
- ☐ % of All Stations totals 100.0%
- ☐ Growth % shows 55.6% for the whole business
- ☐ My payment table matches the checkpoint
- ☐ Petrol Litres shows 54,301.7 and 51,107.2
- ☐ I have downloaded PayLink and read the Solo Project brief
Quick Recap
Share of total: the measure divided by itself with ALL on the dimension. Year measures fix the year with CALCULATE; growth divides the change by the old year. A share inside a row divides by the row's own total, so no ALL. CALCULATE works on any expression, such as litres. The Solo Project, PayLink Nigeria, is due on Day 14.
Final Scenario
The managing director has five minutes. She asks which station matters most, whether the company grew, and whether it is worth putting a second POS machine at every pump.
You answer all three from one page: GRA Filling Station is the biggest, revenue grew 55.6% but mostly on price, and POS is already 32.6% of the money, higher at some stations than others.
Every answer was one or two measures. That is what CALCULATE is for.
Next: the Solo Project brief, then Day 12, time intelligence.