Daily DAX : Day 317 CONTAINSROW

Power BI DAX: CONTAINSROW Function

Description

The CONTAINSROW function in DAX (Data Analysis Expressions) checks if a specific row of values exists in a table. It returns TRUE if the row is found, otherwise FALSE.

Syntax

CONTAINSROW(table, value1, [value2], ...)
    
  • table: The table to search in (e.g., a table expression or table name).
  • value1, [value2], ...: The values to search for, corresponding to the columns in the table.

Return Value

TRUE if the row with the specified values exists in the table, FALSE otherwise.

Use Cases

CONTAINSROW is commonly used to:

  • Check if specific data combinations exist in a table.
  • Filter data based on multiple column conditions.
  • Validate data integrity or perform conditional logic in measures or calculated columns.

Example

Suppose you have a table named Sales with columns Product and Region. You want to check if there is a row where Product = "Laptop" and Region = "North".

IsLaptopNorth = CONTAINSROW(Sales, "Laptop", "North")
    

This returns TRUE if such a row exists, otherwise FALSE.

Practical Example in Power BI

Create a measure to flag if a specific product-region combination exists:

HasSpecificSale = 
    IF(
        CONTAINSROW(Sales, Sales[Product], "Laptop", Sales[Region], "North"),
        "Found",
        "Not Found"
    )
    

This measure checks if the combination exists and returns "Found" or "Not Found" accordingly.

Notes

  • CONTAINSROW is case-sensitive for text comparisons.
  • It checks for an exact match of all specified values in a single row.
  • Use in measures or calculated columns for dynamic checks.

Comments

Popular posts from this blog

Daily DAX : Day 65 INFO.TABLEPERMISSIONS

Daily DAX : Day 55 PV