Brackets and Tiers
Not every chart lists every number. A discount kicks in at fifty parcels. A stamp covers anything up to five pounds. The value only has to fall in the right bracket. This video shows the two Lookup ranges built for that, nearest lower and nearest higher.
On this page
Chapters
Read the docs
Transcript
Show the full transcript
0:00 Intro
Not every chart lists every number. A discount kicks in at fifty parcels. A stamp covers anything up to five pounds. The value only has to fall in the right bracket. This video shows the two Lookup ranges built for that, nearest lower and nearest higher.
0:18 The idea
Think of a loyalty card with tiers. Ship fifty parcels a month and you get five percent off. At two hundred, ten percent. At five hundred, fifteen. Birchwood Bakery shipped a hundred and twenty this month. They've passed the fifty mark, but not two hundred yet. So they get the tier they've reached, five percent. That's nearest lower: the highest step at or below your number. Now think of a postage chart. Up to one pound, four dollars. Up to five, seven fifty. Up to ten, eleven. Up to twenty, eighteen. A parcel goes on the scale, seven point two pounds. It's over five, so the five pound price is too small. The first line that covers it is up to ten, eleven dollars. That's nearest higher: the lowest step at or above your number.
1:06 In your app
In a data table, the tiers go in a table called Volume Discounts. Each row has a From number and a discount. On the Customers table, Birchwood Bakery shows a hundred and twenty parcels this month. The Lookup compares a hundred and twenty with the From column. Every row at or below it is a candidate, zero and fifty. The highest of those is fifty, so the Volume Discount is five. Here are all four customers. Quill Studio shipped eight, so it sits on the bottom tier, zero percent. Zero is a real value here, not empty. Birchwood Bakery, a hundred and twenty, five percent. Pine and Co shipped exactly two hundred. Exactly on the line counts, so ten percent. And Lumen Books shipped six hundred and fifty. The top tier has no upper end, so fifteen percent. The postage chart works the other way. The Weight Chart table has an Up to column and a charge. Parcel P one thousand three weighs seven point two pounds. Nearest higher looks at the rows at or above seven point two, ten and twenty, and takes the lowest, ten. Weight Charge, eleven dollars. Across the parcels: half a pound, up to one, four dollars. Exactly ten pounds, up to ten, eleven. Seven point two, eleven. P one thousand four weighs twenty-five pounds, and nothing on the chart goes that high, so it stays empty. Exactly five pounds, seven fifty. Choosing is easy if you read the chart's heading. If the numbers say where each tier starts, from fifty, from two hundred, use nearest lower. If they say where each line ends, up to five, up to ten, use nearest higher.
2:51 Setting it up
On the Customers table, add a Lookup called Volume Discount. Look up the value in Volume Discounts. Return this field, Discount. This one needs no exact key. Under Range match, pick Nearest lower value. For the column, pick From, against this record's field, Parcels This Month. Save.
3:12 Rules
Three rules to keep track of. Rule one: off the end of the chart, nothing matches. Nearest higher needs a line above the number. A twenty-five pound parcel has none, so the field is empty. Nearest lower needs a step below the number, which is why the discount table starts at zero. Rule two: a number exactly on the line counts. Pine and Co shipped exactly two hundred. Two hundred is at or below two hundred, so they're on the ten percent tier. Nearest higher works the same way: exactly ten pounds is up to ten. Rule three: the range column needs plain numbers. If someone types N slash A, or adds a comma, like one comma two hundred, that row is skipped and never counts as zero. So use a Number field for the column, or keep its text to digits only. So that's brackets and tiers. Nearest lower takes the steps you've reached. Nearest higher takes the first line that covers you. And exactly on the line always counts. Next up: between, for rates that are in effect from one date to another.
Also on Vimeo · the whole series on Vimeo