TOCSV DAX Function (Text)
Converts the records of a table into a CSV (comma-separated values) text.
Syntax
Parameter | Attributes | Description |
---|---|---|
Table |
The table to be converted. |
|
MaxRows | Optional |
The maximum number of rows to be converted. A negative number means all rows are converted. Default is 10. |
Delimiter | Optional |
The field separator. Must be a non-empty constant string. Default is ‘,’. |
IncludeHeaders | Optional |
If true, the header row is included. Default is true. |
Return values
Result in CSV format.
Remarks
The sort order of the result cannot be controlled.
The new line character cannot be modified.
Any quotation marks (") within the value are replaced with 2 quotation marks (""). If the original value contains a quotation mark or the delimiter, then the entire value, after the aforementioned replacement of quotation marks, is enclosed in quotation marks. The delimiter is never affected by the addition or replacement of quotation marks, even if the delimiter contains a quotation mark.
In case of need, use CONCATENATEX to create a CSV controlling the order and the new line character.
Examples
DEFINE MEASURE Sales[ByCountry] = VAR SalesByCustomer = ADDCOLUMNS ( VALUES ( Customer[CountryRegion] ), "Amount", [Sales Amount] ) VAR Result = TOCSV ( SalesByCustomer, 3, ",", FALSE ) RETURN Result EVALUATE SUMMARIZECOLUMNS ( 'Customer'[Continent], "By Country CSV", [ByCountry] )
Continent | By Country CSV |
---|---|
Asia | Australia,7638059.93580003 Turkmenistan,118336.552 Thailand,63107.118 |
North America | United States,10312118.2484997 Canada,885208.0705 |
Europe | Germany,2519890.79830002 United Kingdom,3621032.15870003 France,1109665.43230001 |
Related functions
Other related functions are:
Last update: Nov 14, 2024 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo, Kenneth Barber
Microsoft documentation: https://learn.microsoft.com/dax/tocsv-function-dax