Skip to main content

Filtering

Learn how to filter data.

A collection can be filtered using Collection.Filter. A list can be filtered using List.Filter.

These functions behave similarly: each receives the collection or list to filter, and then a function that returns true for all elements that should pass the filter.

For instance, in the example below, a dataset is read and the resulting collection is filtered in order to return only the rows that match a given country name. Specifically, this example reads a dataset in airports and returns only those airports in a given country.

main(country: string) =
let
airports = Csv.InferAndRead("https://raw-tutorial.s3.eu-west-1.amazonaws.com/airports.csv")
in
Collection.Filter(airports, a -> a.Country == country) // airports in a given country
info

If you want to try this example, you can deploy the following endpoint:

Tutorial 1 - Filtering data in a collection
Learn how to filter rows in a collection.

Sample usage:

/tutorial/1-filter?country=<string>

For instance, to ask for airports in Portugal, use:

/tutorial/1-filter?country=Portugal