where

where, keyword

Filters tables within a where block or within a filtered assignment.

Example (block)

table T = with
  [| as N |]
  [| 0 |]
  [| 1 |]
  [| 2 |]
  [| 3 |]

where T.N mod 2 == 0
  show table "Even" with
    T.N

This outputs the following table:

N
0
2

Example (filtered assignment)

table Products = with
  [| as Product, as Price |]
  [| "cap", 3.50 |]
  [| "hat", 2.50 |]
  [| "ball", 4.00 |]

Products.Price = Products.Price * 1.1 where Products.Price < 3

show table "Prices" with
  Products.Product
  Products.Price

This outputs the following table:

Product Price
cap 3.5
hat 2.75
ball 4

Remarks

keep where applies the filter to the rest of the current block without extra indentation. Filtering propagates to downstream tables.

Cross tables cannot be filtered with a where block or a filtered assignment. Use an explicit filtered table like table T = where Cross.Cond to obtain a regular table.

Filter tables created with table T = where ... are independent of later filters applied to the source table when the source has a single primary dimension. This avoids re-filtering the new table unintentionally.

table Items = with
  [| as Id, as X, as Y |]
  [| 1, "A", 0 |]
  [| 2, "B", 1 |]
  [| 3, "A", 0 |]
  [| 4, "B", 1 |]
  [| 5, "C", 2 |]
  [| 6, "B", 1 |]

table T = where Items.X != "C"

where Items.X != "A"
  show scalar "Count in T" with count(T.*)

This outputs the following scalar:

Count in T
5
User Contributed Notes
0 notes + add a note