Dynamic URL in Power Query

Thirty_Noodles

New Member
Joined
Jan 14, 2025
Messages
6
Office Version
  1. 2024
Platform
  1. Windows
Hello all,

Is it possible to make a power query dynamic? For eample, if part of the URL is changed (for example within the cell of a spreadsheet or similar? I have the following Power Query:

Power Query:
let
    Source = Json.Document(Web.Contents("https://easytide.admiralty.co.uk/Home/GetPredictionData?stationId=0116")),
    tidalEventList = Source[tidalEventList],
    #"Converted to Table" = Table.FromList(tidalEventList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"eventType", "dateTime", "height", "isApproximateTime", "isApproximateHeight", "date"}, {"Column1.eventType", "Column1.dateTime", "Column1.height", "Column1.isApproximateTime", "Column1.isApproximateHeight", "Column1.date"})
in
    #"Expanded Column1"

Part of this query highlighted below in red needs to vary (e.g. from 0116 to 0111A) and ideally, this would be controlled via a cell dropdown or similar.

"https://easytide.admiralty.co.uk/Home/GetPredictionData?stationId=0116"


Is this achievable?

Thanks for any advice.

Noodles
 
Very feasible. Create a Named Range in Excel like the screenshot below. You can make this the dropdown.

1740068006636.png


And here is what your Power Query would look like:

Power Query:
let
    // Get the value from the named range "SheetName"
    SheetName = Excel.CurrentWorkbook(){[Name="SheetName"]}[Content]{0}[Column1],
    
    // Create the dynamic URL
    BaseUrl = "https://easytide.admiralty.co.uk/Home/GetPredictionData?stationId=",
    DynamicUrl = BaseUrl & SheetName,
    
    // Get data from the dynamic URL
    Source = Json.Document(Web.Contents(DynamicUrl)),
    tidalEventList = Source[tidalEventList],
    #"Converted to Table" = Table.FromList(tidalEventList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"eventType", "dateTime", "height", "isApproximateTime", "isApproximateHeight", "date"}, {"Column1.eventType", "Column1.dateTime", "Column1.height", "Column1.isApproximateTime", "Column1.isApproximateHeight", "Column1.date"})
in
    #"Expanded Column1"
 
Upvote 0
Solution
ExcelToDAX, this is genius!

Thanks very much for the swift response; it worked a treat!

Noodles.
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,226,835
Messages
6,193,230
Members
453,781
Latest member
Buzby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top