Power Query Problems

How to Create Dynamic API Date Variables in Power Query

Khadija KhanKhadija Khan Oct 23, 2026 869 views

Question details

The user needs to configure dynamic API date variables, specifically a fixed start date and a dynamic end date, within Power Query.

How to Create Dynamic API Date Variables in Power Query
Product
Power Query / Power Apps
Device & OS
not provided
Scenario
Building a query to connect Power Apps to an API that requires dynamically updated date ranges in its URL.
Observed behavior
Needs to format dates, create parameter queries, and correctly pass dynamic end dates into the API URL to automate data retrieval.
Before you start

Ensure you have your base API URL ready and verify the exact date format required by your specific API endpoint (e.g., YYYY-MM-DD or MM/DD/YYYY).

Solution 1Recommended

Use M Code in the Advanced Editor

Create dynamic date parameters using built-in M functions in the Advanced Editor to seamlessly pass dates into your API URL.

To create a dynamic end date (like today's date) alongside a fixed start date, you can use built-in M language functions such as DateTime.LocalNow(). These dates must be formatted into text strings so they can be successfully appended to your API URL.

1
Open Advanced Editor

In the Power Query Editor, navigate to the Home tab on the ribbon and click on 'Advanced Editor'.

2
Define the fixed start date

Inside the let block, create a text variable for your start date. For example, type: StartDate = "2023-01-01".

3
Define the dynamic end date

Create a variable for today's date and convert it to text. Type: EndDate = Date.ToText(DateTime.Date(DateTime.LocalNow()), "yyyy-MM-dd"). Adjust the format string if your API requires a different layout.

4
Construct the API URL

Concatenate your base URL with the date variables using the '&' operator. For example: Source = Json.Document(Web.Contents("https://api.example.com/data?start=" & StartDate & "&end=" & EndDate)). Click 'Done' to apply the changes.

Use M Code in the Advanced Editor
Community Support for Power Apps: Because this query connects Power Apps to an API, Microsoft advises consulting the Power Platform Community if you encounter complex parameter integration issues.
Free Microsoft Office alternative

Looking for a Free and Lightweight Office Suite?

While Power Apps and Power Query API integrations are specific to the Microsoft ecosystem, WPS Office provides an outstanding, free alternative for all your regular spreadsheet and data analysis needs. Enjoy full compatibility with your existing files, a familiar interface, and a lightweight installation.

  1. 1. Download WPS Office: Visit the official WPS Office website and download the free installation package.
  2. 2. Install the application: Run the installer and follow the on-screen instructions to set up WPS Office on your device.
  3. 3. Open your spreadsheets: Launch WPS Spreadsheets and open your existing Excel workbooks to continue your data analysis without losing any formatting.
Fully compatible with Microsoft Excel (.xlsx, .xls) and CSV file formats.Completely free and lightweight alternative to heavy Office installations.Familiar user interface ensuring seamless migration with zero learning curve.Powerful built-in formulas, pivot tables, and charting tools for daily data analysis.
microsoft office alternative - wps office

Frequently Asked Questions

How do I format dates for API calls in Power Query?

You can use the Date.ToText() function in M code, specifying the exact format your API requires. For example, Date.ToText(myDate, "yyyy-MM-dd") will format the date into the standard API format.

Can I pass Power Apps variables into Power Query parameters?

Yes, Power Query parameters can be configured to accept inputs directly from Power Apps. This allows users to dynamically change query variables (like start and end dates) directly from the app's user interface.

Where can I find help for complex Power Apps and API integrations?

The Microsoft Power Platform Community forums are the best place to ask highly specific questions about connecting Power Apps to APIs and passing dynamic variables between the two environments.