Create a Dynamic Power Query URL Using the Current Date in Excel
Question details
Create a Power Query URL that automatically includes the appropriate year and two-digit month for a regularly published price newsletter.

- Product
- Microsoft Excel Power Query
- Device & OS
- not provided
- Scenario
- The newsletter URL changes with each publication period, and the user wants the query to select the appropriate period automatically.
- Observed behavior
- The desired URL uses a calculated date, a four-digit year, and a zero-padded month that update when the query is refreshed.
Check the newsletter's actual URL pattern, including its fixed path, filename, and any encoded characters. Confirm when a new issue becomes available so you can adjust the date rule to match the publication schedule.
Build the newsletter URL with Power Query M
Use a blank query to calculate the publication period and assemble a URL that updates on refresh.
The example adds 15 days when the current day of the month is greater than 21; otherwise, it uses the current date. This selects the following month after the cutoff, but you should change the rule if the publisher follows a different schedule.
The domain and filename below are placeholders. Replace them with the publisher's exact URL pattern.
In Excel, select Data > Get Data > From Other Sources > Blank Query.
In Power Query Editor, select Home > Advanced Editor and replace the existing code with: let thisDate = Date.From(DateTime.LocalNow()), adjustedDate = if Date.Day(thisDate) > 21 then Date.AddDays(thisDate, 15) else thisDate, year = Text.From(Date.Year(adjustedDate)), month = Number.ToText(Date.Month(adjustedDate), "00"), URL = "https://example.com/documents/" & year & month & "-newsletter.pdf" in URL
In Advanced Editor, replace the example domain, path, and filename suffix with the actual fixed parts of the newsletter URL. Preserve any required URL encoding, then select Done.
Check the URL displayed in Power Query Editor against an available newsletter issue. Select Home > Close & Load, then use Data > Refresh All whenever you need to recalculate it.

Work with newsletter data in WPS Spreadsheet
WPS Office is a free, lightweight alternative for working with spreadsheet data in a familiar interface. Open compatible Excel files and continue editing in WPS Spreadsheet; it does not fix or replace the Microsoft Power Query M workflow described above.

Frequently Asked Questions
How does the query make the month two digits?
In Power Query's Advanced Editor, Number.ToText(Date.Month(adjustedDate), "00") formats months such as January as 01.
How do I change the publication cutoff?
Open the query in Power Query Editor and select Home > Advanced Editor. Change the condition Date.Day(thisDate) > 21 and the date adjustment to match the publisher's release schedule. A working-day schedule may require additional logic.
When does the URL update?
The date is recalculated when the query refreshes. In Excel, select Data > Refresh All to update it. The time zone used by DateTime.LocalNow can differ between desktop and cloud refresh environments.
Why does the query show a URL instead of the newsletter?
The example ends with URL, so it returns text. In Advanced Editor, change the final expression to Web.Contents(URL) to request the file, then add the appropriate steps for its file type.




