Forum Discussion
How to pass the request object as query string in Power Query Formula Language
- 10 years ago
How is extracting data from the JSON going on? If there's any problem, feel free to post. If no further question, please accept one reply as solution to close this thread. :)
Thanks Eric. That was a great help.
Hi Eric ,
I am now able to connect to the API . However my responce in in below format.
{"rows": [{"values": [["skype"], 6990480.0]}, {"values": [["*null*"], 70280640.0]}, {"values": [["office"], 11148624.0]}, {"values": [["sql-non-specified"], 323136.0]}, {"values": [[".net-framework-4.6"], 632352.0]}, {"values": [["sql-server-2016"], 247392.0]}, {"values": [["visual-studio-dev14"], 541824.0]}, {"values": [["azure"], 325392.0]}, {"values": [["msn games"], 289680.0]}, {"values": [["windows7"], 651264.0]}, {"values": [["All others"], 5956896.0]}], "columns": [{"type": "array", "label": ["ms_prod"]}, {"type": "number", "label": "measure_value"}]}
How do i convert this to a table format in PBI desktop .
When i am impoting JSON i am getting the columns and rows in below format.
How do i convert the Rows list and columns list into a table format ?
Thanks in advance.
- Eric_Zhang10 years agoMicrosoft Employee
Could you share how did you manage to make the API work? What was wrong?
To convert the json to a table, I think you can reference the power query below. I am using a JSON file other than web API, however the transformations are in the same way, you can just replace the source accordingly.
let Source = Json.Document(File.Contents("C:\test\json.json")), rows = Source[rows], #"Converted to Table" = Table.FromList(rows, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Added Index" = Table.AddIndexColumn(#"Converted to Table", "Index", 0, 1), #"Expanded Column1" = Table.ExpandRecordColumn(#"Added Index", "Column1", {"values"}, {"Column1.values"}), #"Expanded Column1.values" = Table.ExpandListColumn(#"Expanded Column1", "Column1.values"), #"Added Column" = Table.AddColumn(#"Expanded Column1.values", "isValue", each let result = try Number.From([Column1.values]) otherwise "Not value", resultType = if result = "Not value" then "N" else "Y" in resultType ), #"Filtered Rows" = Table.SelectRows(#"Added Column", each ([isValue] = "N")), #"Expanded Column1.values1" = Table.ExpandListColumn(#"Filtered Rows", "Column1.values"), #"Merged Queries" = Table.NestedJoin(#"Expanded Column1.values1",{"Index"},#"Added Column",{"Index"},"NewColumn",JoinKind.Inner), #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Column1.values", "isValue"}, {"NewColumn.Column1.values", "NewColumn.isValue"}), #"Filtered Rows1" = Table.SelectRows(#"Expanded NewColumn", each ([NewColumn.isValue] = "Y")), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Index", "isValue", "NewColumn.isValue"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Column1.values", "ms_prod"}, {"NewColumn.Column1.values", "measure_value"}}) in #"Renamed Columns"- Peddabomma10 years agoMicrosoft Employee
Hi Eric,
There was a syntax error in my query after fixing that i was able to connect to the API.
Thanks, Raghu
- Eric_Zhang10 years agoMicrosoft Employee
How is extracting data from the JSON going on? If there's any problem, feel free to post. If no further question, please accept one reply as solution to close this thread. :)