# tables

Named 1-D/2-D lookup tables read by TABLE("name", k1[, k2]) in any expression.

In the model file this key holds a list of `table` entries, each named by its `name`.

A scenario, an experiment or an optimizer can set a field by the path `tables.<name>.<field>`. A data binding can write a field.

## Typical uses

These sections hold the values that expressions read. `variables` are numbers that a model changes while it runs. `tables` are fixed lookups by one or two keys. `timeseries_inputs` are profiles over time, such as a tariff or a demand curve. `entities` describe the entity types: how they look and what holding them costs.

## Behaviour and rules

A variable is read as a bare name in an expression and written by an ASSIGN block. Its `initial` value is restored at the start of every replication. A table is read with `TABLE("name", key)` or with two keys for a 2-D table. The `key_mode` decides what happens between keys: `exact`, `step` or `linear`. A missing exact key is a run-time error unless the table has a `default`.

A time series is read with `TS("name")` for now, or with a second argument for another time. Its `interpolation` is `step` by default, which is exact for a rate. Past the last sample, `beyond` decides whether the last value holds, the series repeats, or the run stops with an error. Sample times must increase.

An entity type is named by the `e_type` of a CREATE block. A `holding_cost` charges each entity for the time it spends in the system, from its creation to its disposal, and only time after the warm-up counts.

## Fields

| Field | Type | Required | Default | Unit | Description |
|---|---|---|---|---|---|
| `name` | string | yes |  |  | The table's name, the first argument of TABLE("name", key). |
| `description` | string |  |  |  | What the table holds; the run does not read it. |
| `keys` | list of string or number | yes |  |  | Row keys (dimension 1). |
| `columns` | list of string or number |  |  |  | Column keys (dimension 2); omit for a 1-D table. |
| `values` | list of number or list of number | yes |  |  | One number per key (1-D), or one row of numbers per key (2-D). |
| `key_mode` | choice |  | `"exact"` |  | exact (the key must be present), step (largest numeric key &lt;= x) or linear (interpolate); step and linear clamp at both ends. One of `exact`, `step`, `linear`. |
| `column_mode` | choice |  | `"exact"` |  | How a lookup treats a column key between the listed ones: exact match, the step below, or linear. One of `exact`, `step`, `linear`. |
| `default` | number or null |  |  |  | Value for a missing exact key; without one a miss is a run-time model error. |

A field of a nested object is described in the JSON Schema (`naga schema`).

## Example

```json
{"tables": [{"name": "Speed", "keys": [1, 2, 3], "values": [10, 8, 6]}]}
```

In the Python builder:

```python
from nagasim import build as nb
m = nb.Model()
m.add_table(name='Speed', keys=[1, 2, 3], values=[10, 8, 6])
```

## Used in

Bundled models: [Hub day: electrifying the ground support equipment](../../gallery/logistics.md), [Hub day: turnaround workload (crews, ground equipment, on-time departures)](../../gallery/logistics.md), [Job shop (routed, per-product sequences)](../../gallery/manufacturing.md), [Job shop with MES digital twin](../../gallery/manufacturing.md), [Process time lookup table](../../gallery/teaching.md).

Guides: [Agent-based modelling](../../agent-based-modelling.md), [Coming from AnyLogic](../../coming-from/anylogic.md), [Coming from Vensim](../../coming-from/vensim.md), [How do I total a subscripted value and remember a past one?](../../how-to/recipes/regions-memory.md), [Model file format](../../model-file-format.md), [Expressions and variables](../../modelling-guide/expressions-variables.md) and 1 more.

## See also

- [All sections](index.md), [Model file keys](../schema.md), [Model file format](../../model-file-format.md)
