Power Query Problems

How to Return Values Based on Date Column Headers in Power Query

Aamir Naveed AkramAamir Naveed Akram Nov 3, 2026 869 views

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.

How to Return Values Based on Date Column Headers in Power Query
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.
Before you start

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.

Solution 1Recommended

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.

1
Load data into Power Query

Select your data table in Excel, then navigate to the Data tab and click 'From Table/Range' to open the Power Query Editor.

2
Unpivot the date columns

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'.

3
Format as Date

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.

4
Add conditional logic

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.

5
Load the data back

Once the logic is applied, click 'Close & Load' on the Home tab to return the processed, Gantt-style data back to your Excel worksheet.

Unpivot Date Columns and Add a Conditional Column
Handling Dynamic Data: Using 'Unpivot Other Columns' ensures that if you add new date columns to your source data in the future, Power Query will process them automatically upon refresh.
Free Microsoft Office alternative

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. 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and follow the simple installation prompts.
  2. 2. Open your Excel Workbook: Launch WPS Spreadsheet and easily open your existing .xlsx or .xlsm files without losing any data formatting.
  3. 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.
Seamless compatibility with Microsoft Excel (.xlsx, .xlsm) formats and macros.Built-in robust PivotTable tools and conditional formatting to track milestones.Familiar, user-friendly interface that requires no steep learning curve.Lightweight installation that runs smoothly on Windows, Mac, and Linux.
microsoft office alternative - wps office

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'.