Overview
Levenshtein Distance computes the classic edit distance between `string1` and `string2` with a full dynamic-programming matrix. Each cell holds the cheapest way to turn a prefix of one string into a prefix of the other, where an insertion, a deletion and a substitution each cost 1 and a matching character costs 0. `distance` is the value in the final cell. Transpositions are not a single operation, so "ab" to "ba" is a distance of 2, not 1.
The comparison is exact and character-by-character: it is case-sensitive, spaces and punctuation count, and characters are compared as JavaScript string units, so an emoji or other character outside the Basic Multilingual Plane counts as two. Lowercase or trim the strings yourself if you want "Apple" and "apple " to match.
`similarity` is (1 minus distance divided by the length of the longer string) times 100, rounded to two decimals. `matchLevel` is derived from that number: exactly 100 is `exact`, 80 or above `high`, 50 or above `medium`, 20 or above `low`, and anything lower `none`. Because similarity is normalized by length, one edit in a long string scores higher than one edit in a short one; use `distance` when you need an absolute threshold such as "at most two typos".
`string1Length` and `string2Length` are the lengths of the inputs as received, and `string1` and `string2` echo them back; these four fields are null on the Free plan. Computation time and memory grow with the product of the two lengths, so very long pairs take noticeably longer.
Live Test Edit Distance Source →
Formula
One function covers the whole catalog: the first argument names the source, the next are its inputs, and the field after them says which single value lands in the cell. Formulas covers the grammar that applies to all of them.
=VERVE("levenshteindistance", A2, B2, "distance")=VERVE.CALL("levenshteindistance", A2, B2, "distance")A2 holds string1, B2 holds string2. Arguments go in that order — the same order as the table below.
With literal values
Nothing has to come from a cell — typed values work the same way.
=VERVE("levenshteindistance", "kitten", "sitting", "distance")=VERVE.CALL("levenshteindistance", "kitten", "sitting", "distance")Inputs
Required inputs are positional, in the order below, followed by the field. Everything else is passed as a "name", value pair after that — the same shape as SUMIFS. Premium inputs are accepted on every plan but only take effect on plans that include them.
| Input | Type | Where it goes | Description |
|---|---|---|---|
string1Required | string | argument 2 (A2) | First string to compare (max 10,000 characters) |
string2Required | string | argument 3 (B2) | Second string to compare (max 10,000 characters) |
What lands in your sheet
The field — the argument after the inputs — is what makes the formula resolve to one cell. Its value is a dot-path from the table below, so swapping it is how you pull a different value — one formula per column.
Seeing everything at once
Leave the field out and the formula returns the whole response instead: two columns, field name on the left and value on the right, spilling from the cell you typed in.
=VERVE("levenshteindistance", A2, B2)=VERVE.CALL("levenshteindistance", A2, B2)The second row's table would land on top of the first's, and every cell after the first reads #REF! (#SPILL! in Excel). Keep one per sheet, or name a field, and leave the cells below and to the right empty.
Response fields
Paths are relative to data. Each one is exactly what the field argument accepts, so swapping it is how you pull a different value into a cell. On a plan without a Premium field the cell reads #PREMIUM(field) rather than a value, so a locked field never looks like a real answer.
| Use as the field | Type | Example cell value | Description |
|---|---|---|---|
distance | number | 3 | The Levenshtein edit distance between the two strings |
similarity | number | 57.14 | Similarity percentage from 0 to 100 |
matchLevel | string | medium | Similarity level: exact, high, medium, low, or none |
string1LengthPremium | number | 6 | Length of the first string |
string2LengthPremium | number | 7 | Length of the second string |
string1Premium | string | kitten | The first input string |
string2Premium | string | sitting | The second input string |
Filling a whole column
Both platforms make one batched call for a column rather than one request per cell, and both cost the same — 1 credit per row looked up. How you write it differs, because the two runtimes batch at different points.
=VERVE("levenshteindistance", A2:A100, B2:B100, "distance")In Google Sheets, give the arguments ranges and the answers spill down from the cell you typed in. Custom functions there run synchronously and in isolation, so dragged cells cannot be coalesced — the range form is how a column becomes one call. The field is required here: a per-row two-column table has nowhere to spill. Use a full column per input (A2:A100, not A2) — a single-cell reference is read as row 1 only and the rest of the column comes back blank.
In Excel, type the formula once and fill down — no range form and none needed, because its runtime is asynchronous and the add-in coalesces the calls a fill produces into a single batched request. Do not hand VERVE.CALL a range: Excel flattens it into positional arguments, so A2:A100 arrives as a hundred separate arguments and the cell reads #ERR rather than filling.
Either way, column A holds your string1 values and the answers land beside them, one row each, blank rows skipped.
When a cell doesn't fill
A failed lookup returns readable text starting with #ERR rather than a spreadsheet error, because Excel cannot show a custom message on a real error — you would get a bare #VALUE! with no reason. The trade-off is that IFERROR() will not catch it; test with LEFT(cell, 4) = "#ERR" instead. Error handling covers the rest.
| Cell reads | What happened |
|---|---|
#ERR Not connected | No API key saved. Open the side panel and connect your account. |
#ERR Replace <name> with a cell or value | A preview formula was copied as-is. Swap the placeholder for a cell reference. |
#ERR No "x" in levenshteindistance | An option name this source does not take. The message lists the ones it does. |
#ERR No data point "…" | The field path is not in the response. Check it against the table above. |
#PREMIUM(field) | The field exists but your plan does not include it. |
#ERR Out of credits | The cycle's credits are spent. Usage resets on your billing date. |
Before the formula works
The add-in reads the API key you saved once in the side panel — the key never goes in the formula, so a shared sheet does not leak it and a collaborator without access simply sees the last calculated values.
- Install the add-in for Google Sheets or Excel.
- Open the side panel and sign in, or paste a key from your dashboard.
- Type the formula above into any cell.
Use cases
- Spell Checking
- Calculate similarity between misspelled words and dictionary entries
- Fuzzy Search
- Implement approximate string matching for search engines
- Plagiarism Detection
- Measure text similarity for detecting copied content
- Data Deduplication
- Identify near-duplicate records in databases
Other ways to use Edit Distance
Set up Edit Distance on VerveSheets, or reach the same source a different way. Your VerveSheets account and credits work on all of them — one key, one balance.
Related
More in Text Processing: