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 ave this Json dataset and I want to transform it into a table with columns indicated in the json: Prodcut_ID and PRICE
the values are int rows records:
{
"columns": [
{
"name": "PRODUCT_ID",
"type": "text"
},
{
"name": "PRICE",
"type": "float"
}
],
"rows": [
[
"A26",
0.30447
],
[
"A158",
1.0970999
],
[
"A18898",
0.205
],
[
"A25177",
19.4
],
[
"A265",
130.95
]
]
}
My target output:
PRODUCT_ID | PRICE
---------------+---------------
A26 |0.30447
A158 |1.0970999
A18898 |0.205
A25177 |19.4
Thanks in advance
Solved! Go to Solution.
Hello @yamaga ,
first you parse the JSON and then extract the values as follows:
let
Query1 = "{#(cr)#(lf) ""columns"": [#(cr)#(lf) {#(cr)#(lf) ""name"": ""PRODUCT_ID"",#(cr)#(lf) ""type"": ""text""#(cr)#(lf) },#(cr)#(lf) {#(cr)#(lf) ""name"": ""PRICE"",#(cr)#(lf) ""type"": ""float""#(cr)#(lf) }#(cr)#(lf) ],#(cr)#(lf) ""rows"": [#(cr)#(lf) [#(cr)#(lf) ""A26"",#(cr)#(lf) 0.30447#(cr)#(lf) ],#(cr)#(lf) [#(cr)#(lf) ""A158"",#(cr)#(lf) 1.0970999#(cr)#(lf) ],#(cr)#(lf) [#(cr)#(lf) ""A18898"",#(cr)#(lf) 0.205#(cr)#(lf) ],#(cr)#(lf) [#(cr)#(lf) ""A25177"",#(cr)#(lf) 19.4#(cr)#(lf) ],#(cr)#(lf) [#(cr)#(lf) ""A265"",#(cr)#(lf) 130.95#(cr)#(lf) ]#(cr)#(lf) ]#(cr)#(lf)}",
#"Parsed JSON" = Json.Document(Query1),
Custom1 = Table.FromRows(#"Parsed JSON"[rows], List.Transform(#"Parsed JSON"[columns], each _[name]))
in
Custom1
If you copy this code into the advanced editor you will see that the first step contains your JSON (with some line break code) and then the relevant steps follow.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hello @yamaga ,
first you parse the JSON and then extract the values as follows:
let
Query1 = "{#(cr)#(lf) ""columns"": [#(cr)#(lf) {#(cr)#(lf) ""name"": ""PRODUCT_ID"",#(cr)#(lf) ""type"": ""text""#(cr)#(lf) },#(cr)#(lf) {#(cr)#(lf) ""name"": ""PRICE"",#(cr)#(lf) ""type"": ""float""#(cr)#(lf) }#(cr)#(lf) ],#(cr)#(lf) ""rows"": [#(cr)#(lf) [#(cr)#(lf) ""A26"",#(cr)#(lf) 0.30447#(cr)#(lf) ],#(cr)#(lf) [#(cr)#(lf) ""A158"",#(cr)#(lf) 1.0970999#(cr)#(lf) ],#(cr)#(lf) [#(cr)#(lf) ""A18898"",#(cr)#(lf) 0.205#(cr)#(lf) ],#(cr)#(lf) [#(cr)#(lf) ""A25177"",#(cr)#(lf) 19.4#(cr)#(lf) ],#(cr)#(lf) [#(cr)#(lf) ""A265"",#(cr)#(lf) 130.95#(cr)#(lf) ]#(cr)#(lf) ]#(cr)#(lf)}",
#"Parsed JSON" = Json.Document(Query1),
Custom1 = Table.FromRows(#"Parsed JSON"[rows], List.Transform(#"Parsed JSON"[columns], each _[name]))
in
Custom1
If you copy this code into the advanced editor you will see that the first step contains your JSON (with some line break code) and then the relevant steps follow.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
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.