OpenBI Docs Buy

UNION

Stacks the rows of two or more tables with the same number of columns, duplicates included.

Group: Table manipulation. Compatible with DAX.

Syntax

UNION ( <table_expression1>, <table_expression2> [, <table_expression>] … )
ParameterTypeDescription
table_expression1TableThe first table; its column names are the result's.
table_expression2TableThe second table, with as many columns as the first.
table_expressionTable
optional, repeatable
Further tables, again with as many columns.

Returns

Table. The rows of all the tables, one table after another, under the first table's column names.

Remarks

  • Columns are matched by position: each table's first column goes into the first column of the result, whatever its name. A different number of columns is an error.
  • Duplicates are not removed. Wrap it in DISTINCT to get each row once.
  • When one table's column is text and another's holds numbers or dates, the column becomes text: a whole number and a text give text. When none is text but one holds values of different kinds, such as IFERROR ( x, "error" ) or an IF that gives a number or a text, each value keeps its own type.
  • A column stays tied to the model only when it comes from the same model column in every table; otherwise it holds plain values.

Examples

Two lists of shops

Frogner is in both and appears twice. The second table's column names do not matter.

EVALUATE
VAR Oslo =
    DATATABLE ( "Shop", STRING, "Liters", INTEGER, { { "Frogner", 120 }, { "Storo", 80 } } )
VAR Bergen =
    DATATABLE ( "Name", STRING, "Volume", INTEGER, { { "Bryggen", 95 }, { "Frogner", 120 } } )
RETURN
    UNION ( Oslo, Bergen )
ORDER BY [Shop]
ShopLiters
Bryggen95
Frogner120
Frogner120
Storo80

A number and a text in one column

EVALUATE
VAR Numbers = DATATABLE ( "Code", INTEGER, { { 1 } } )
VAR Texts = DATATABLE ( "Code", STRING, { { "x" } } )
RETURN
    UNION ( Numbers, Texts )
ORDER BY [Code]
Code
1
x

A union of the same column filters it

EVALUATE
ROW (
    "Pils and IPA",
        CALCULATE (
            [Liters sold],
            UNION (
                FILTER ( VALUES ( Products[Product] ), Products[Product] = "Pils" ),
                FILTER ( VALUES ( Products[Product] ), Products[Product] = "IPA" )
            )
        )
)
Pils and IPA
1336210

EXCEPT, INTERSECT, DISTINCT, DATATABLE, ROW.

Last updated · OpenBI Studio 0.3.74