Why Notion Formula at() Function Returns Empty on Valid Array Index
🔍 WiseChecker

Why Notion Formula at() Function Returns Empty on Valid Array Index

You have a Notion database formula that uses the at() function to retrieve an element from an array. The array contains valid data, and the index you pass is within bounds. Yet the formula returns an empty value instead of the expected element. This problem occurs because Notion formula arrays are zero-indexed and the at() function has specific behavior when the index is a number versus a string. This article explains the exact conditions that cause at() to return empty and provides the steps to correct your formula.

Key Takeaways: Fixing the Notion at() Function

  • Index type mismatch: at() returns empty when you pass a string index instead of a number index to an array.
  • Zero-indexing: The first element is at index 0, not 1. Using index 1 returns the second element.
  • Non-existent index: Even if the array has items, an index equal to or larger than the array length returns empty.

ADVERTISEMENT

Why the at() Function Returns Empty on a Valid Array Index

The at() function in Notion formulas extracts an element from an array at a given index. The formula syntax is at(array, index). The function expects the index to be a number. If you pass a string that looks like a number, Notion does not automatically convert it. The index must be a numeric expression, not a text value.

A second cause is zero-indexing. The first element of an array is at index 0. If you write at(["a","b","c"], 1), the result is “b”, not “a”. Users new to zero-indexing often expect index 1 to return the first element and are surprised when the result is the second element. This is not a bug but a design choice shared by many programming languages.

A third cause is an index that is valid in size but refers to a position that does not exist. For example, an array of three elements has valid indices 0, 1, and 2. Index 3 is out of bounds and returns empty. The same happens if the array itself is empty. The at() function has no way to return a value when the index is beyond the last element.

Steps to Correct the at() Function Formula

  1. Check the index type
    Open the formula editor. Look at the second argument of the at() function. If the index is a string like “0” or “2”, change it to a number by removing the quotation marks. Use at(prop("Tags"), 0) instead of at(prop("Tags"), "0").
  2. Verify the index value is zero-based
    If you want the first element, use index 0. For the second element, use index 1. For the third, use index 2. Check your formula against this rule. If you previously used index 1 expecting the first element, change it to 0.
  3. Confirm the array has enough elements
    Use the length() function to get the array size. Write a test formula like length(prop("Tags")) and view the result. If the length is 3, valid indices are 0, 1, and 2. If your index is 3 or higher, reduce it to a valid number.
  4. Test with a static array
    Replace the dynamic property with a static array to isolate the issue. Write at(["a","b","c"], 0) and see if it returns “a”. If it does, the problem is with the source property, not the at() function. If it returns empty, check the formula syntax for typos.
  5. Check for empty array
    If the source property produces an empty array, at() returns empty no matter what index you use. Add a condition with if() and empty() to handle this case. Example: if(empty(prop("Tags")), "No tags", at(prop("Tags"), 0)).

ADVERTISEMENT

If at() Still Returns Empty After the Main Fix

Formula returns empty but the array has items

The property you are using may not be an array. Notion properties like Multi-Select and Rollup can produce arrays. A simple text property does not. Verify the property type in the database schema. If the property is a text or number, wrap it in split() to create an array first. Example: at(split(prop("Tags"), ", "), 0).

Index is a computed number that evaluates to a non-integer

If the index is a formula result, it may produce a decimal like 1.5. The at() function truncates the decimal and uses the integer part. This can cause unexpected empty results if the truncated value is out of bounds. Use floor() or ceil() explicitly to control rounding. Example: at(prop("Items"), floor(prop("Index"))).

Nested arrays cause index confusion

If your property is a rollup that returns an array of arrays, at() extracts the inner array, not a single value. For example, at(prop("Rollup"), 0) returns an array, not a scalar. To get a scalar, use at(at(prop("Rollup"), 0), 0) to reach the innermost element.

at() Function Behavior: Number Index vs String Index

Item Number Index String Index
Example formula at(["a","b"], 0) at(["a","b"], "0")
Result “a” empty
Index type Number Text
Conversion needed None Remove quotes or use toNumber()

The table shows that a string index always returns empty. Notion does not coerce strings to numbers in the at() function. Always pass a numeric value.

You can now identify and fix the three main causes of an empty at() result: a string index, a wrong zero-based index, or an out-of-bounds index. Start by checking the index type and the array length. Use the length() and empty() functions to debug your formula. For nested arrays or computed indices, apply the advanced patterns described above. This approach will eliminate the empty return and make your formulas reliable.

ADVERTISEMENT