How to Generate Future Weekly Dates and Fill Stock Values in Power Query
Question details
The user needs to create missing future week-ending rows for items in Power Query and automatically carry forward the latest closing-stock value to those new rows.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Managing inventory or stock data where weekly records have gaps, and the previous stock value must be carried forward to maintain an accurate ongoing inventory count.
- Observed behavior
- The current dataset skips weeks where no activity occurred, leaving gaps in the date sequence and missing stock values for those empty weeks.
Ensure your dataset is formatted as an Excel Table and contains clear columns for the Item ID, Week Ending date, and Available Value.
Use Power Query to Generate Dates and Fill Down
Use Power Query's advanced grouping and custom function capabilities to dynamically generate a sequence of weekly dates and fill the inventory values forward.
By grouping the data by item and calculating the duration between the minimum and maximum dates, Power Query can generate a complete list of missing weekly dates. Merging this list back with your data allows you to apply a Fill Down operation to carry the last known stock value forward.
In Excel, go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor, click the Home tab and select Advanced Editor to input your custom M code.
Select your Item column, navigate to the Transform tab, and click Group By to isolate the processing of date ranges for each specific item.
Use the List.Dates function in your M code to generate a sequence starting from the minimum date to the maximum date, stepping by a duration of 7 days (#duration(7, 0, 0, 0)).
Perform a Left Outer Join to merge your newly generated date table with your original source data matching on the 'Week Ending' column, then expand the 'Available Value' column.
Select the newly expanded 'Available Value' column, go to the Transform tab, and click Fill > Down. This replaces the null values in the newly generated weeks with the last available closing stock value.

Use Excel Lookup Formulas and Fill Down Logic
If you prefer not to use Power Query M code, you can manually build a structured table in Excel and use formulas to fetch and carry forward stock values.
Manage Complex Inventory Data Seamlessly with WPS Office
While advanced Power Query M scripting is specific to Microsoft Excel, WPS Spreadsheet offers a robust, lightweight, and completely free alternative for managing complex datasets. Easily handle large inventory lists and perform advanced lookups without the high subscription costs.
- 1. Download and Install: Visit the official WPS website, download the free installation package, and install WPS Office on your device.
- 2. Open Your Data: Launch WPS Spreadsheet and simply open your existing Excel (.xlsx) inventory files to start managing your data.
- 3. Apply Formulas: Utilize the built-in formula tab to easily execute data lookups and manage missing weekly values seamlessly.

Frequently Asked Questions
Why is the Power Query Table.FillDown function not replacing my blank cells?
Table.FillDown only works on true 'null' values. If your cells contain empty strings or spaces instead of nulls, the fill down will fail. You may need to replace blank strings with nulls in the Transform tab before applying the Fill Down step.
Can I generate daily dates instead of weekly dates in Power Query?
Yes. When using the List.Dates function, change the duration parameter from #duration(7, 0, 0, 0) to #duration(1, 0, 0, 0) to step the sequence by one day at a time instead of seven.
How can I improve the processing speed of my custom Power Query function?
Complex grouping and custom functions can be resource-intensive. To speed it up, go to Query Options, disable 'Allow data previews to download in the background', and set your Current Workbook Privacy Levels to 'Ignore'.




