# Input and Result Rules

## Content

This topic supplements the **[SJS.TABLE](/spreadjs/docs/features/what-if-analysis/data-table/sjs-table-function)** function by explaining how the output array dimensions are determined and how input values are mapped to each simulation position.
It focuses specifically on:

* How the size of the spilled result is calculated
* How many simulations are performed
* Which input values are selected for each simulation
* How mismatched input dimensions are handled

These rules apply when working with non-standard result\_reference shapes or when combining multiple inputs of different sizes.

## Dimension Overview

The following table summarizes how the shape of `result_reference` affects the result size and simulation behavior.

| result\_reference Shape | Output Size | Simulation Count | Input Usage |
| ---------------------- | ----------- | ---------------- | ----------- |
| Multi-cell range | Same as `result_reference` | 1 | First value only |
| Single column | Preserve row count; columns = max input columns | Per column | First row of each input |
| Single row | Preserve column count; rows = max input rows | Per row | First column of each input |
| Single cell | Max rows × max columns across inputs | Per output cell | Full positional mapping |

## Examples by Shape

### Base Model (From [Complete Example](/spreadjs/docs/features/what-if-analysis/data-table/sjs-table-function#complete-example-%E2%80%94-two-variable-data-table))

The Predict Table uses:

```auto
=SJS.TABLE(B7, C7:J7, B2, B8:B41, B1)
```

Where:

* `B7` → Net Income (single-cell result\_reference)
* `C7:J7` → Discount values (1 × 8)
* `B8:B41` → Price values (34 × 1)

This model is used to explain the dimension rules below.
All examples use:

```auto
Result formula: =B1*10 + C1
```

### 1\. Single Cell \(Complete Example Case\)

Formula:

```auto
=SJS.TABLE(B7, C7:J7, B2, B8:B41, B1)
```

Shapes:

* `B7` → 1 × 1
* `C7:J7` → 1 × 8
* `B8:B41` → 34 × 1

Result size:

```auto
34 rows × 8 columns
```

Mapping:

* Each row corresponds to one Price value.
* Each column corresponds to one Discount value.
* Each cell recalculates Net Income using:
    * Price = current row value
    * Discount = current column value

This demonstrates full positional expansion.
![image](https://cdn.mescius.io/document-site-files/images/b2223940-43c2-44cf-8eda-f5ab9acd84f0/image-20260416.9f4515.png?width=600)

### 2\. Single Column result\_reference \(Variation of Base Model\)

Assume Net Income is referenced as a vertical range:

```auto
=SJS.TABLE(B8:B41, C7:J7, B2)
```

Behavior:

* Row count (34) is preserved.
* Columns expand to match the 8 Discount values.
* One simulation per Discount value.

Each column represents recalculation under one Discount rate.
![image](https://cdn.mescius.io/document-site-files/images/b2223940-43c2-44cf-8eda-f5ab9acd84f0/image-20260416.fdf9bd.png?width=600)

### 3\. Single Row result\_reference \(Variation\)

Assume a horizontal summary row:

```auto
=SJS.TABLE(C7:J7, B8:B41, B1)
```

Behavior:

* Column count (8) is preserved.
* Rows expand to match 34 Price values.
* One simulation per Price value.

Each row represents recalculation under one Price.
![image](https://cdn.mescius.io/document-site-files/images/b2223940-43c2-44cf-8eda-f5ab9acd84f0/image-20260416.b2be6c.png?width=600)

### 4\. Multi\-Cell result\_reference

If a 2 × 2 result block is used:

```auto
=SJS.TABLE(B7:C8, C7:J7, B2)
```

Behavior:

* Output size remains 2 × 2.
* Only the first Discount value is used.
* Additional input values are ignored.
* Only one simulation occurs.

This case does not produce dimensional expansion.
![image](https://cdn.mescius.io/document-site-files/images/b2223940-43c2-44cf-8eda-f5ab9acd84f0/image-20260416.48b914.png?width=600)

## Matching Rules

* Single-value inputs apply to all simulations.
* Single-row inputs vary by column.
* Single-column inputs vary by row.
* Multi-row and multi-column inputs vary by both row and column.
* Out-of-range positions are treated as empty, and extra input values beyond the required dimensions are ignored.