How to Create Dynamic API Date Variables in Power Query
Question details
The user needs to configure dynamic API date variables, specifically a fixed start date and a dynamic end date, within 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.
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).
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.
In the Power Query Editor, navigate to the Home tab on the ribbon and click on 'Advanced Editor'.
Inside the let block, create a text variable for your start date. For example, type: StartDate = "2023-01-01".
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.
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.

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. Download WPS Office: Visit the official WPS Office website and download the free installation package.
- 2. Install the application: Run the installer and follow the on-screen instructions to set up WPS Office on your device.
- 3. Open your spreadsheets: Launch WPS Spreadsheets and open your existing Excel workbooks to continue your data analysis without losing any formatting.

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.




