Overview
Computed attributes create product values from other product data. You can use them for badges, tiers, tags, filters, sorting, merchandising rules, and storefront API responses. Layers supports two ways to create new computed values:- Computed attributes use JavaScript Functions. Choose this when you need custom logic, multiple inputs, templates, previewing, or typed outputs.
- Derived attributes use the visual Derive builder. Choose this when you want to map values from one source attribute to a new value without writing code.
Functions
Functions let you write JavaScript that receives selected product data and returns a typed result. They are best for calculations such as discount percentage, average margin, SKU coverage, inventory health, or multi-field outputs. Use a Function when you need to:- Combine several product fields.
- Work with variants, prices, tags, metafields, or collection titles.
- Preview the result on a real product before saving.
- Return a number, text, true or false, a list, or a group of values.
Derive builder
The Derive builder is a visual interface for deriving an attribute value from another attribute using mapping rules. Use the Derive builder when you want to map values from a source attribute (such as tags or a metafield) to new output values without writing custom logic. For example, you could derive a “Season” attribute from product tags by mapping tag values like “lightweight” and “breathable” to “Summer”, and “insulated” and “thermal” to “Winter”. How to use:1
Select a source attribute
Select the attribute whose values you want to map from, such as product tags, in Source attribute.
2
Choose how to handle matches
Under When more than one rule matches, choose:
- Use first match: Use the output from the first matching rule, checking rules from top to bottom. This is the default.
- Use every match: Return a list containing the output from every matching rule, in rule order.
3
Define mapping rules
Each rule maps one or more source values to an output value:
- Operator: Select Contains, Equals, Starts with, or Ends with.
- Input value: Select or enter one or more values. A match on any value triggers the rule.
- Output: Enter the value to return when the rule matches.
4
Set an optional fallback
In Use first match mode, enter an Otherwise value if you want a result when no rule matches. Leave it blank to omit the attribute for unmatched products.Use every match has no fallback. If no rule matches, Layers omits the attribute for that product.
5
Save the attribute
Once your rules are configured, save the attribute. Layers automatically recalculates all products in the background.
- Case insensitive: Matching ignores letter case. “Summer” and “summer” are treated the same.
- Single or multiple outputs: Use the first match for one label, such as a primary season. Use every match for multiple labels, such as all applicable styles. One rule contributes its output once, even if several of its input values match.
- List filtering: When you use a text list as a filter, each output appears as a separate filter value. Selecting one value includes products whose list contains it.
- Empty results: Layers omits attributes with no value, empty text, or an empty list from product data and filter values.
Automatic product recalculation
When you create a new computed attribute or update an existing computed attribute’s logic, Layers automatically recalculates all products in your catalog in the background. During recalculation, Layers excludes any computed attribute that returns no value, empty text, or an empty list. If an attribute previously had a value and now returns an empty result, Layers removes it from the product data and any associated filter values.Recalculation is triggered when you create a computed attribute or modify its logic. Updates to other fields, such as the attribute name or filterable settings, do not trigger recalculation.
Data access
Functions use an input query to select the product data they can read. See Function input query. Legacy attributes may use older data references.
Platform default computed attributes
The following computed attributes are available by default in the Layers platform:SKU Coverage
SKU Coverage
Description: Ratio between available variants and total variants. For example, a product with 3 of 4 variants available has SKU coverage of 0.75, which the dashboard displays as 75%. Returns no value when a product has no variants.Use case: Identify products with partial variant availability.
Days Available
Days Available
Description: The number of days since the product became available, based on the imported Published At for the product. If no available date has been imported, Layers uses the date the product was created.Use case: Build freshness rules, “new arrivals” groups, and aging product reports.
Has Image
Has Image
Description: Whether the product has a featured image.Use case: Find products that need image cleanup before merchandising.
Age of Newest Variant
Age of Newest Variant
Description: The age of the most recently created variant.Use case: Highlight products with newly added sizes, colors, or variants.
Price Varies
Price Varies
Description: Whether a product’s variants have different prices.Use case: Identify products where variants do not all share the same price.
For current built-in Function templates, see Computed attribute recipes.