How does the DATATABLE function (DAX) work?

The DATATABLE function (DAX) creates a table. The syntax allows you to define each column name and data type, and add data values to it.

DATATABLE Formula Syntax

     ColumnName1, DataType1, ColumnName2, Datatype2 … , {{Value1, Value2…}, {ValueN, ValueN+1…}…}

How do you use the DATATABLE function?

Used Datatable function to give flexibility in defining each column name and data type specifically while the table constructor is just an easy and fast way of creating a data table with no specific metadata setup.

Related Blog Posts


Considerations when using the DATATABLE function

If you want to add expression-based columns to your table, The best would be using other functions such as SelectColumns, AddColumns, or SummarizeColumns.

If you use Table Constructor to build a table, you can use any expression as the value.

Unlike DATATABLE, Table Constructor allows any scalar expressions as input values. The syntax used by DATATABLE is different from that used by Table Constructor.

The value in each cell can be only constant, not any scalar expression.
An alternative for that would be using SelectColumns, AddColumns or any other methods to get an expression-based column added to the table.

Related Video Tutorials

Formula examples using the DATATABLE function

=DataTable(“Name”, STRING, “Region”, STRING ,{ {” User1″,”East”}, {” User2″,”East”}, {” User3″,”West”}, {” User4″,”West”}, {” User4″,”East”} } )

= DATATABLE ( “Price Range”, STRING, “Min Price”, CURRENCY, “Max Price”, CURRENCY, { { “Low”, 0, 10 }, { “Medium”, 10, 100 }, { “High”, 100, 9999999 } } )

DATATABLE ( “Quarter”, STRING, “StartDate”, DATETIME, “EndDate”, DATETIME, { { “Q1”, “2015-01-01”, “2015-03-31” }, { “Q2”, “2015-04-01”, “2015-06-30” }, { “Q3”, “2015-07-01”, “2015-09-30” }, { “Q4”, “2015-010-01”, “2015-12-31” } } )

Related Course Modules