Power Query Today: How to Create Dynamic Date Columns
In this article
To get today's date in Power Query, use the formula DateTime.LocalNow() to capture the current system time and then wrap it in DateTime.Date() to remove the timestamp. This allows your reports to automatically update based on the current date every time the data is refreshed, eliminating the need to manually change date filters or hard-code dates into your queries.
Dynamic dates are essential for creating dashboards that show "Today," "Yesterday," or "Last 30 Days" without requiring a manual update every morning. By leveraging the Power Query M language, you can create a custom column or a standalone parameter that acts as a reference point for all your data filtering and calculations. This process works across Power BI Desktop and Excel's Get & Transform tools, though menu labels may differ slightly depending on your software version or region.
What You'll Need
- Microsoft Excel (with Power Query enabled) or Power BI Desktop.
- A dataset already loaded into the Power Query Editor.
- Basic familiarity with the Power Query interface (the Ribbon and the Formula Bar).
Step-by-Step
- Open the Power Query Editor: In Excel, go to the Data tab and select Get Data > Launch Power Query Editor. In Power BI, click on Transform Data from the Home ribbon.
- Create a Custom Column: Navigate to the Add Column tab on the top ribbon and select Custom Column. This opens a dialog box where you can define the logic for your new date field.
- Enter the Today Formula: In the Custom column formula box, type the following exactly:
= DateTime.Date(DateTime.LocalNow()).
Technical Breakdown:DateTime.LocalNow()retrieves the current date and time from your local system. However, because it includes the time (e.g., 2026-12-04 14:30:00), it can cause issues when comparing it to a date-only column. Wrapping it inDateTime.Date()strips the time component, leaving you with a clean date value. - Name the Column: In the New column name field at the top of the dialog, enter a descriptive name such as "Today's Date" or "Refresh Date." Click OK.
- Set the Data Type: By default, Power Query may assign the "Any" data type to your new column. Look at the icon to the left of the column header. Click the icon and select Date from the dropdown menu. This ensures that the column is recognized as a date for filtering and sorting purposes.
- Filter Data Using the Dynamic Date: To use this date for filtering (for example, to show only records from today), click the filter arrow on your actual data date column. Select Date Filters > Equals. Instead of picking a date from the calendar, you will need to modify the formula in the formula bar to reference your "Today's Date" column.
- Apply and Close: Once the column is created and verified, go to the Home tab and select Close & Apply to load the dynamic date logic into your main data model.
Common Mistakes
One of the most frequent errors is using DateTime.LocalNow() without the DateTime.Date() wrapper. If you do this, Power Query treats the value as a DateTime type. When you try to filter a Date column (which has no time) against a DateTime value (which does), the match will often fail because the time is rarely exactly midnight. This results in empty tables or missing data despite the date appearing to be correct.
Another common mistake is forgetting to set the data type. If the column remains as "Any," you may encounter errors when performing date subtractions (e.g., calculating the number of days between a transaction date and today). Always explicitly set the type to Date or Date/Time.
Users also frequently confuse DateTime.LocalNow() with DateTimeZone.LocalNow(). While both provide the current time, the latter includes time zone offsets. For most standard reporting needs, DateTime.LocalNow() is the simpler and more appropriate choice unless you are dealing with a global dataset spanning multiple time zones.
Tips
Create a Single-Value Table: Instead of adding a "Today" column to every row of a large dataset (which increases memory usage), create a separate query for the current date. Right-click in the Queries pane, select New Query > Blank Query, and enter = DateTime.Date(DateTime.LocalNow()) in the formula bar. Convert this to a table. You can then reference this single value in other queries using a merge or a custom filter, which is significantly more efficient for large datasets.
Calculating Relative Dates: Once you have today's date, you can easily find yesterday or the start of the month. To get yesterday, use Date.AddDays(DateTime.Date(DateTime.LocalNow()), -1). To find the start of the current month, use Date.StartOfMonth(DateTime.Date(DateTime.LocalNow())). These formulas allow you to build highly flexible reports that shift automatically as time progresses.
Handling Server Time: Be aware that if you publish your report to a cloud service (like Power BI Service), DateTime.LocalNow() will return the time of the server hosting the data, not your local computer's time. Servers often use UTC. To adjust for your specific time zone, you may need to use DateTimeZone.SwitchZone to shift the UTC time to your local offset.
Troubleshooting
If your date is not updating, the first thing to check is the Refresh settings. Power Query does not update in real-time as you watch the screen; it only updates when a manual refresh is triggered or a scheduled refresh occurs. Click the Refresh button on the Data tab in Excel or the Home tab in Power BI to force the calculation to run again.
If you see an "Expression.Error: We cannot convert the value to type Date," it means you are likely trying to perform a date operation on a column that is still formatted as Text or Any. Go back into the Power Query Editor, find the column in question, and ensure the data type is set to Date.
If the date returned is off by one day, check your time zone settings. This is common when working with cloud-based refreshes. If the server is in UTC and it is 11:00 PM in New York, the server already considers it "tomorrow." To fix this, you can add or subtract hours using DateTime.AddZone or DateTimeZone.SwitchZone to align the server time with your local business hours.
Frequently Asked Questions
Does Power Query update the date automatically?
Yes, but only upon data refresh. The formula calculates the date at the moment the query is executed. It does not change dynamically while the report is open unless you trigger a refresh of the data source.
Can I use this to create a "Last 7 Days" filter?
Yes. You can create a custom column that subtracts 7 days from today's date using Date.AddDays and then filter your data to include only rows where the date is greater than or equal to that calculated value.
Is there a simpler way than writing M code?
While you can use the user interface for many things, there is no "Today" button in the standard Add Column menu. Writing the short DateTime.LocalNow() formula is the most direct and standard method.
Will this work in both Excel and Power BI?
Yes, because both applications use the same Power Query engine and M language. The formula and the steps to implement it are identical in both platforms.
How do I get only the year or month from today?
You can wrap the today formula in other functions. For example, Date.Year(DateTime.Date(DateTime.LocalNow())) will return only the current year as a number.