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 constant string that defines the name of the column. A dynamic expression is not allowed.

type Repeatable

The data type of the column: INTEGER, DOUBLE, STRING, BOOLEAN, CURRENCY, DATETIME.

data

The data for the table.

Where {values in row1} is a comma delimited set of constant expressions, namely a combination of constants, combined with a handful of basic functions including DATE, TIME, and BLANK, as well as a plus operator between DATE and TIME and a unary minus operator so that negative values can be expressed.

The following are all valid values: 3, -5, BLANK(), “2009-04-15 02:45:21”. Values may not refer to anything outside the immediate expression, and cannot refer to columns, tables, relationships, or anything else.

A missing value will be treated identically to BLANK(). For example, the following are the same: {1,2,BLANK(),4} {1,2,,4}

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.

The data type name specified in DAX differs from the data types available in the user interface of products that use DAX, such as Power BI, Excel, and Visual Studio. Specifically, CURRENCY corresponds to a Fixed Decimal Number in Power BI, whereas DOUBLE corresponds to the Decimal Number in Power BI and Decimal in the DAX Data types list.

» 4 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 7, 2024   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo, Kenneth Barber

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

2018-2024 © 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.

Volatile

A volatile function may return a different result every time you call it, even if you provide the same arguments. Click to read more.

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.