DATATABLE DAX Function (Table manipulation)

Returns a table with data defined inline.

Syntax

DATATABLE ( <name>, <type> [, <name>, <type> [, … ] ], <data> )
Parameter Attributes Description
name Repeatable

A column name to be defined.

type Repeatable

A type name to be associated with the column.

data

The data for the table.

Return values

Table An entire table or a table with one or more columns.

A table declaring an inline set of values.

Remarks

Unlike DATATABLE, the table constructor allows any scalar expressions as input values.

The syntax used by DATATABLE is different from that used by the table constructor.

» 3 related articles

Examples

--  DATATABLE is useful to build constant tables in code.
--  It requires the list of arguments and the list of rows
--  to build the table.
EVALUATE
DATATABLE (
    "Name", STRING,
    "Ordinal", INTEGER,
    {
        { "Small",  1 },
        { "Medium", 2 },
        { "Large",  3 }
    }
)
ORDER BY [Ordinal]
Name Ordinal
Small 1
Medium 2
Large 3

Values in the definition of the table cannot be expressions; they need to be constant. The following syntax is not valid and generates an error.

EVALUATE
DATATABLE (
    "Aggregation", STRING,
    "Value", CURRENCY,
    {
        { "Min", MIN ( Sales[Net Price] ) },
        { "Max", MAX ( Sales[Net Price] ) }
    }
)

Tables with calculated expressions can be computed using the ROW function, or the table constructor {}, instead of using DATATABLE.
The table constructor requires renaming the columns.

EVALUATE
    UNION (
        ROW ( "Aggregation", "Min", "Value", MIN ( Sales[Net Price] ) ),
        ROW ( "Aggregation", "Max", "Value", MAX ( Sales[Net Price] ) )
    )

EVALUATE
    SELECTCOLUMNS ( 
        {
            ( "Min", MIN ( Sales[Net Price] ) ),
            ( "Max", MAX ( Sales[Net Price] ) )
        },
        "Aggregation", [Value1],
        "Value", [Value2] 
    )
Aggregation Value
Min 0.76
Max 3,199.99
Aggregation Value
Min 0.76
Max 3,199.99

Related articles

Learn more about DATATABLE in the following articles:

Last update: Nov 23, 2021   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo, Kenneth Barber

Microsoft documentation: https://docs.microsoft.com/en-us/dax/datatable-function

2018-2021 © SQLBI. All rights are reserved. Information coming from Microsoft documentation is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Iterator

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Deprecated

This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.

Contribute

Want to improve the content of DATATABLE? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.