Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I have a following JSON:
[ { "timestamp": "2019-08-07T09:41:32.000Z", "result": [ { "site_name": "x", "count_distinct__z": 1948.305445666293, "count_distinct__v": 250565.23678795504 }, { "site_name": "y", "count_distinct__z": 1948.305445666293, "count_distinct__v": 3889974.5781805683 } ] } ]
...and I want to extract the "result" list as a table. I can extract record from the JOSN as:
timestamp | 2019-08-07T09:41:32.000Z |
result | List |
...but I can't expand the "List" as a table.
Kind regards,
Piotr
Solved! Go to Solution.
Hi @arnamq
Not sure if I understand what you need, but is this what you after?
please see the attached.
Hi @arnamq ,
I created a sample to implement it. You could follow the steps.
Here is the script.
let Source = Json.Document(File.Contents("C:\Users\xueding\Desktop\821632.json")), #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"timestamp", "result"}, {"Column1.timestamp", "Column1.result"}), #"Expanded Column1.result" = Table.ExpandListColumn(#"Expanded Column1", "Column1.result"), #"Expanded Column1.result1" = Table.ExpandRecordColumn(#"Expanded Column1.result", "Column1.result", {"site_name", "count_distinct__z", "count_distinct__v"}, {"Column1.result.site_name", "Column1.result.count_distinct__z", "Column1.result.count_distinct__v"}) in #"Expanded Column1.result1"
I attached the sample that you can try and check if it is what you want.
Edit:
Attach my sample. (I find I didn't attach it. )
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Kudos are nice too.
Hi @arnamq
I've attached the file with a solution, all you need to do is follow the query steps.
Thank you for a quick response 🙂
One more question: is it possible to do similar transformation without using expliced declaration of the columnt names?
Depending on the query count and names of a result columns may by different.
Kind regards,
Piotr
Hi @arnamq
Not sure if I understand what you need, but is this what you after?
please see the attached.
//Not sure if I understand what you need, but is this what you after?
No, not exacly but we're close. I mean a situation when the result schema is unknown before running the query. We can skip the "timestamp" field hance that it is constant and focus on the "result" list. Once it may be:
[ { "timestamp": "2019-08-07T09:41:32.000Z", "result": [ { "site_name": "x", "count_distinct__z": 1948.305445666293, "count_distinct__v": 250565.23678795504 }, { "site_name": "y", "count_distinct__z": 1948.305445666293, "count_distinct__v": 3889974.5781805683 } ] } ]
once
[ { "timestamp": "2019-08-07T09:41:32.000Z", "result": [ { "site_name": "x", "x": 1948.305445666293, "z": 250565.23678795504, "a": 1948.305445666293, "b": 3889974.5781805683 }, { "site_name": "y", "x": 1948.305445666293, "z": 3889974.5781805683, "a": 1948.305445666293, "b": 3889974.5781805683 } ] } ]
and another time it may be:
[ { "timestamp": "2019-08-07T09:41:32.000Z", "result": [ { "animal" : "frog" }, { "animal" : "lion" } ] } ]
and another time it may be something else 🙂
Kind regards,
Piotr
Hi Piotr ( @arnamq )
Try the attached
Now in the second step ( #"Converted to Table1" = Record.ToTable(Source),) I have: we cannot convert a value of type List to type Record.
I'm using the same JSON source as previously:
[ { "timestamp": "2019-08-07T09:41:32.000Z", "result": [ { "site_name": "x", "count_distinct__z": 1948.305445666293, "count_distinct__v": 250565.23678795504 }, { "site_name": "y", "count_distinct__z": 1948.305445666293, "count_distinct__v": 3889974.5781805683 } ] } ]
Hi @arnamq ,
I created a sample to implement it. You could follow the steps.
Here is the script.
let Source = Json.Document(File.Contents("C:\Users\xueding\Desktop\821632.json")), #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"timestamp", "result"}, {"Column1.timestamp", "Column1.result"}), #"Expanded Column1.result" = Table.ExpandListColumn(#"Expanded Column1", "Column1.result"), #"Expanded Column1.result1" = Table.ExpandRecordColumn(#"Expanded Column1.result", "Column1.result", {"site_name", "count_distinct__z", "count_distinct__v"}, {"Column1.result.site_name", "Column1.result.count_distinct__z", "Column1.result.count_distinct__v"}) in #"Expanded Column1.result1"
I attached the sample that you can try and check if it is what you want.
Edit:
Attach my sample. (I find I didn't attach it. )
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Kudos are nice too.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
99 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
87 | |
64 |