TOCSV Function in DAX
The TOCSV() function in DAX (Data Analysis Expressions) is used to convert a table or table expression into a single string of comma-separated values (CSV). It's useful when you want to display or export table data as a string, often for tooltips, labels, or exports.
DAX Syntax
The function has the following parameters:
- Table: The table to be converted to CSV.
- MaxRows: It is an optional parameter. The maximum number of rows to convert. Default is 10 rows.
- Delimiter: It is an optional parameter. A column delimiter. Default is comma ",".
- IncludeHeaders: It is an optional parameter. A boolean value (TRUE or FALSE) specifies a header with column name as the first row. Default is True.
Return value A string with CSV representation of the table.
Example: Let's say we have a table named ‘Student List’.

Let’s create a measure with name “TOCSV measure”.
DAX
TOCSV Measure = TOCSV('Student List') Let’s use this measure in the card visual as shown in the image below:

DAX
TOCSV Measure = TOCSV(
SELECTCOLUMNS(
'Student List',
"Student", 'Student List'[StudentName],
"Teacher", 'Student List'[AssociatedTeacher]
)
) The output of the above code is shown below:

Example: With Custom Delimiter and No Headers.
DAX
TOCSV Measure = TOCSV(
SELECTCOLUMNS(
'Student List',
"Student", 'Student List'[StudentName],
"Teacher", 'Student List'[AssociatedTeacher]
), 20, "|", FALSE()
) The output of the above code is shown below:

Example:
DAX
TOCSV Measure = TOCSV( TOPN(3, 'Student List', 'Student List'[ID], DESC), 3, ", ", TRUE )
The output of the above code is shown below:

We can also export the data from the visual, by clicking on three dots, and then click on Export data.

The file is downloaded as a csv file.

Note: As it is a measure the table used in the function is also filtered by the filter context.
Use Cases:
- Showing small table data in tooltips or cards
- Creating a summary text from a list
- Exporting small sets of data in CSV-like format