- Load Data into Power BI:
- Open Power BI Desktop and load the data that includes your JSON column. You can load data from various sources like Excel, SQL Server, or a CSV file.
- Navigate to
Home>Get Dataand select the data source type. Connect and import your dataset into Power BI.
- Open Power Query Editor:
- In Power BI Desktop, click on
Transform Dataunder theHometab to open the Power Query Editor.
- In Power BI Desktop, click on
- Select the JSON Column:
- Identify and select the column containing the JSON data that you wish to parse.
- Convert JSON Data to a Table:
- With the JSON column selected, go to the
Transformtab in Power Query Editor. - Click on
Transform>JSON>Parse. This action will convert the JSON text into a structured record.
- With the JSON column selected, go to the
- Expand the Parsed JSON:
- Once the JSON is parsed, a new record-type column will appear.
- Click on the
Expandicon (the two arrows pointing away from each other) in the header of this column. - In the expansion dialog, select the fields you wish to include in your table and click
OK. If your JSON has nested arrays or objects, Power BI will allow you to expand those layers as well.
- Handle Nested Structures:
- If your JSON column contains nested objects or arrays:
- After expanding the first level, locate any columns that have additional records or lists.
- Repeat the process by selecting these columns and clicking
Expandagain until all necessary nested data is parsed and expanded into columns.
- If your JSON column contains nested objects or arrays:
- Rename Columns (Optional):
- Rename the expanded columns for clarity. Right-click on any column header and select
Rename, or use theTransform>Renameoption.
- Rename the expanded columns for clarity. Right-click on any column header and select
- Data Type Adjustment:
- Ensure that all parsed columns have the correct data types assigned.
- Click on the column header, and under the
Transformtab, selectData Typeto change the type (e.g.,Date,Text,Decimal Number).
- Close and Apply Changes:
- Once you have parsed and formatted your JSON data, click on
Close & Applyin the top-left corner of the Power Query Editor. - Power BI will apply these changes and load the transformed data back into the main report canvas.
- Once you have parsed and formatted your JSON data, click on
Tips:
- Performance Considerations: If your JSON column contains very large objects, parsing may affect performance. Consider optimizing your data source if necessary.
- Error Handling: If some JSON entries fail to parse, use
Transform>Replace Errorsto handle these gracefully or apply conditional logic to manage unexpected formats. - Power BI M Language: For advanced parsing, you can use Power Query’s M language to create custom parsing logic if needed.
Example Scenario:
If you have a JSON column like this:
{
"ORDER_NO": "12345",
"STATE": {
"CODE": "ACTIVE",
"DESC": "Order is active"
},
"MARKET": {
"SALES_REGION": {
"CODE": "EU",
"DESC": "Europe"
}
}
}
- Select the column and parse the JSON.
- Expand the main record to get
ORDER_NO,STATE, andMARKET. - Expand the
STATEandMARKETcolumns further to access nested properties likeCODE,DESC, etc.
By following these steps, you’ll be able to effectively parse and use JSON data in Power BI for analysis and reporting.