Power Query DateTime.IsInCurrentSecond Function Explained
In this article
The DateTime.IsInCurrentSecond function in Power Query returns true if a given datetime value falls within the exact second that the query is currently being evaluated, and false otherwise. It is useful for filtering records that were created or updated in the current second during real-time data refreshes. This function requires no external setup — it is built into Power Query and works in Excel, Power BI, and other Microsoft data platforms that support M language. No additional tools or configurations are needed.
What You'll Need
- Microsoft Excel 2016 or later, or Power BI Desktop
- A data source loaded into Power Query (e.g., Excel table, CSV, SQL database)
- Basic familiarity with Power Query Editor
Step-by-Step
- Open your Excel workbook or Power BI Desktop file containing the data you want to analyze.
- Go to the Data tab in Excel (or Home tab in Power BI) and select "Get Data" or "Transform Data" to open Power Query Editor.
- In Power Query Editor, ensure your data table is selected in the left pane. If you have multiple queries, click the one containing the datetime column you want to evaluate.
- Locate the datetime column you wish to test. This must be a column with actual datetime values, not text. If your column is text, use "Change Type" > "Date/Time" first.
- Go to the "Add Column" tab in the ribbon, then click "Custom Column".
- In the Custom Column dialog box, enter a name for your new column, such as "IsCurrentSecond".
- In the Custom column formula box, type:
DateTime.IsInCurrentSecond([YourColumnName]), replacing "YourColumnName" with the exact name of your datetime column (e.g., [OrderTime]). - Click OK. A new column will appear with Boolean values: true or false.
- Filter the new column to show only rows where "IsCurrentSecond" equals true. To do this, click the filter dropdown in the new column header and uncheck "false".
- Review the filtered results — these are records where the datetime matches the exact second when the query refreshed.
- Click "Close & Load" to apply the changes back to your worksheet or report.
Common Mistakes
- Using text instead of datetime values: If your column is formatted as text (e.g., "2024-05-17 14:22:03"), DateTime.IsInCurrentSecond will return an error. Always convert text to Date/Time type first using the Transform tab.
- Assuming it works on historical data: The function only evaluates against the current system second at refresh time. It cannot determine if a past record was created in "the current second" from yesterday — only during the current query execution.
- Using it for time-based calculations: This function is not meant for duration comparisons, time zones, or intervals. It is strictly a binary check for exact second alignment.
- Expecting real-time streaming: Power Query does not refresh continuously. The function only triggers during manual or scheduled refreshes, not continuously like a live dashboard.
- Typing the function name incorrectly: The function is case-sensitive and must be exactly
DateTime.IsInCurrentSecond. Missing capitalization or typos will cause errors.
Tips
- Combine with other time functions: Use DateTime.IsInCurrentSecond alongside DateTime.LocalNow() to compare your data against the current moment programmatically.
- Use it for logging or audit trails: If you’re capturing timestamps from external systems, this function helps isolate records created during the exact moment of data ingestion.
- Test in a small sample first: Apply the function to a subset of 10–20 rows to verify behavior before scaling to large datasets.
- Refresh manually to observe behavior: Press "Refresh" in Power Query Editor to see how the true/false values change with each refresh — you’ll notice only one or two rows might flip to true, depending on timing.
- Remember network and system delays: The function uses the local machine’s system clock. If your data source is remote or the refresh is delayed, the second may be slightly off from the server time.
- Don’t rely on it for precision timing: For millisecond-level accuracy or high-frequency trading data, this function is insufficient. Use dedicated real-time systems instead.
Troubleshooting
- If you see "Expression.Error: The name 'DateTime.IsInCurrentSecond' wasn't recognized", your version of Power Query does not support it. This function is available from Excel 2019 and Power BI Desktop version 2.104.791 and later. Update your software via Microsoft Update or the Power BI Desktop download page.
- If the function returns blank instead of true/false, your column may contain null values. Use the Transform tab > Replace Values to replace nulls with a default datetime, or wrap the function in an if statement:
if [YourColumn] = null then false else DateTime.IsInCurrentSecond([YourColumn]). - If the column shows all false values, your data’s datetime is not synchronized with the system clock. Check if the source system uses UTC and your machine uses local time — consider using DateTimeZone.ToLocal() before applying the function.
- If the query fails to load after applying the function, check the Data Source Settings. Ensure the source is accessible and credentials are valid. Sometimes, the function causes evaluation delays on large tables — try filtering rows before applying the function.
- If the function works in Power BI Desktop but not in the service, note that the Power BI Service may use different server time zones. Use DateTimeZone.SwitchZone() to standardize time zones before applying DateTime.IsInCurrentSecond.
- For persistent errors, try recreating the query: Copy your data to a new query, reapply transformations, and re-add the custom column. Corrupted query steps can sometimes cause unexpected failures.
Frequently Asked Questions
Does DateTime.IsInCurrentSecond work with time zones?
It uses the local system clock of the device running Power Query. If your data is in UTC and your machine is in PST, the function compares against PST. To align with a different time zone, convert the datetime first using DateTimeZone.ToLocal() or DateTimeZone.SwitchZone().
Can I use this function to detect if a record was created in the last second?
No. This function checks only for exact alignment with the current second at the time of refresh. To find records from the last second, use DateTime.Now() minus a duration, such as [YourColumn] > DateTime.Now() - #duration(0,0,0,1).
Why does my function return false even though the time looks correct?
The system clock may have millisecond precision, but the function only matches the full second. If your data has milliseconds (e.g., 14:22:03.789), it will still match only if the second part is identical and the clock aligns at the exact moment of refresh.
Is this function available in Excel Online?
No. DateTime.IsInCurrentSecond is not supported in Excel Online or the web version of Power Query. Use only in desktop Excel or Power BI Desktop.
Can I use this in a calculated column in Power BI model?
No. This function is only available in Power Query during data transformation, not in DAX calculated columns. It cannot be used in the data model layer.
Will this function trigger a refresh if used in a scheduled report?
No. The function evaluates at refresh time, but it does not cause or trigger a refresh. Scheduled refreshes run on the Power BI Service or Excel’s refresh schedule — this function simply returns a value based on the system time during that scheduled run.