Skip to main content

List.Contains

Indicates whether the list contains the value.

Syntax

List.Contains(
list as list,
value as any,
optional equationCriteria as any
) as logical

Remarks

Indicates whether the list contains the specified value. Returns true if the value is found in the list, false otherwise.

  • list: The list to search.
  • value: The value to search for in the list.
  • equationCriteria: (Optional) The comparer used to determine if two values are equal.

Examples

Example #1

Determine if the list {1, 2, 3, 4, 5} contains 3.

List.Contains({1, 2, 3, 4, 5}, 3)

Result:

true

Example #2

Determine if the list {1, 2, 3, 4, 5} contains 6.

List.Contains({1, 2, 3, 4, 5}, 6)

Result:

false

Example #3

Ignoring case, determine if the list contains "rhubarb".

List.Contains({"Pears", "Bananas", "Rhubarb", "Peaches"},
"rhubarb",
Comparer.OrdinalIgnoreCase
)

Result:

true

Example #4

Determine if the list contains the date April 8, 2022.

let
Source = {#date(2024, 2, 23), #date(2023, 12, 2), #date(2022, 4, 8), #date(2021, 7, 6)},
ContainsDate = List.Contains(Source, Date.From("4/8/2022"))
in
ContainsDate

Result:

true

Category

List.Membership functions

More examples

Implement this function to retrieve or calculate the service URL based on the data source path parameters

GetAuthorizationUrlFromWwwAuthenticate = (url as text) as text =>
let
// Sending an unauthenticated request to the service returns
// a 302 status with WWW-Authenticate header in the response. The value will
// contain the correct authorization_uri.
//
// Example:
// Bearer authorization_uri="https://login.microsoftonline.com/{tenant_guid}/oauth2/authorize"
responseCodes = {302, 401},
endpointResponse = Web.Contents(url, [
ManualCredentials = true,
ManualStatusHandling = responseCodes
])
in
if (List.Contains(responseCodes, Value.Metadata(endpointResponse)[Response.Status]?)) then
let
headers = Record.FieldOrDefault(Value.Metadata(endpointResponse), "Headers", []),
wwwAuthenticate = Record.FieldOrDefault(headers, "WWW-Authenticate", ""),
split = Text.Split(Text.Trim(wwwAuthenticate), " "),
authorizationUri = List.First(List.Select(split, each Text.Contains(_, "authorization_uri=")), null)
in
if (authorizationUri <> null) then
// Trim and replace the double quotes inserted before the url
Text.Replace(Text.Trim(Text.Trim(Text.AfterDelimiter(authorizationUri, "=")), ","), """", "")
else
error Error.Record("DataSource.Error", "Unexpected WWW-Authenticate header format or value during authentication.", [
#"WWW-Authenticate" = wwwAuthenticate
])
else
error Error.Unexpected("Unexpected response from server during authentication.");