Forum Discussion

tjanssen's avatar
tjanssen
Frequent Visitor
5 years ago
Solved

Import data from API with dynamic URL in existing table

Hello everyone,  I'm have a question related to PowerBi and importing data from an API. The url of the api is dynamic and looks like: https://webapi.nl/api/1/measurements/ID1/ID2/YEAR(2020)/MONTH...
  • mahoneypat's avatar
    5 years ago

    It would be easier to turn your list of dates into a table, and then format those dates in the needed string you can append to your url inside the Web.Contents on each row.  To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

     

    let
    Source = List.Dates(#date(2020, 1, 1), Duration.Days(Duration.From(DateTime.Date(DateTime.LocalNow())-(#date(2020, 1, 1)))), #duration(1, 0, 0, 0)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "DateText", each Date.ToText([Column1], "yyyy/M/d"), type text),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Column1"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Columns", "Custom", each "url/"&[DateText])
    in
    #"Added Custom1"

     

    Regards,

    Pat