OpenBI Docs Buy

GENERATE

Each row of a table joined with the rows a second table expression gives for it; rows that get none left out.

Group: Table manipulation. Compatible with DAX.

Syntax

GENERATE ( <table1>, <table2> )
ParameterTypeDescription
table1TableThe rows to start from.
table2Table
evaluated for each row
The table worked out for each row of the first; it can use that row's columns.

Returns

Table. Each row of the first table paired with each row its second table gives, the columns of both side by side.

Remarks

  • A row whose second table is empty does not appear at all. GENERATEALL lists it once, with blanks.
  • The second table sees the first's row as a row context only. Table functions such as VALUES ignore a row context: wrap them in CALCULATETABLE to turn the row into a filter, as the second example does.
  • The two tables must not share a column name.
  • When the second table does not depend on the row, the result is the same as CROSSJOIN.

Examples

One row per crate

Each shop gets a row for every crate slot it fills; Storo fills none and drops out.

EVALUATE
VAR Shops =
    DATATABLE (
        "Shop", STRING, "Crates", INTEGER,
        { { "Frogner", 2 }, { "Storo", 0 }, { "Sagene", 1 } }
    )
VAR Slots = DATATABLE ( "Slot", INTEGER, { { 1 }, { 2 }, { 3 } } )
RETURN
    GENERATE ( Shops, FILTER ( Slots, [Slot] <= [Crates] ) )
ORDER BY [Shop], [Slot]
ShopCratesSlot
Frogner21
Frogner22
Sagene11

The best-selling product of each category

EVALUATE
GENERATE (
    VALUES ( Products[Category] ),
    CALCULATETABLE ( TOPN ( 1, VALUES ( Products[Product] ), [Liters sold] ) )
)
ORDER BY Products[Category]
Products[Category]Products[Product]
BeerPils
CiderCider

GENERATEALL, CROSSJOIN, CALCULATETABLE, TOPN, ADDCOLUMNS.

Last updated · OpenBI Studio 0.3.74