all

all, aggregator

def nosort process all(value: boolean): boolean default true

Returns true iff all the boolean values in the group value are true. If the group is empty, returns true.

Examples

Basic usage

table T = with
  [| as Id, as IsValid |]
  [| "a",   true       |]
  [| "b",   true       |]
  [| "c",   true       |]

allValid = all(T.IsValid)

// true
show scalar "All valid?" with allValid

Grouping by category

table Products = with
  [| as Category, as Product, as InStock |]
  [| "fruit",     "apple",    true       |]
  [| "fruit",     "banana",   true       |]
  [| "fruit",     "cherry",   false      |]
  [| "veg",       "carrot",   true       |]
  [| "veg",       "potato",   true       |]

table Categories[cat] = by Products.Category

Categories.AllInStock = all(Products.InStock)

show table "Stock status by category" with
  cat
  Categories.AllInStock

This produces the following table:

cat AllInStock
fruit False
veg True

With empty groups

table T = with
  [| as Category, as IsValid |]
  [| "A", true  |]
  [| "A", true  |]
  [| "B", false |]
  [| "C", true  |]

table Categories = with
  [| as Category |]
  [| "A" |]
  [| "B" |]
  [| "C" |]
  [| "D" |] // No data for this category.

Categories.AllValid = all(T.IsValid) by T.Category at Categories.Category

show table "Validation results" with
  Categories.Category
  Categories.AllValid

This produces:

Category AllValid
A True
B False
C True
D True

Remarks

The all aggregator is marked as nosort because the order of evaluation does not (mathematically) matter for a logical AND operation.

The default value of true for empty groups follows the mathematical convention that the conjunction of an empty set of propositions is true (this is known as the “vacuous truth”).

Recipes and best practices

  1. Data validation: You can use all to check if every record in a dataset meets certain criteria:
    isValid = all(Items.Quantity > 0 and Items.Price > 0)
  2. Filtering before checking: Combine with filters to check only relevant records:
    isValid = all(Items.Quantity > 0) when Items.IsActive
  3. Comparison with any: Consider whether you need all values to pass (all) or just some values to pass (any).
  4. Negation of all: not (all X) is mathematically equivalent to any(not X), although the former one is computationally more efficient.
  5. Group checking: Use all with a by clause to check each group independently:
    Categories.IsPremium = all(Items.Price > 1000) by Items.Category

See also

User Contributed Notes
0 notes + add a note