OpenBI Docs Buy

MATCHBY

In a window function, the columns that identify the current row.

Group: Window and visual calculations. Compatible with DAX.

Syntax

MATCHBY ( <matchBy_columnName> [, <matchBy_columnName>] … )
ParameterTypeDescription
matchBy_columnNameColumn
repeatable
A column of the relation that, with the others named and the PARTITIONBY columns, tells its rows apart.

Returns

None. It gives no value of its own: it tells the window function around it how to find the current row.

Remarks

  • Without MATCHBY, every column of the relation must match the context to find the current row. MATCHBY names the columns to match on instead.
  • The MATCHBY columns together with the PARTITIONBY columns must tell every row of the relation apart; when two rows share them, it is an error.
  • MATCHBY needs the relation: it can't be used when the relation is left out.
  • It goes only inside a window function; anywhere else it is an error.

Examples

Months and shops identify a row

Within each shop, the month tells the rows apart: MATCHBY names it, PARTITIONBY adds the shop.

EVALUATE
VAR Pils =
    FILTER (
        Sales,
        Sales[Product] = "Pils"
            && ( Sales[Shop] = "Shop Kampen" || Sales[Shop] = "Shop Sagene" )
            && YEAR ( Sales[Month] ) = 2026 && MONTH ( Sales[Month] ) <= 3
    )
RETURN
    ADDCOLUMNS (
        Pils,
        "Month before",
            MAXX (
                OFFSET (
                    -1,
                    Pils,
                    ORDERBY ( Sales[Month] ),
                    PARTITIONBY ( Sales[Shop] ),
                    MATCHBY ( Sales[Month] )
                ),
                Sales[Liters]
            )
    )
ORDER BY Sales[Shop], Sales[Month]
Sales[Month]Sales[Shop]Sales[Product]Sales[Liters]Month before
2026-01-01Shop KampenPils278(blank)
2026-02-01Shop KampenPils326278
2026-03-01Shop KampenPils278326
2026-01-01Shop SagenePils260(blank)
2026-02-01Shop SagenePils275260
2026-03-01Shop SagenePils262275

A month alone is not enough

Without the partition by shop, each month is there twice, once per shop.

EVALUATE
VAR Pils =
    FILTER (
        Sales,
        Sales[Product] = "Pils"
            && ( Sales[Shop] = "Shop Kampen" || Sales[Shop] = "Shop Sagene" )
            && YEAR ( Sales[Month] ) = 2026 && MONTH ( Sales[Month] ) <= 3
    )
RETURN
    ADDCOLUMNS (
        Pils,
        "Month before",
            MAXX ( OFFSET ( -1, Pils, ORDERBY ( Sales[Month] ), MATCHBY ( Sales[Month] ) ), Sales[Liters] )
    )

Result: an error.

PARTITIONBY, ORDERBY, OFFSET, WINDOW.

Last updated · OpenBI Studio 0.3.74