Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Scenario:
In Power BI Desktop, when we connect to a .json file, power query editor will transform it automatically if its structure is single.
Sample data1:
Output in power query:
From the APPLIED STEPS we can find that power query editor expands all columns automatically to get this result table.
Extension:
If the json file’s structure is a bit complex and expand all columns which could not get the expected result, how can we transform the file in power query?
Sample data2:
Expected output:
Preface:
If we connect to this .json file and expand all columns directly, it will get this table which is not we wanted:
Operations:
#"Added Custom" = Table.AddColumn(#"Renamed Columns", "Value", each [Contents][Price]{0}[values])
Note: This step is the combination of the steps that we click ‘Record => Price[list] => Record => values[lists]’, just add a custom column to show it.
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Products", each Record.FromList(
List.Zip(
Record.ToList([Contents][Products])),
{"A_B","B_C"}
))
Note: For this step, we need to use List.Zip() function to ‘pack and compress’ a new list due to the column and row transformation, then transform it to a record for next steps.
#"Added Custom2" = Table.AddColumn(#"Expanded Products", "Custom", each List.Zip({[ID],[Value]}))
#"List to Record" = Table.TransformColumns(#"Filtered Rows",{"Custom",each Record.FromList(_,{"ID","values"})}),
#"Expanded Custom1" = Table.ExpandRecordColumn(#"List to Record", "Custom", {"ID", "values"}, {"Custom.ID", "Custom.values"})
Main Functions reference:
Author: Yingjie Li
Reviewer: Ula Huang, Kerry Wang
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.