Power Query DateTime.IsInNextSecond: Quick How-To
In this article
DateTime.IsInNextSecond is an M formula function in Power Query that returns a single logical value, true or false, telling you whether a given datetime value falls inside the next full second after the moment Power Query evaluates the formula. In plain terms, it answers one narrow question: is this timestamp due to happen in the coming second? Because the clock keeps moving, this function is only meaningful when the expression is evaluated again and again, for example inside a dataset that refreshes on a schedule. If you simply hard-code it into a static query, it will most likely return false on every refresh, because by the time the query runs, the date column sits in the past.
The practical uses are narrow but real: flagging records that are about to become active, building a small "imminent" indicator in a refresh dashboard, or testing whether a calculated target time is about to arrive. Anything heavier, such as filtering rows by second-level precision, is better handled by comparing Timestamps directly. Note that the formula syntax can differ slightly by Power Query version and by whether you write in English or a localized function name, though the core behaviour stays the same.
What You'll Need
- A version of Power Query with the DateTime.IsInNextSecond function available (Power BI Desktop, Excel's Get & Transform, or Dataflows). The function ships alongside DateTime.IsInCurrentSecond and DateTime.IsInPreviousSecond.
- A column, expression, or variable that returns a real datetime value, not a text string that merely looks like a date.
- The Power Query Editor open, with the Advanced Editor accessible if you prefer writing M directly, or the formula bar if you prefer writing one step at a time.
- An understanding that the result changes with the clock. If your query does not refresh, the answer will not update either.
Step-by-Step
- Open your workbook or report and launch the Power Query Editor. In Excel, go to Data > Get Data > Launch Power Query Editor. In Power BI Desktop, use Home > Transform data. Labels can differ slightly by version, device or region, so look for the editor launch entry if the wording looks unfamiliar.
- Load the query that contains the datetime column you want to test. If you do not have one yet, use any table with a genuine Date/Time type column, or create one on the fly with a new blank query.
- Confirm the column type. Select the column header and check the type icon, then use Transform > Data Type > Date/Time if it currently reads as Text or Any. A text value such as "2026-12-05 13:00:00" will not behave like a datetime inside the function unless it is converted first.
- Add a Custom Column. Go to Add Column > Custom Column and name it something meaningful, such as IsNextSecond.
- Enter the formula. The function takes exactly one argument, so the pattern is
DateTime.IsInNextSecond([YourColumn]). Replace[YourColumn]with the column name from the Available columns list. Do not wrap the column name in quotes; quoted text is treated as a literal string. - Click OK. Power Query adds the column and fills it with true or false for each row. The column type will usually come back as True/False, which is the logical type.
- Inspect the result. On a static historical column, you should expect almost everything to be false. If you see nothing but true, wait a few seconds and refresh the preview; anything that was genuinely "next second" is likely already gone.
- To test the moving-clock behaviour, create a separate helper query with a single value:
DateTime.LocalNow(). Then reference it through a one-second offset,Date.AddSeconds(DateTime.LocalNow(), 1), and pass that into DateTime.IsInNextSecond. That expression should reliably return true, which confirms the function is wired correctly. - If you are comfortable writing M directly, open the Advanced Editor and place the same expression in a step, for example
AddedFlags = Table.AddColumn(Source, "IsNextSecond", each DateTime.IsInNextSecond([Timestamp])). This is handy when you want the formula nested rather than as its own query step. - Set refresh behaviour. In Excel, use Data > Refresh All or set a refresh interval through the connection's properties. In Power BI, schedules live under the dataset settings in the Power BI service. Remember the service runs your query on its own clock, which may differ from your local machine's time zone and time.
- Close and load, then validate a few rows against your source data to confirm the flags line up with your expectations for timestamps that are actually seconds away.
Common Mistakes
The most frequent problem is expecting the function to filter a historical table rather than annotate a moving window. Because DateTime.IsInNextSecond compares each value against the moment of evaluation, a table of past events will yield all false, and newcomers often read that as a broken formula.
Another common slip is passing text. If your source column is typed as Text, the function returns an error or a misleading result rather than flagging the type mismatch loudly. Always convert to Date/Time first.
Wrapping the argument in square brackets incorrectly is also easy to do. The argument should be the column reference itself, not a string, and not wrapped in additional quotation marks. Similarly, forgetting that the function is case-sensitive in its name causes a "did not recognize the name" error in the Advanced Editor.
Finally, comparing a UTC-based value with a local-clock evaluation is a classic source of confusion. If your column stores UTC and Power Query evaluates against local time, the answer will be off by your time-zone offset and the function will look erratic.
Tips
- Use the sibling functions together: DateTime.IsInCurrentSecond tells you about the current second, IsInPreviousSecond about the second that just passed. Comparing all three is useful when exploring behaviour.
- Store the evaluation moment in a variable rather than calling DateTime.LocalNow() repeatedly in one expression, so the comparison is consistent across rows.
- Second-level logic is inherently unstable in a refresh pipeline. If you need reliable filtering, compare full DateTime values or use a wider window such as minutes or hours, which tolerates the delay between a query being queued and being run.
- Name the custom column clearly, such as IsNextSecondFlag, to avoid confusion with the function name itself when you reference it later.
- Keep the column as logical type rather than converting to text; Power BI and Excel filter, sort on, and slice by true/false far more efficiently than by strings.
Troubleshooting
If the Custom Column dialog returns "Expression.Error: We cannot apply function to a value of type Text," confirm the column's Data Type is Date/Time and reapply. If the function name itself is underlined with "The name 'DateTime.IsInNextSecond' wasn't recognized," check spelling and capitalisation; the function is a single word segment after the dot, and the D, I and S letters are all capitalised in the official name.
If the added column shows only false, that is usually expected on fixed data. To prove the function works, run the Date.AddSeconds test from the steps above, or open the query on a refresh and watch the value flip for a row whose timestamp is mined from the clock.
If performance suffers on a large table, remember the function is evaluated per row. Reconsider whether second-level granularity is genuinely needed; often a simple comparison against a fixed reference time is quicker and more predictable. If a query returns an error on blank values, wrap the argument in a null check with if [YourColumn] = null then false else DateTime.IsInNextSecond([YourColumn]).
If you are unsure whether the function exists in your environment, test it in the Advanced Editor with a minimal expression such as DateTime.IsInNextSecond(DateTime.LocalNow()). A name error there confirms the version lacks it; a true or false confirms it works.
Frequently Asked Questions
What does DateTime.IsInNextSecond actually return?
A single logical value, true or false. It is not a filter and does not change the datetime itself.
Why does the function return false for all my rows?
Because the column contains past values. Only timestamps that fall in the coming second evaluate to true, so a static table will almost always be false throughout.
Can I use it on a text column that contains dates?
Not directly. Convert the column to Date/Time first with Transform > Data Type. Doing this also prevents confusing errors.
Does the result update automatically?
No. It recalculates when the query refreshes, whether that is a manual refresh in Excel or a scheduled refresh in the Power BI service.
Is there a time-zone version?
Use DateTimeZone.IsInNextSecond for values that carry their own zone offset. Mixing plain DateTime and zone-aware values in one comparison is a frequent source of wrong answers.
Should I use this to build alerts?
Only loosely. Second-level windows are too tight for scheduled refresh pipelines; use a wider window such as the next minute for anything that needs to fire reliably.