powerquerym

Power Query return a field name based on parameter


I need to return a field based on the parameter I am passing, something like this

(URLPath as text, Page as number) =>
let
    Source = Json.Document(Web.Contents("https://XX.com/api/v2/" & URLPath 
    , [Query =[per_page="100",page=Number.ToText(Page)],Timeout=#duration(0, 0, 1, 0)])),
in 
    Source[URLPath]

Unfortunately, M takes things literally and so tries to return URLPath. Is there a way to make it understand that this thing is dynamic. I looked around Record functions but could not see it. Thank you.


Solution

  • Record.Field is my answer.

    Record.Field(Source, URLPath)