How to Return Values Based on Date Column Headers in Power Query
Question details
The user needs a method to compare dynamic date column headers with specific milestone, purchase-order, and production dates to output corresponding labels or a blank.

- Product
- Excel Power Query
- Device & OS
- not provided
- Scenario
- Creating a dynamic Gantt-style view or milestone tracker where column headers are dates that need to be matched against project milestones.
- Observed behavior
- The user wants to evaluate date-based column headers against milestone columns to return text values like PO, PROD END, or milestone names dynamically.
Ensure your dataset is formatted as an Excel Table and that you have clearly identified the specific milestone columns you need to compare against the dynamic date headers.
Unpivot Date Columns and Add a Conditional Column
By unpivoting the dynamic date columns, you can transform them into rows, allowing you to easily compare each header date against your milestone dates using conditional logic.
Power Query handles dynamic column headers best when they are unpivoted. This transforms horizontal date columns into vertical data, making it possible to compare the dates row-by-row against your project milestones without breaking the query when new date columns are added.
Select your data table in Excel, then navigate to the Data tab and click 'From Table/Range' to open the Power Query Editor.
Select all the static (non-date) columns such as Project Name and ID. Right-click any of the selected column headers and choose 'Unpivot Other Columns'. The date headers will now appear in a new column called 'Attribute'.
Click the data type icon in the header of the new 'Attribute' column and select 'Date' to ensure the headers are recognized as valid dates for comparison.
Go to the Add Column tab and click 'Conditional Column'. Set up your logic: If [Attribute] equals [Milestone Date Column], then output the milestone name. Set the 'Otherwise' value to a blank or null.
Once the logic is applied, click 'Close & Load' on the Home tab to return the processed, Gantt-style data back to your Excel worksheet.

Use a PivotTable and Timeline for a Gantt-Style View
If you want to avoid maintaining complex Power Query setups or formulas, using a PivotTable combined with a Timeline can achieve a similar visual milestone tracker.
Manage Complex Data and Timelines Easily with WPS Office
If you are struggling with complex Power Query formulas and want an intuitive, lightweight solution for managing project timelines and spreadsheets, WPS Office offers powerful data processing tools as a free alternative to Microsoft Office.
- 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and follow the simple installation prompts.
- 2. Open your Excel Workbook: Launch WPS Spreadsheet and easily open your existing .xlsx or .xlsm files without losing any data formatting.
- 3. Utilize Built-in Data Tools: Use WPS Spreadsheet's advanced formulas, conditional formatting, and PivotTables to build dynamic Gantt charts and project milestone trackers.

Frequently Asked Questions
How do I handle dynamic column headers in Power Query?
The most robust method is to select your static columns, right-click, and choose 'Unpivot Other Columns'. This automatically converts any new or changing date column headers into rows, preventing the query from breaking when the source data changes.
Can I return a blank string instead of a null value in a conditional column?
Yes. When creating a Conditional Column in Power Query, you can leave the output field entirely blank, or you can manually adjust the generated M code in the formula bar to output "" instead of the default null.
Why are my unpivoted date headers turning into text?
When Power Query unpivots column headers, it typically defaults the new 'Attribute' column to a Text data type. To fix this, simply click the data type icon on the column header and manually change it to 'Date'.




