Skip to content
Astera Technology

Count facet choices without their own active filter

Remove only the counted facet’s filter while retaining the other selection.

Download complete case notes and answer keys ↓

Set the decision and its input

The original filter is colour red and sizeM. The colour facet counts options among all sizeM records, temporarily excluding the colour filter itself. The supplied records give red2 and blue1. Keeping red active while counting colour choices misleadingly makes blue0.

Filled local test worksheet
CaseInput JSON
Base test{"facet":"colour","filters":{"colour":"red","size":"M"},"records":[{"colour":"red","size":"M"},{"colour":"red","size":"M"},{"colour":"blue","size":"M"},{"colour":"blue","size":"L"}]}
Download editable CSV ↓

Run the supplied comparison

The executed local function applies the declared facet context. These are counts of choices available under the other filters, not totals for the already-selected red result.

Faulty and required outputs
PathOutput JSON
Faulty path{"counts":{"red":2,"blue":0}}
Required path{"counts":{"red":2,"blue":1}}
Download editable CSV ↓
Complete local Node24.14.1 programme
import assert from 'node:assert/strict';

const run=function run(i,corrected=true){
    if(i.facet!=='colour')return {held:true};
    const eligible=i.records.filter(r=>r.size===i.filters.size&&(!corrected?r.colour===i.filters.colour:true));
    return {counts:{red:eligible.filter(r=>r.colour==='red').length,blue:eligible.filter(r=>r.colour==='blue').length}};
  };
const cases=[{"input":{"facet":"colour","filters":{"colour":"red","size":"M"},"records":[{"colour":"red","size":"M"},{"colour":"red","size":"M"},{"colour":"blue","size":"M"},{"colour":"blue","size":"L"}]},"corrected":false,"expected":{"counts":{"red":2,"blue":0}}},{"input":{"facet":"colour","filters":{"colour":"red","size":"M"},"records":[{"colour":"red","size":"M"},{"colour":"red","size":"M"},{"colour":"blue","size":"M"},{"colour":"blue","size":"L"}]},"corrected":true,"expected":{"counts":{"red":2,"blue":1}}},{"input":{"facet":"colour","filters":{"colour":"red","size":"L"},"records":[{"colour":"red","size":"M"},{"colour":"blue","size":"L"}]},"corrected":true,"expected":{"counts":{"red":0,"blue":1}}},{"input":{"facet":null,"filters":{"colour":"red","size":"M"},"records":[]},"corrected":true,"expected":{"held":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Download runnable example ↓

Choose from the boundary evidence

SizeL retains that filter and yields red0/blue1. An unsupported requested facet is held rather than reusing a colour rule.

  1. Name the facet being counted
  2. Remove only its own filter
  3. Count under retained filters

Do not remove every filter to inflate option counts.

Editable boundary inputs and outputs
ConditionInput JSONExpected output JSON
retain the other facet filter{"facet":"colour","filters":{"colour":"red","size":"L"},"records":[{"colour":"red","size":"M"},{"colour":"blue","size":"L"}]}{"counts":{"red":0,"blue":1}}
unsupported requested facet{"facet":null,"filters":{"colour":"red","size":"M"},"records":[]}{"held":true}
Download editable CSV ↓

What colour counts should the base widget show?

Show the worked answer

Red2 and blue1, because all three sizeM rows remain eligible when only the colour filter is removed.

Related resources