Forum Discussion
Create tables based on all Query Parameters
- 8 years ago
I did it in one table instead of creating new table for each character's id.
We need one table and one function.
Here's full solution:
1. Create function getCharacter(id):
let Source = (id as text) => let Source = Json.Document(Web.Contents("https://swapi.co/api/people/" & id)), #"Converted to Table" = Record.ToTable(Source) in #"Converted to Table" in Source2. Create table with ids for id parameter in URL: https://swapi.co/api/people/{id}
Table with ids for API: https://swapi.co/api/people/{id}
3. Invoke the function getCharacter(id) on this table: go to 'Add column' -> 'Invoke custom function' and expand.
Expanded table with character details for each id specified earlier
M code for the expanded table above:
let idList = {"1", "2", "3"}, #"Converted to Table" = Table.FromList(idList, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "id"}}), #"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "getCharacter", each getCharacter([id])), #"Expanded getCharacter" = Table.ExpandTableColumn(#"Invoked Custom Function", "getCharacter", {"Name", "Value"}, {"getCharacter.Name", "getCharacter.Value"}) in #"Expanded getCharacter"
I did it in one table instead of creating new table for each character's id.
We need one table and one function.
Here's full solution:
1. Create function getCharacter(id):
let
Source = (id as text) => let
Source = Json.Document(Web.Contents("https://swapi.co/api/people/" & id)),
#"Converted to Table" = Record.ToTable(Source)
in
#"Converted to Table"
in
Source
2. Create table with ids for id parameter in URL: https://swapi.co/api/people/{id}
Table with ids for API: https://swapi.co/api/people/{id}
3. Invoke the function getCharacter(id) on this table: go to 'Add column' -> 'Invoke custom function' and expand.
Expanded table with character details for each id specified earlier
M code for the expanded table above:
let
idList = {"1", "2", "3"},
#"Converted to Table" = Table.FromList(idList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "id"}}),
#"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "getCharacter", each getCharacter([id])),
#"Expanded getCharacter" = Table.ExpandTableColumn(#"Invoked Custom Function", "getCharacter", {"Name", "Value"}, {"getCharacter.Name", "getCharacter.Value"})
in
#"Expanded getCharacter"- wsdcawefwqrevfq3 years agoHelper I
While this is an old post, for anyone who ends up here looking for a solution, the above process is explained quite well in this video:
https://www.youtube.com/watch?v=MCTXMUuH3gk&ab_channel=PowerBIGuy