简体   繁体   中英

Use each Power Query JSON array item as parameters to the next Query

I have some REST API endpoints, and I want to fetch a specific view of the data to Excel.

Let say I want to create a table with UserName and it Age . To get this data I need to do two requests:

GET /users will return

[
  {
    "name": "User1",
    "id": 3
  }
  ...
]

Then I need to take the name of each item in the result of GET /users for the UserName column, and for each id , I need to do the next request:

GET /users/3 will return

{
  "age": 52,
  "address": "xyz"
}

And I need to take the age and set it as the second column, right after the name from the first request.

Can I do it? How? (With Excel Power Query , of course)

You need to use the each construct in PowerQuery. Rough scaffolding below:

let Source = ... ,    
Age = Table.AddColumn(Source, "AgeColumnName", each Json.Document(Web.Contents("https://example.com/api/users/" & [id]"))),
in Age

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM