Formula Editor

Formula Editor

Overview

The formula editor appears throughout the calculator editor wherever a calculation is needed — option pricing, variables, fixed fees, price adjustments, weight, and the total price formula. You can find formula fields in Calculator Editor → Options & Pricing. Each formula editor has four modes accessible via tabs at the top: Manual (type formulas directly), Describe with AI (generate a formula from plain English), Explain formula (get a plain-English breakdown of an existing formula), and Troubleshoot (run the formula for a set of choices, see the value of every part, and find out why the result is not what you expected).

Quick Reference

Value Accessors

These functions pull values from options, variables, and tables into your formulas. All string arguments must use double quotes — OPT("WIDTH") is correct, OPT(WIDTH) is not.

Function Description
OPT("KEY") The option's computed value — the result after any formula on that option has run. For switch options, returns TRUE or FALSE.
OPT_TOKEN("KEY") The selected Choice Token for a dropdown/radio/button/swatch (not the display label). Use this with TABLE() lookups (as a row key and/or column key) or IF comparisons. Empty when nothing is selected.
INPUT("KEY") The raw value the customer entered. Only works for numeric-like options: number, slider, length, area, volume, and weight. Not for quantity — use OPT("KEY") for the resolved count.
INPUT("KEY", "dim1") A single dimension from a dimensions option. Use the stable tokens "dim1", "dim2", "dim3" for each dimension in order.
INPUT("KEY", "area") Total area of a Room map option. 0 until each counted room is closed. Also "perimeter" (all walls, including open rooms) and "rooms" (rooms with at least one wall length). There is no per-wall token. OPT("KEY") is the option price, not the area.
VAR("KEY") A calculator variable defined in the Variables section. Also: VAR("BASE_PRICE") — your Initial Price base in dollars (fixed or variant). System / product variables: VAR("SHOPIFY.PRICE"), VAR("SHOPIFY.UNIT_PRICE"), VAR("SHOPIFY.QUANTITY"), and VAR("META....") metafield aliases where configured.
HAS("OPTION_KEY", "CHOICE_KEY") Returns TRUE when a choice option (dropdown, radio, button, checkbox group, swatch, image swatch, switch) has the specified value selected.
COUNT("OPTION_KEY") The number of selected values (0 to N) in a multi-select option such as a checkbox group.
CHARCOUNT("KEY") The character count of a text or textarea option's input. Use this instead of LEN(INPUT(...)).
TABLE("name", key) / TABLE("name", rowKey, colKey) Looks up a value from a pricing table. One key for one-column (key→value) tables; row + column keys for multi-column grids. Keys can be numbers (INPUT) or Choice Tokens (OPT_TOKEN). Optional fourth argument sets match mode: "exact", "nearestLower", "nearestUpper", "nearest", or "interpolate" (one-column numeric tables).

OPT vs. OPT_TOKEN vs. INPUT: Use INPUT for the raw entered value (dimension math, unit conversions). Use OPT for the option's computed / priced result after its own formula has run. Use OPT_TOKEN for the selected Choice Token when looking up or comparing choices — never use OPT as a table key for dropdown/radio/button/swatch options.

Capitalization does not matter for names. Option keys, variable names, pricing table names, Choice Tokens in HAS, and dimension names in INPUT("KEY", "dim1") match regardless of case: OPT("area"), OPT("Area"), and OPT("AREA") all read the AREA option, and TABLE("pricing", …) finds a table named Pricing. If two names differ only by case, the exact spelling wins. Function names are case-insensitive too.

Operators

Operator Description
+ - * / Add, subtract, multiply, divide
% Modulo (remainder)
^ or ** Exponent (power)
== != Equal, not equal
< <= > >= Comparison
&& Logical AND
|| Logical OR
( ) Group expressions to control evaluation order

Functions

Logic

Function Description
IF(condition, then, else) Returns then when condition is true, otherwise else.
AND(a, b, ...) Returns TRUE when all arguments are true.
OR(a, b, ...) Returns TRUE when at least one argument is true.
NOT(x) Returns TRUE when x is false, and vice versa.

Math

Function Description
ABS(x) Absolute value of x.
MIN(a, b, ...) Returns the smallest value.
MAX(a, b, ...) Returns the largest value.
CLAMP(x, min, max) Bounds x between min and max.
SQRT(x) Square root of x.
POWER(x, y) / POW(x, y) Raises x to the power of y.
EXP(x) e raised to the power of x.
ROOT(x, n) Nth root of x.
SIGN(x) Returns -1, 0, or 1 depending on the sign of x.
SUM(a, b, ...) Adds all arguments. Non-numbers are treated as 0.

Rounding

Function Description
ROUND(x, n) Rounds x to n decimal places.
CEILING(x) Rounds x up to the nearest integer.
FLOOR(x) Rounds x down to the nearest integer.
TRUNC(x, n) Truncates x to n decimal places without rounding.

Text

Function Description
LEN(text) Number of characters in text.
CONCAT(a, b, ...) Concatenates values together as a string.

Details

Manual Mode

The default mode. Type your formula directly into the editor. The formula is checked as you type, the calculator's live Preview column shows the resulting price, and the Troubleshoot tab shows the value of each part. The editor supports autocomplete — as you type, it suggests option keys, variable names, and function names.

Describe with AI

Switch to the Describe with AI tab to generate a formula from a plain-English description:

  1. Click the Describe with AI tab (sparkle icon) above the formula field.
  2. Describe what you want the formula to do in plain English — for example, "charge $2.50 per square foot with a $25 minimum."
  3. Click Generate. The AI produces a working formula using the correct syntax and your calculator's option keys.
  4. Review the generated formula and accept it, or refine your description and generate again.

The AI uses your calculator's current options and variables as context, so it can reference them by name.

Describe with AI writes formulas only. A dollar extra (“Rush is $15”) belongs in the formula. A store product you want added to the cart (hanger, gift wrap) is an add-on product — link it on the choice with Add to cart. Do not also put that product’s price in the formula. Which names appear on the cart line is Cart properties, not a formula.

Explain Formula

Switch to the Explain formula tab when you have an existing formula you want to understand:

  1. Click the Explain formula tab above a formula field that already contains a formula.
  2. The AI reads the formula and returns a step-by-step plain-English explanation of what it does and how it evaluates.

This is useful when reviewing formulas written by someone else, or when revisiting a complex formula you wrote previously.

Troubleshoot

Switch to the Troubleshoot tab when a formula returns a number you did not expect — a table lookup that comes back as 0, a surcharge that never applies, a total that is off. The tab runs the formula with the same engine the storefront uses and shows you what every part of it is worth, so you can see exactly where the number goes wrong.

  1. Click the Troubleshoot tab above the formula field.
  2. The Scenario is the live Preview. Whatever a customer has chosen in the preview is what the tab evaluates, and everything re-evaluates by itself whenever a choice changes — there is nothing to click. You can change a choice in either place: pick it in the preview, or use the same controls in the tab and watch the preview follow. The option this formula prices is listed first, then the options the formula reads; click Show all options to see the rest. Choice pickers show the label and its Choice Token, because that token is what OPT_TOKEN(), HAS() and table lookups use. Reset to storefront defaults puts the preview back to what a customer sees when the page loads.
  3. A field you cannot change is one the storefront would not let the customer change either, and the tag under it says why: Hidden until Surface finish is Planar or Hidden while Finish is Gloss names the visibility rule and the choice that controls it, Hidden with the eye toggle means the option is hidden in the editor, and Set by rule to 7 while Finish is Gloss means a value rule is filling it in. When a value rule adjusts something you just typed — or changes another option because of what you picked — the tab tells you what it set and why.
  4. Type the number you expected in I expected whenever you know it. The tab compares it with what the customer actually sees: the formula result (after the option's Rate, for an option formula), or — when the storefront does not use this formula in this scenario — the price the storefront charges for the option instead. It also searches for that number: if it sits in a cell of a table the formula reads, or is what another choice or the quantity would give, the tab says so under the issue — 1618.92 is the value at row 2500, column 3000 of "planar"; this lookup used column 2300 and found nothing — and uses it to pick the fix.
  5. Read Likely issues first. They come in three groups you can open or close: Problems (wrong whatever the customer picks — a Choice Token that matches no table row, a misspelled table mode), Check (worth a look — an empty table cell, an out-of-range value, a hidden option that the number you expected points at), and In this scenario (the calculator working as designed for these choices: options hidden by a visibility rule — they price as 0, which is what you want when a formula adds up options that show one at a time — options with nothing selected, empty inputs). Problems and Check start open; In this scenario starts collapsed with a one-line summary — 12 options hidden for these choices · 1 with nothing selected — so a large calculator does not bury the real issues under a dozen notes. Closing a group leaves that summary on the header, and the open or closed state is remembered while the calculator stays open. When every option the formula reads is hidden, that is one Check — the matching hidden-option notes are not listed again. Open In this scenario to see each option with the rule that hides it, a Select … link when one choice would show it (including a hide-when rule with two choices), and an arrow to its step. Visibility rules with more than one condition offer Open … → Visibility instead of a one-click flip. Each problem has a one-line title that names the exact thing that is wrong — Width: the choice "3000" has Choice Token "2300", which is not a column in "planar" — one sentence on what happened, and a Fix block with the smallest change that solves it. When the change is a Choice Token, the block has a button that applies it for you (Set token to "3000") and the preview keeps the same choice selected; other fixes open the option or the table. Other ways to fix lists the alternatives (for example adding the missing column instead), and long key lists sit behind Show 20 columns so the sentence stays short. The fixes are ranked by how much you would have to change: one choice out of step with its table points at that choice's token; a whole table built from labels points at the table. Issues cover a Choice Token that does not match a table row, OPT() used where OPT_TOKEN() was meant, INPUT() on a quantity option (always 0), a table mode that misses keys between tiers (with what each other mode would return), a Rate other than 1 multiplying the formula, or an IF whose condition is never true for this scenario. For an option formula the tab also tells you when the storefront would not use the formula at all in that scenario — the option has nothing selected, the value is out of range, a visibility rule (named) or the eye toggle hides it, a different choice is selected, or a value rule replaces the result. The result block then shows what the storefront charges for the option, the reason in one sentence, and what this formula would return if it applied. When you opened the formula of a choice that is not selected, the tab says which choice is selected instead and one click selects this one — in the preview too.
  6. Step by step starts closed. Open it to walk the formula from the outside in. Each row is one part of the formula with its value; rows inside an IF show whether that branch was taken, and table lookups show the row and column that were tried, whether they hit, and the closest keys when they missed. The circled chevron beside an issue's title opens Step by step, scrolls it into view, and highlights the step it came from.
  7. Click Explain this result for a short plain-English write-up of the likely cause and the fix. Write-ups stack under the button for as long as the calculator is open: when you change a choice in the preview, the write-up folds to one line (time, first sentence, and the result) instead of disappearing. A short Current tag marks the write-up that matches the choices in the preview. Click a line to read it again, or use Put those choices back to put the preview back to exactly those choices (later picks are not kept). They are not saved with the calculator — closing the editor clears them.

Two shortcuts open this tab for you:

  • Price looks wrong? under the price in the live Preview column opens the Total Price Formula's Troubleshoot tab for the exact choices the preview is showing.
  • Tell Chat with AI that a price or formula is wrong ("Large with rush should be $12 but shows $9", "the Rush fee never adds for 25 pieces") and it opens the Troubleshoot tab for that formula with a note on what to check first. When you describe the case, the chat puts those choices into the preview and fills in the price you expected.

The tab reads your current draft, so you can change the formula, a Choice Token, a table, or a rule and see the new result immediately — nothing is saved until you save the calculator.

AI Credits

Describe with AI, Explain formula, and the Explain this result button on the Troubleshoot tab consume AI credits from your plan allowance. The rest of the Troubleshoot tab — the scenario, the step-by-step values, and the likely issues — runs in your browser and is free. Simple requests use fewer credits than complex ones. Monitor your usage on the Subscription page.

Examples

Area-based pricing — multiply two dimension inputs to get square footage, then apply a rate:

INPUT("WIDTH") * INPUT("HEIGHT") * 0.50

Dimensions option — calculate area from sub-dimensions and convert square inches to square feet:

INPUT("DIMENSIONS", "dim1") * INPUT("DIMENSIONS", "dim2") / 144

Room map — charge per square foot of closed rooms, with 10% waste:

INPUT("ROOM", "area") * 1.1 * 4.50

Using a variable — reference a calculator variable in the total formula and add option contributions:

VAR("AREA") * 50 + OPT("MOTOR") + OPT("FINISH")

Conditional pricing with HAS — charge a premium rate when a specific material is selected:

IF(HAS("MATERIAL", "PREMIUM"), VAR("AREA") * 1.25, VAR("AREA"))

Table lookup — pull a per-square-foot rate from a pricing table:

TABLE("price_per_sqft", INPUT("WIDTH"), INPUT("HEIGHT"))

One-column table lookup — key→value material rate keyed by Choice Tokens (column header can be omitted when there is only one value column):

TABLE("materials", OPT_TOKEN("MATERIAL"))

Multi-column lookup with a Choice Token column key — numeric size in the blue column, material tokens across the green header row:

TABLE("sheet_prices", INPUT("SIZE"), OPT_TOKEN("MATERIAL"))

Table lookup with interpolation — linear interpolation on a one-column numeric table (mode as the fourth argument when a column key is present):

TABLE("rates", INPUT("LENGTH"), "Price", "interpolate")

Minimum price enforcement — set a $25 price floor:

MAX(25, OPT("QTY") * 2.50)

Multi-select surcharge — add $5 for each topping selected:

COUNT("TOPPINGS") * 5

Per-character pricing — charge per character of engraving text:

CHARCOUNT("ENGRAVING_TEXT") * 0.75

OPT vs. INPUT — INPUT("LENGTH") is the raw number the customer typed, while OPT("FINISH") is the dollar amount computed by the Finish option's formula:

INPUT("LENGTH") * 2 + OPT("FINISH")

Shopify variant price — start from the storefront variant price and add option contributions:

VAR("SHOPIFY.PRICE") + OPT("SIZE") + OPT("COLOR")

Calculator initial price (base) — same idea using the configured Initial Price (fixed or variant) via VAR("BASE_PRICE"):

VAR("BASE_PRICE") + OPT("SIZE") + OPT("COLOR")

See Initial Price (Base Price) for when to prefer BASE_PRICE vs SHOPIFY.PRICE.

Describe with AI — You type: "Price is width times height times $3.50 per square foot, minimum $50." The AI returns: MAX(50, INPUT("WIDTH") * INPUT("HEIGHT") * 3.50).

Explain formula — You paste IF(HAS("FINISH", "MATTE"), VAR("AREA") * 4.25, VAR("AREA") * 3.75) and switch to Explain formula. The AI responds: "If the Finish option is set to Matte, multiply the area by $4.25; otherwise multiply by $3.75."

Troubleshoot — The preview shows $0 for a 3000 × 2500 sheet. You click Price looks wrong? (or open the formula's Troubleshoot tab) and type 1618.92 in I expected. Likely issues names the problem: Width's Choice Token is 2300, which is not a column in the planar table. The Fix block offers Set token to "3000"; after you click it, the preview shows $1618.92.

    • Related Articles

    • Total Price Formula

      Overview The Unit price calculation / Total price calculation field (this section is titled Total Price Formula in the nav) is the main place you define how the line price is computed from options and base. You can also set minimum and maximum price ...
    • Calculator Editor Overview

      Overview The calculator editor is the main workspace where you build and customize your product calculator. It is divided into three areas: a header bar at the top, a tabbed main panel in the center, and a live preview panel on the right. Together, ...
    • Customer access and layout (editor profiles)

      Overview The editor profile controls how much a customer can change inside the editor and how the design relates to the artboard. You set it in Calculator Editor → Step 5 (Designer) → gear icon → Storefront editor settings → Customer experience, ...
    • Pricing Variables

      Overview Pricing variables are named, computed values that act as intermediate steps in your pricing logic. Instead of writing one large formula, you can break the calculation into smaller, readable pieces — each stored as a variable — and reference ...
    • Weight Calculation

      Overview Weight calculation lets you define a formula that computes a product's shipping weight based on customer selections. The calculated weight is saved with the order so your shipping provider can use it to quote accurate rates. You configure it ...