Skip to main content

Building a grid from another one with GRID()

How to make a grid's prices derive from another one with the GRID() function: a single source for the numbers, no copies drifting apart, and what to do when generation stops with an error.

A grid can read the cells of another grid inside its own generation formula. So, if two services have linked prices (for example “polishing topsides + deck” is the sum of two existing grids), you write the link once: when you change the starting grid, the one derived from it updates with it. The function is written on a grid's page, Settings → Prices lists, products and services → Price grids (detailed pricelist), and is for whoever sets the marina's prices.

1. What it is for

Without GRID() you would have to copy the numbers of one grid into the other by hand, and at the first adjustment the two tables would no longer say the same thing. With GRID() the derived grid holds no numbers of its own: it calculates its cells starting from those of the grid you call.

2. How to write it

GRID() is written in the Generation expression (see Expressions) and has three forms, from the simplest to the most precise:

Form

What it reads

GRID('slug')

The cell of the called grid in the same band and the same column as the one you are calculating.

GRID('slug', 'code=value')

The same band, but the column you indicate: code is the code of a variant of the called grid, value the option's match value. Several pairs are separated by ; ('code=value;other=value').

GRID('slug', 'code=value', band.max)

The row chosen by value: the number you pass as the third argument is classified with the scale of the called grid. Usually you pass band.max, the upper limit of the band you are calculating.

Instead of the slug you can write the grid's numeric id (GRID(27)), but the slug reads better. If you don't want to fix the column but want to indicate the row, write an empty string as the second argument.

A few examples (made-up names):

GRID('polishing-topsides-only') + GRID('polishing-deck-only')
GRID('polishing-complete') * 0.85
GRID('engine-winter-storage', 'engine_count=1') + params.rate1
GRID('engine-winter-storage', 'engine_count=1', band.max) + params.rate1

The result can be combined like any other value: sums, multiplications by a parameter, ROUND(...), IF(...).

The formula with GRID() open in Edit & test

3. Where it works and what it reads

  • Only in generation formulas: the Generation expression (the rate) and the Cost formula. In the other fields (Applicability, Quantity, Unit price, Measure this instead (same bands) and in a scale's expression) there is no cell to start from, and saving is refused with “GRID() can only be used in the generation expression.”.

  • It reads the actual value: if the called grid's cell has a hand-chosen price (the yellow cell) it reads that, otherwise the value generated by the formula.

  • It works at generation time: the derived grid's matrix is built with the called grid's cells as they are at that moment. For this reason the called grid must already have been generated.

  • Try live does not know the other grids: in the editor a formula with GRID() cannot give a result. To see the prices press Generate on the grid and look at the matrix (see The formula editor: scripts and live test).

4. The Slug

Every grid has a Slug, a short name without spaces that the program derives from the grid's name when you create it. You see it in the list of grids and in the Identity and scale box of the page, next to the text to copy, for example GRID('polishing-topsides-only').

The slug stays the same even if you rename the grid, so the references don't break. You can change it by hand in the grid's form (Slug field), but changing it breaks existing references: formulas that use the old slug stop finding the grid. If you clear the field, the slug is derived again from the name. If another identical slug already exists, the program assigns a different one and tells you.

5. Same scale or different scale

Without the third argument the called grid must use the same scale as the one deriving from it: the rows are the same bands and GRID('slug') crosses band by band. Two scales with the same thresholds, but created separately, do not count as the same scale.

You have two ways out, depending on what differs:

  • Change the quantity measured, not the bands. If the two grids have the same bands but measure different things (for example the engine's HP and the tender's HP), keep them on the same scale and give the deriving grid the Measure this instead (same bands) field (see Price grids). It is the simplest route: GRID('slug') keeps working and you don't have to maintain a second scale.

  • The scales are really different. Pass the third argument: the called grid looks for the row with its own scale, whatever it is. For example, a grid classified on the tender's HP that reads the price of a grid classified on engines:

GRID('engine-winter-storage', 'engine_count=1', band.max) + params.rate1

The third argument only works if the called grid has a numeric scale: it does not apply to a dimension class scale nor to a grid without a scale.

6. Regenerating: the cascade

When you press Generate on a grid, the program also regenerates all those that call it with GRID(), in the right order (first the starting grid, then those that derive from it, and so on). A warning lists the regenerated grids: “Also regenerated … dependent grid(s) that reference this one: …”. In the Diagnostics tab of the starting grid the Referenced by these grids box lists them.

A reference that goes round in a circle (A reads B and B reads A, or a grid that reads itself) is not allowed: saving is refused with “Circular GRID() reference: …” and the path of the loop.

If something goes wrong

When you press Generate, if GRID() cannot read the cell generation stops and tells you why: it does not fill the matrix with zeros. The name between quotes in the message is the one you wrote in the formula.

Message

What to do

“GRID('xxx'): no grid with that slug or id.”

Check the slug (or the id): is it the called grid's? It may have been changed.

“GRID('xxx'): a grid cannot reference itself.”

You wrote the slug of the grid you are editing.

“GRID('xxx'): pin the variant "code", e.g. GRID('xxx', 'code=…').”

The called grid has a variant that this one does not: say which column to read in the second argument.

“GRID('xxx'): no matching cell — the referenced grid must be generated first, and it must use the SAME scale as this one (otherwise name the row by value: GRID('xxx', …, band.max)). Column: …”

Generate the called grid first. If it continues, the two grids do not have the same scale: pass the third argument or use Measure this instead (same bands).

“GRID('xxx'): the value … falls outside every band of its scale "…".”

With the third argument: the number passed is outside all the bands of the other grid's scale. Widen its first or last band (see Price scales).

“GRID('xxx'): the row for the value … exists but has no cell in column … — generate the referenced grid first.”

The row is there, the cell is missing: generate the called grid.

“GRID('xxx'): the row value must be a number, got "…".”

The third argument is not a number: use band.max, band.min or a numeric calculation.

“GRID('xxx'): that grid classifies by size class, not by a number, so its row cannot be looked up by value — drop the third argument and use the same scale.”

See above: the third argument does not apply to dimension class scales.

“GRID('xxx'): that grid has a single row (no scale), so there is no row to look up by value — drop the third argument.”

The called grid has no scale: remove the third argument.

These errors do not appear in the Formula diagnostics box, which only checks the parameters and variants used in the formulas (see Checking a grid: diagnostics and regression cases): they show up at generation.


Did this answer your question?