# What-If Analysis

## Content

What‑If Analysis is a modeling technique used to evaluate how changes in one or more input values affect the result of a formula.
Instead of manually modifying cells and recalculating repeatedly, What‑If Analysis allows you to systematically explore different scenarios and observe how results respond to varying assumptions.
SpreadJS provides three complementary approaches to perform What‑If Analysis:

* **Data Table Analysis** using the `SJS.TABLE` worksheet function
* **Goal Seek Analysis** using the `GC.Spread.Sheets.CalcEngine.goalSeek` method
* **Scenario Analysis** using workbook-level scenarios managed by `ScenarioManager`

Although these features support scenario‑based evaluation, they serve different purposes and operate differently.

## Data Table Analysis (SJS.TABLE)

`SJS.TABLE` evaluates a result cell or range across multiple input combinations and returns the collected results as a dynamic array.
It is implemented as a standard worksheet formula, which means it:

* Participates in normal worksheet recalculation
* Can be edited, copied, and nested inside other functions
* Automatically spills results into adjacent cells

In addition, `SJS.TABLE`:

* Supports dynamic arrays and inline arrays
* Allows multiple input variables in a single formula
* Supports cross‑sheet references and named ranges

Data Table Analysis is best suited for comparing outcomes across predefined sets of input values.

## Goal Seek Analysis

`goalSeek` is an imperative calculation method that adjusts the value of a specified cell until a formula reaches a desired target result.
Unlike `SJS.TABLE`, Goal Seek:

* Modifies the changing cell directly
* Uses an internal numerical solving algorithm
* Returns a `boolean` or `Promise<boolean>`
* Operates through the CalcEngine API rather than a worksheet formula

Goal Seek is best suited for solving inverse problems, such as determining what interest rate produces a specific payment amount.

## Scenario Analysis

Scenario Analysis saves named sets of input values and applies them to a workbook to compare different business outcomes.
A scenario stores values for one or more changing cells. When a scenario is applied, SpreadJS writes the stored values to the target cells and recalculates dependent formulas. When the scenario is restored, the affected cells are returned to their captured base values.
Scenario Analysis is best suited for comparing named assumptions, such as optimistic, pessimistic, and break-even forecasts.

## Comparison

| Feature | Data Table (`SJS.TABLE`) | Goal Seek (`goalSeek`) | Scenario |
| ------- | ---------------------- | -------------------- | -------- |
| Type | Worksheet formula | CalcEngine API method | Workbook-level scenario state |
| Execution model | Declarative | Imperative | Saved and applied value sets |
| Primary purpose | Evaluate multiple input combinations | Find an input value for a target result | Compare named sets of input assumptions |
| Returns | Dynamic array | `boolean` or `Promise<boolean>` | Applies or restores worksheet values |
| Modifies worksheet cells | No | Yes | Yes, when a scenario is applied or restored |

## Related Topics

| **Topic** | **Description** |
| ----- | ----------- |
| [Data Table: SJS.TABLE Function](/spreadjs/docs/features/what-if-analysis/data-table/sjs-table-function) | Syntax, parameters, and common usage patterns |
| [Data Table: Input and Result Rules](/spreadjs/docs/features/what-if-analysis/data-table/sjs-table-function/input-and-result-rules) | Detailed rules for output size and input matching behavior |
| [Data Table: Performance and Calculation](/spreadjs/docs/features/what-if-analysis/data-table/performance-and-calculation) | Controlling recalculation and monitoring progress |
| [Goal Seek](/spreadjs/docs/features/what-if-analysis/goal-seek) | API reference and solving behavior |
| [Scenario](/spreadjs/docs/features/what-if-analysis/scenario-manager) | Saving, applying, restoring, and managing named scenarios |
| [Excel Compatibility](/spreadjs/docs/features/what-if-analysis/excel-compatibility) | Import and export behavior for What-If Analysis features |

## Using What‑If Analysis in SpreadJS Designer

In SpreadJS Designer, What‑If Analysis tools are available on the What‑If Analysis menu.
Options include:

* Scenario Manager
* Goal Seek
* Data Table

![SpreadJS Designer displays the What-If Analysis menu with Scenario Manager, Goal Seek, and Data Table commands for evaluating worksheet assumptions.](https://cdn.mescius.io/document-site-files/images/b2223940-43c2-44cf-8eda-f5ab9acd84f0/image-20260720.e5b1ae.png?width=800)
For details about the Designer interface and configuration workflow, see [What-If Analysis](/spreadjs/docs/spreadjs-designer-component/spdesignerwork/what-if-analysis-data-table).