Convert json List Record to Table value in PowerBI
Solution 1
I'm missing the step of ExpandRecordColumn
Function. After I put that in my Query. It's worked.
let
Source = Json.Document(File.Contents("C:\Users\hp\Desktop\File.JSON")),
Family = Source[Family],
#"Converted to Table" = Table.FromList(Family, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"Father", "Age", "Mother", "MAge", "Children"}, {"Father", "Age", "Mother", "MAge", "Children"})
in
#"Expanded Column1"
Solution 2
Let me share a step by step guide for those who want to do it without writing Power Query and jsut using Power BI user interface (Desktop/Web).
-
Open Power BI Desktop
-
Get Data → More ... → Select JSON from the list and click on Connect (You can also use WEB API or other sources which gives you JSON data)
-
Choose the JSON file and open it.
-
In the data panel, you see Family|List. Click on List link to add a navigation step.
-
From Transform tab, click on To Table and from dialog click on OK.
-
From the header of "Column1", click on Expand columns button to expand columns and from the menu, uncheck Use original column name as prefix and check the columns that you want and click on OK.
-
You will see the columns and data in table format. You can change data type of columns by click on data type button .
And finally you will have something like this:
Finally if you want to see the generated query, click on Advanced Editor button and see the code:
let
Source = Json.Document(File.Contents("C:\Users\rag\Desktop\data.json")),
Family = Source[Family],
#"Converted to Table" = Table.FromList(Family, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"Father", "Age", "Mother", "MAge"}, {"Father", "Age", "Mother", "MAge"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Column1",{{"Age", type number}, {"MAge", type number}})
in
#"Changed Type"
More information:
- Get started with Power BI Desktop
- Shape and combine data in Power BI Desktop
- Perform common query tasks in Power BI Desktop
Comments
-
Jayendran almost 2 years
I'm totally new to Power BI so I'm tried different approached to convert my JSON file to a table but unsuccessful so far.
{ "Family": [ { "Father": "F1", "Age": 50, "Mother": "M1", "MAge": 49, "Children": [ { "Name": "C1" }, { "Name": "C2" } ] }, { "Father": "F2", "Age": 55, "Mother": "M2", "MAge": 53, "Children": [ { "Name": "Cc1" }, { "Name": "Cc2" } ] } ] }
I'm trying to convert this into the table below
Father Age Mother MAge F1 50 M1 49 F2 55 M2 53
I tried like convert table and transpose which is not working I always get an error like
Expression.Error: We cannot convert a value of type Record to type