TOJSON Function in DAX

The TOJSON() DAX function in Power BI is used to convert a table or a row into a JSON-formatted string. This is particularly useful when working with Power BI integrations, Power Automate, PowerApps, or custom visuals, where JSON is often the expected format for data exchange.

DAX Syntax

TOJSON(Table, [MaxRows])

The function has the following parameters:

Return value A string with JSON representation of the table. The representation contains column names as "header", count-of-rows as "rowCount", and values as "data".

Example: Lets we the following table named ‘Student List’.

TOJSON DAX Function in Power BI

Let’s create a measure with name “TOJSON measure”.

DAX

TOJSON Measure = TOJSON(
    TOPN(3, 'Student List', 'Student List'[ID], DESC),
    3
)    

Let’s use this measure in the card visual as shown in the image below:

TOJSON DAX Function in Power BI