Scales and grids are configured by writing small expressions (formulas) in text boxes. You don't need to know how to program: they are formulas similar to those of a spreadsheet. This article explains what you can write, where, and the mistakes to avoid.
The most important point: the “context”
The available variables depend on WHERE you write the expression. Each box has its own set of allowed variables. Writing one that is not allowed in that box makes the formula fail (and today the system refuses to save an expression with disallowed variables or syntax errors).
Box | Where | Allowed variables |
|---|---|---|
Value expression | Price scale | only |
Generation expression | Grid (fills the matrix) |
|
Cost formula | Grid (fills the costs) |
|
Applicability | Grid |
|
Quantity | Grid | as Applicability, plus |
Unit price | Grid | as Applicability, plus |
Mistake number one: in the generation formula boat.* / engine.* / generator.* do NOT exist. The formula runs once for each cell, before it even knows the boat — so it can only use the band (band.*), the columns (variant.CODE), the parameters (params.CODE) and the previous band (prev). To differentiate the price by fuel or number of engines, don't write engine.fuel: create a variant (column) and use variant.fuel. See below.
What the variables mean
boat.*— boat data:boat.length,boat.width,boat.mq,boat.draught,boat.displacement,boat.type_class,boat.air_conditioning,boat.desalinator,boat.tender_type…engine.*— engine:engine.count(number of engines),engine.hp,engine.fuel,engine.transmission.generator.*— generators:generator.kw_max(the largest), etc.period.*— the period chosen when quoting, available in two counts: by days (period.days,period.weeks,period.months,period.calendar_months,period.years) and by nights (period.nights,period.night_weeks,period.night_months,period.night_calendar_months,period.night_years). Days count both ends (from the 1st to the 15th = 15 days), nights exclude the departure day (from the 1st to the 15th = 14 nights): choose the count by which you sell the service. The weekly/annual marina grids useperiod.weeks/period.yearsfor the pro-rata quantity. They are all decimal values (pro rata).Beware of the two kinds of month.
period.monthsandperiod.night_monthsdivide by an average month of 30.42 days: from 1 October to 30 April is 212 days, so the count gives 6.97 and not 7 (winter is shorter than the average). If the service is sold by the month — winter storage, monthly mooring — useperiod.calendar_months(orperiod.night_calendar_months), which counts months on the calendar: the same period makes exactly 7.00. Whole months are exact, and only the leftover days are pro rata on the month they fall in (from 15 October to 20 December = 2 + 6/31 = 2.19).A note on the “Try live” button: there you enter a number of days, not a period with dates, so there is no calendar to read and the calendar months show the average-month value (6.97 over 212 days). On the real quote the value is the right one (7.00).
band.*— the row's band during generation:band.index(1, 2, 3…),band.min,band.max.variant.CODE— the column's value (e.g.variant.fuel,variant.engine_count), using the codes you defined in the Variants.params.CODE— your parameters (e.g.params.eur_per_mq).prev— the value generated for the previous band (to make prices grow row by row).cell.value— the price found in the matrix for that boat (in Quantity and Unit price; in the Cost formula it is the price of the same cell).cell.cost— the purchase cost of the same cell, readable from the rate's generation formula;cell.valueis the reverse, readable from the Cost formula (one direction at a time). See Purchase costs and margin in price grids.carry.*— the values of the previous band's variables, see “Multi-line scripts” further below.customer.*— the contract's customer (category and type):customer.category,customer.category_name,customer.type,customer.type_name. In marina grids.season.*— the season crossed:season.name,season.index.contract.*— the contract:contract.type,contract.type_name,contract.durationand the flagscontract.is_transit,contract.is_rent,contract.is_seasonal,contract.is_daily,contract.is_monthly,contract.is_yearly.resource.*— only in marina grids: the dimensions of the berth (the mooring), read when you price by the mooring's dimensions instead of the boat's.
The functions
There are eleven: the ten below plus GRID(), which reads the price of another grid (see Building a grid from another one with GRID()).
Function | Meaning |
|---|---|
| If… then… otherwise. |
| The smallest / the largest of the values. |
| Rounds (to 0 decimals by default). |
| Rounds up / down. |
| Absolute value. |
| True if all / if at least one / negation. |
Operators: + - * /, comparisons == != < <= > >=, AND / OR / NOT, parentheses and ** for exponentiation. Strings go between double quotes: "DIESEL".
The “Available fields & functions” help
Under each expression box there is the “Available fields & functions” button (magic wand icon). When you open it you find:
clickable chips: clicking a field (e.g.
boat.length), a function (e.g.IF() or a grid-specific token (e.g.variant.fuel), the token is inserted at the cursor of the last box you clicked;a legend with the meaning of each variable and the “Available in” column that says in which boxes it can be used;
ready-made examples: clicking an example, the whole expression is inserted into the active box.
Click first inside the box you want to fill in (so it becomes the “active” one), then click the chips.
To work full page, with the test data and a result that updates by itself, use the Edit & test button on the grid's page: see The formula editor: scripts and live test.
Examples (with the rule in words)
Scale — value expression
Rule | Expression |
|---|---|
Classify by surface |
|
Classify by engine power |
|
Grid — generation formula
Rule | Expression |
|---|---|
Price per HP, but never below a minimum |
|
Scales with the number of engines |
|
First band = base, each following band = previous +X% |
|
Grid — applicability (must give true/false; if false the line is skipped)
Rule | Expression |
|---|---|
Only diesel, not outboard |
|
Only sailing boats |
|
Grid — quantity / unit price (for time-based services)
Rule | Expression |
|---|---|
Storage by day bands (quantity) |
|
Daily rate from monthly price (unit price) |
|
Monthly × months, with annual cap (unit price) |
|
Unit price. When you set it, it always applies: the value it returns becomes the final unit price (e.g. cell.value * boat.mq for a rate at €/m²).
A phrase instead of the price. The Unit price can return text between double quotes, for example "Final account": the line is added at zero and the quote prints that phrase instead of the price. It only works on order lines: on a contract the line would enter at zero without a phrase. In the grid test the price is shown as printed instead of the price.
The typical mistake in generation (wrong → right)
❌ Wrong:
IF(engine.fuel == "DIESEL", band.max*10, band.max*12)—engine.*does not exist in generation.✅ Right: add a
fuelvariant with optionsDIESEL/PETROL, then writeIF(variant.fuel == "DIESEL", band.max*10, band.max*12).
Multi-line scripts
When a single line becomes unreadable you can write several lines: you assign a value to a variable (base = band.max * params.eur_per_hp), use if (…) { … } else if (…) { … } else { … } and close with return. Comments start with # or //. If you don't write return, the last expression counts. A one-line expression keeps working as it is.
base = band.max * params.eur_per_hp
if (band.max <= params.hp_threshold) {
base = params.fixed_cat1
}
return base * variant.engine_countBand after band (prev and carry). In the generation formula the grid calculates one band at a time, in order. prev is the final result of the previous band (0 on the first). carry.name is the value that a variable name had in the previous band: it is needed when what grows is an intermediate value (for example a €/m² that rises by 2% at every band) and not the final result. On the first band carry is empty: start with if (band.index == 1).
if (band.index == 1) {
rate = params.base_rate
} else {
rate = carry.rate * (1 + params.incr)
}
return rate * band.maxTo write and try a script comfortably see The formula editor: scripts and live test.
Allowed values
The categorical fields (boat type, fuel, transmission, tender type) accept only fixed codes, exact and case-sensitive: DIESEL is different from Diesel. The “Allowed boat field values” page (the “See the allowed values for categorical boat fields” link from the variant and from the grid view) lists, for each field, the Code (use this) column and the Label (descriptive only). Always use the Code from the left-hand column.
Field | Allowed codes |
|---|---|
|
|
|
|
|
|
|
|
The numeric fields (boat.length, boat.width, boat.mq, boat.displacement, engine.count, engine.hp, generator.kw_max…) accept any number. The Yes/No fields (boat.air_conditioning, boat.desalinator) are 0 or 1, except the insurance waiver of recourse boat.insurance_waiver_recourse, which is a code: "YES", "NO" or "UNKNOWN" (not specified). So write boat.insurance_waiver_recourse == "NO", never == 0.
The waiver of recourse (the “Insurance waiver recourse” field of the boat sheet: Unspecified / No / Yes) can decide whether a grid applies (boat.insurance_waiver_recourse == "NO" in Applicability), which column it reads (a variant with one option per code) or how much it charges (for example cell.value * IF(boat.insurance_waiver_recourse == "YES", 1, 1.15) in the Unit price). It is always read from the boat; boats registered earlier may have “No” by default: check before using it in prices.
Beware of the SAIL BOAT code: it contains a space and is in capitals.
If you get it wrong
An unclosed quote or a syntax error blocks saving the grid, with an error message.
Pressing “Generate” with an invalid generation formula, the system reports the error instead of filling the matrix with zeros.
An invalid expression in applicability/quantity/price does not break the page: it simply skips the line with a reason.
If you prefer, have the formula written from a description in words: see the article Writing a formula with Marin.AI.
