COUNTIF & FILTER
- The COUNTIF function returns a conditional count across a range;
=COUNTIF(range, criterion)
- The FILTER function returns a filtered version of the source range, returning only rows or columns that meet the specified conditions.
=FILTER(range, condition1, [condition2, ...])
- By combining COUNTIF & FILTER one can FILTER the data across all days based on a
menu
item, then use COUNTIF to count occurrences of aname
in the filtered data.
Named Ranges in Formulas
The formula can be adapted for a LAMBDA function
name | range | note |
---|---|---|
_mealdata | $G$2F2:$P$2O2 |
Range contains menu item for that dayDaily meals data entries |
_namedata | $G$2F3:$P$8O7 |
Range contains unique list of namesDaily names data entries |
_namelist | $A$3A2:$P$8A7 |
Range contains names listed each dayList of names for filtering data |
_meallist | $A$2B1:$P$8D1 |
Range contains a unique list of menu itemsList of meals for filtering data |
First Formula
Formula uses named ranges to make the code easier to manage.
=COUNTIF(FILTER(_names_namedata, _meals=C$2_mealdata=B$1), $B3$A2)
LAMBDA Function
=BYROW(_namelist, LAMBDA(n, MAP(_meallist, LAMBDA(m, COUNTIF(FILTER(_namedata,_mealdata=m),n)))))