OpenBI Docs Buy

CONTAINS

Whether a table has a row with the given values in the given columns.

Group: Information. Compatible with DAX.

Syntax

CONTAINS ( <table>, <columnName>, <value> [, <columnName>, <value>] … )
ParameterTypeDescription
tableTableThe rows to search: a table of the model or a table expression.
columnNameColumn
repeatable
A column of the table to look in, or of a table it looks up through a relationship.
valueValue
repeatable
What the column before it must hold.

Returns

Boolean. TRUE when one row at least holds each value in its column, FALSE otherwise.

Remarks

  • Columns and values come in pairs, and every pair must match on the same row: a row with IPA and another with 80 liters do not make a row with both.
  • The match is strict, as for CONTAINSROW and the IN operator: a blank finds only a blank, never 0 or empty text. Text is matched without regard to upper and lower case.
  • A value of a type its column cannot be compared with, such as the text "80" for a column of whole numbers, is an error. Turn it into the column's type with VALUE or FORMAT first.
  • Over an empty table the answer is FALSE.
  • A column of a related table on the one side counts as the row's own: CONTAINS ( Sales, Products[Category], "Cider" ) asks whether a row of Sales is for a cider (example 3). A table without such a relationship, or a table made by VALUES or SUMMARIZE, is an error with such a column.
  • For a single column, CONTAINSROW or IN reads more simply. To filter one table by the values another table holds, TREATAS is usually the better tool.

Examples

One value, then two on the same row

IPA is there with 80 liters, not with 120.

EVALUATE
VAR Orders =
    DATATABLE (
        "Product", STRING, "Liters", INTEGER,
        { { "Pils", 120 }, { "IPA", 80 }, { "Stout", 45 } }
    )
RETURN
    ROW (
        "IPA", CONTAINS ( Orders, [Product], "IPA" ),
        "Cider", CONTAINS ( Orders, [Product], "Cider" ),
        "IPA with 80", CONTAINS ( Orders, [Product], "IPA", [Liters], 80 ),
        "IPA with 120", CONTAINS ( Orders, [Product], "IPA", [Liters], 120 )
    )
IPACiderIPA with 80IPA with 120
TRUEFALSETRUEFALSE

Blanks and case

The Stout line has no liters: a blank finds it, a zero does not. Lower-case pils finds Pils.

EVALUATE
VAR Orders =
    DATATABLE (
        "Product", STRING, "Liters", INTEGER,
        { { "Pils", 120 }, { "IPA", 80 }, { "Stout", BLANK () } }
    )
RETURN
    ROW (
        "Blank liters", CONTAINS ( Orders, [Liters], BLANK () ),
        "Zero liters", CONTAINS ( Orders, [Liters], 0 ),
        "Lower case", CONTAINS ( Orders, [Product], "pils" )
    )
Blank litersZero litersLower case
TRUEFALSETRUE

Did a shop buy a product?

The category is a column of Products, which Sales looks up.

EVALUATE
ROW (
    "Pils at Frogner", CONTAINS ( Sales, Sales[Product], "Pils", Sales[Shop], "Shop Frogner" ),
    "Any Stout", CONTAINS ( Sales, Sales[Product], "Stout" ),
    "Any cider", CONTAINS ( Sales, Products[Category], "Cider" )
)
Pils at FrognerAny StoutAny cider
TRUEFALSETRUE

CONTAINSROW, ISEMPTY, LOOKUPVALUE, TREATAS, CONTAINSSTRING.

Last updated · OpenBI Studio 0.3.74