CONTAINS Function
Description:
CONTAINS function checks if there exists at least one row where all columns have specified values.
Return Value:
CONTAINS returns a boolean value, TRUE if each specified value can be found in the corresponding columnName, or are contained, in those columns; otherwise, it returns FALSE.
Syntax:
CONTAINS(<Table>,<ColumnName>,<Value> [,<ColumnName>,<Value> [, … ] ])
- Description of the parameters:
PARAMETER |
DESCRIPTION |
---|---|
Table |
DAX expression that returns a table of data to test |
ColumnName |
Name of an existing column in the input table or in a related table. |
Value |
DAX expression that returns a single scalar value to look for in the column |
Example:
An example of the CONTAINS function is to check for the resistance of a value in a column.
So, let's create a measure that checks if the 'ProductSubCategory' column contains the value "Speakers". To do this, we will use the following formula
CONTAINSMeasure =
CONTAINS(
ProductSubcategory,
ProductSubcategory[ProductSubcategory],
"Speakers"
)
Note that:
- columnName must belong to the specified table, or to a table that is related to table.
- The arguments columnName and value must come in pairs; otherwise an error is returned.
Related Video: