Power Query Problems

Create a Dynamic Power Query URL Using the Current Date in Excel

Adam DavisAdam Davis Dec 2, 2026 868 views

Question details

Create a Power Query URL that automatically includes the appropriate year and two-digit month for a regularly published price newsletter.

Create a Dynamic Power Query URL Using the Current Date in Excel
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.
Before you start

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.

Solution 1Recommended

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.

1
Create a blank query

In Excel, select Data > Get Data > From Other Sources > Blank Query.

2
Enter the M code

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

3
Match the publisher's 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.

4
Test and refresh the query

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.

Build the newsletter URL with Power Query M
To retrieve the file: The example returns the URL as text. To request its contents instead, change the final line from URL to Web.Contents(URL) in Advanced Editor. You may need to provide credentials and add further steps to interpret the returned file.
Free Microsoft Office alternative

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.

Review and organize newsletter price data in a spreadsheetOpen and edit compatible Microsoft Excel XLSX filesUse a familiar spreadsheet interface for an easier move from Microsoft OfficeWork with a free, lightweight office suite
microsoft office alternative - wps office

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.