Calculate Days Between Two Dates: Power BI DAX DATEDIFF
Calculate days between two dates in Power BI with DAX DATEDIFF. Compare date subtraction, handle blanks, and use complete column and measure examples.
By Felix Su
Use DATEDIFF ( Orders[StartDate], Orders[EndDate], DAY ) to calculate the number of days between two dates in Power BI. This DAX date difference returns the count of day boundaries, not elapsed 24-hour periods. Guard missing dates with ISBLANK; choose date subtraction when you need fractional elapsed days.
That one sentence about boundaries is the whole game. DATEDIFF does not measure how much time has passed; it counts how many day, month or year edges you cross. Get that wrong and a "days to deliver" column can be off by one across thousands of rows — quietly, with no error message.
This guide walks through the official DATEDIFF behavior documented by Microsoft, the mistakes that produce wrong results, the three ways to compute a DAX date difference, and the patterns that keep date logic accurate at scale — including how it fits into a unified analytics platform like Singdata's data infrastructure.
Key Takeaways
DATEDIFF returns the number of interval boundaries crossed, not complete elapsed units: 23:59 to 00:01 the next day returns 1 DAY despite only two elapsed minutes.
The signed result is positive when the end date is later than the start date, and negative when the argument order is reversed.
Intervalmust be an unquoted keyword (DAY,MONTH,YEAR…), written as a constant rather than a quoted string.Calculated columns suit row-level durations; measures suit durations that must respond to filters. Neither is automatically faster — profile your own model.
Guard missing dates with ISBLANK; convert text to typed dates with an explicit locale in Power Query before using DAX.
Simple
DATEDIFFover two date columns works without a marked date table; one becomes useful once you filter time ranges that span several tables.
What is the DATEDIFF Function in DAX?

DATEDIFF is a DAX date-and-time function that returns the number of interval boundaries between two dates, expressed as a signed integer. It answers questions such as "How many days did this order take to ship?" or "How many months has this account been active?" without hand-built date arithmetic.
According to Microsoft's documentation, DATEDIFF counts how many times a given interval boundary is crossed — not how many complete units have elapsed. That single sentence explains most of the "unexpected" results people report, and it's worth internalizing before you write a formula.
Syntax of the DATEDIFF Function
The syntax is compact and consistent:
DATEDIFF(<Date1>, <Date2>, <Interval>)
Here is what each argument does:
<Date1>: The start date, provided as a scalar datetime value.<Date2>: The end date, also a scalar datetime value.<Interval>: The unit to measure, written as a keyword such asDAY,MONTH, orYEAR— not as a quoted string.
For example, to calculate the number of days between two columns:
DeliveryDays = DATEDIFF('Orders'[OrderDate], 'Orders'[DeliveryDate], DAY)
This returns a positive number of days when the delivery date is later than the order date, and a negative number if the two are reversed.
Two arguments deserve a caveat. <Date1> and <Date2> must each resolve to a single value in the current context; a column reference is fine inside a row context (a calculated column), but not directly inside a measure that is evaluated once per visual. And a Date value carries no timezone — Power BI stores a naive datetime — so any timezone correction has to happen before the value reaches the model.
Supported Time Units for Date Differences
DATEDIFF supports eight interval keywords:
SECOND: Difference in seconds.
MINUTE: Difference in minutes.
HOUR: Difference in hours.
DAY: Difference in days.
WEEK: Difference in weeks.
MONTH: Difference in months.
QUARTER: Difference in quarters.
YEAR: Difference in years.
The Boundary-Crossing Behavior (The Part Most Guides Miss)
Because DATEDIFF counts boundaries rather than elapsed time, the result can be larger than a human would intuitively expect. Take two timestamps:
-- October 28, 2025 10:15 to November 1, 2025 08:00
DaysCrossed = DATEDIFF(DATE(2025,10,28) + TIME(10,15,0), DATE(2025,11,1) + TIME(8,0,0), DAY)
The timestamps are 3 days, 21 hours and 45 minutes apart, yet the expression returns 4 because four midnight boundaries were crossed. Changing the end to 30 October 2025 08:00 returns 2 despite fewer than 48 elapsed hours.
The same logic applies to coarser units: DATEDIFF(DATE(2025,10,28), DATE(2026,1,1), MONTH) returns 3, because November, December and January boundaries were crossed even though only two full months elapsed. If your business definition of "months active" means complete calendar months, pair DATEDIFF with additional logic — subtracting 1 when the end day-of-month is earlier than the start day-of-month is the common fix — instead of trusting the raw count.
Three Ways to Compute a Date Difference
DATEDIFF is not the only option, and it is not always the right one. Direct subtraction, Power Query's Duration.Days, and DATEDIFF each answer a slightly different question, so pick the one that matches your definition of "a day."
Method | Typical use case | Precision: boundaries vs. elapsed days | Data types returned | Missing-value guard | Refresh context |
|---|---|---|---|---|---|
| Whole-day counts for SLA, delivery lag, aging buckets | Counts midnight/day boundaries crossed; ignores elapsed hours | Integer | IF ( ISBLANK ( StartDate ) || ISBLANK ( EndDate ), BLANK (), DATEDIFF ( StartDate, EndDate, DAY ) ) | Calculated column → refresh; measure → query |
| Precise elapsed time, fractional days, sorting | Elapsed days with a fractional part when either operand holds a time; | Decimal (double) | Explicit | Same as above |
| Power Query ETL, precomputing a lag column upstream | Returns only the day component of a duration; drops the fractional hours | Number; assign Int64.Type to the output column when needed |
| Evaluated during Power Query refresh only |
| ETL where fractional days are needed | Total elapsed days, including the fractional part | Number (fractional) | Same as | Power Query refresh only |
Use DATEDIFF with DAY for calendar-boundary counts. Use subtraction or Duration.TotalDays for fractional elapsed days. A duration of 1.75 days may cross either one or two midnights, depending on the start time.
Microsoft describes Duration.Days as the days component of a duration. Power Query durations have days, hours, minutes and seconds, not calendar months or years. For #duration(2, 12, 0, 0), Duration.Days returns 2 and Duration.TotalDays returns 2.5.
A Self-Contained Sample Table You Can Paste and Run
In Power BI Desktop, choose Modeling > New table and paste this calculated-table definition. It creates five test rows with no existing model dependencies. After creating DateExamples, run the EVALUATE query below in DAX query view or DAX Studio. Example configuration — validate in your target environment.
DateExamples =
UNION (
ROW ( "Label", "Same timestamps, no boundary", "StartDate", DATE ( 2025, 1, 1 ) + TIME ( 8, 0, 0 ), "EndDate", DATE ( 2025, 1, 1 ) + TIME ( 20, 0, 0 ) ),
ROW ( "Label", "Across two midnights", "StartDate", DATE ( 2025, 1, 1 ) + TIME ( 23, 30, 0 ), "EndDate", DATE ( 2025, 1, 3 ) + TIME ( 0, 30, 0 ) ),
ROW ( "Label", "Reversed order", "StartDate", DATE ( 2025, 3, 10 ), "EndDate", DATE ( 2025, 3, 1 ) ),
ROW ( "Label", "Date only, four days", "StartDate", DATE ( 2025, 6, 1 ), "EndDate", DATE ( 2025, 6, 5 ) ),
ROW ( "Label", "Blank end date", "StartDate", DATE ( 2025, 7, 1 ), "EndDate", BLANK () )
)
A single EVALUATE then shows what each method does with those rows:
EVALUATE
ADDCOLUMNS (
DateExamples,
"@BoundaryDays", DATEDIFF ( [StartDate], [EndDate], DAY ),
"@ElapsedDays", [EndDate] - [StartDate],
"@BlankSafe", IF ( ISBLANK ( [StartDate] ) || ISBLANK ( [EndDate] ), BLANK (), DATEDIFF ( [StartDate], [EndDate], DAY ) )
)
Expected results, row by row: 0 boundary days for the 8:00-to-20:00 pair on the same date; 2 for 23:30 to 00:30 two nights later (elapsed is about 1.04 days); -9 for the reversed pair; 4 for June 1 to June 5; and BLANK() for the last row under @BlankSafe instead of a misleading number.
Example: Using DATEDIFF to Calculate Days Between Two Dates
Now the everyday case: an Orders table with OrderDate and DeliveryDate, and a request to report the DAX days between two dates per order. Everything below assumes both columns are typed as Date or Date/Time — check that first in the Data view, because a text-typed date column is the most common reason a DATEDIFF in Power BI misbehaves.
The reliable row-level pattern is a calculated column with an explicit guard:
DeliveryDays =
IF (
ISBLANK ( Orders[OrderDate] ) || ISBLANK ( Orders[DeliveryDate] ),
BLANK (),
DATEDIFF ( Orders[OrderDate], Orders[DeliveryDate], DAY )
)
For a real order placed 2 January 2026 and delivered 5 January 2026, the column returns 3. When the same order is delivered on 6 January instead, it returns 4. And a row with no delivery date returns a blank cell rather than a suspicious value.
For a Power BI calculate number of days between two dates task, decide first whether the result belongs to each row or to the current report selection. The examples below cover both.
DAX Number of Days Between Two Dates as a Measure
A DAX number of days between two dates measure evaluates in the current filter context for each visual result cell, rather than storing one value per source row.
When the dates should come from slicers rather than each row, a measure that resolves one value with SELECTEDVALUE is the right shape. Note what it does not do: it doesn't pair a MIN start date with a MAX end date from unrelated rows, because that invents a range nobody selected.
SelectedRangeDays =
VAR StartDate = SELECTEDVALUE ( 'DateRange'[StartDate] )
VAR EndDate = SELECTEDVALUE ( 'DateRange'[EndDate] )
RETURN
IF (
ISBLANK ( StartDate ) || ISBLANK ( EndDate ),
BLANK (),
DATEDIFF ( StartDate, EndDate, DAY )
)
Create a DateRange table containing the allowed start/end pairs, and select exactly one row or pair. The measure returns 10 for 1 January 2026 to 11 January 2026. SELECTEDVALUE returns BLANK when a column has zero or multiple distinct values. For independent date slicers, use two disconnected date tables and reference one selected date from each.
Summing Row Differences with SUMX
A row-level duration and a total want different functions. Aggregating the calculated column with SUM adds up per-row day counts correctly, but SUMX keeps the logic in one place and reads the row context explicitly:
TotalDeliveryDays =
SUMX (
Orders,
IF (
ISBLANK ( Orders[OrderDate] ) || ISBLANK ( Orders[DeliveryDate] ),
BLANK (),
DATEDIFF ( Orders[OrderDate], Orders[DeliveryDate], DAY )
)
)
Two orders of 3 and 4 days return 7. One order of 3 days and a blank row return 3, because SUMX ignores the blank. Left unguarded, the blank row may contribute an unexpected value instead — which is exactly why the guard lives inside the iterator.
Pulling Dates Across Tables with RELATED
When the end date lives on a related table, pull it across with RELATED instead of hunting for LOOKUPVALUE. That requires a relationship that is active, one-to-many (one on the lookup side, many on the fact side), and has a single matching row per fact row. A blank result is also meaningful: RELATED returns blank when no related row exists.
Set it up first: Orders has a foreign key ShipmentId; Shipments has a unique ShipmentId and the DeliveredDate. In Model view, drag Shipments[ShipmentId] onto Orders[ShipmentId]. Power BI usually detects one-to-many with Shipments as the one side — confirm the cardinality and cross-filter direction in Edit Relationship before trusting it.
OrderDeliveryDays =
IF (
ISBLANK ( Orders[OrderDate] ) || ISBLANK ( RELATED ( Shipments[DeliveredDate] ) ),
BLANK (),
DATEDIFF ( Orders[OrderDate], RELATED ( Shipments[DeliveredDate] ), DAY )
)
An order placed 2 January 2026 with a delivery logged on 9 January 2026 returns 7. Blank results signal a missing related row; a broken or missing relationship fails at the model level, so fix cardinality or the join key there rather than patching the formula.
Days From or To TODAY()
TODAY() returns the current date at midnight. Do not infer its business timezone from the workspace region. Validate the result in the deployed Power BI Service around midnight; for a fixed business calendar, supply an explicit as-of date from a controlled source.
Tenure as a calculated column and tenure as a measure behave differently:
TenureDaysColumn =
IF ( ISBLANK ( Employees[HireDate] ), BLANK (), DATEDIFF ( Employees[HireDate], TODAY (), DAY ) )
TenureDaysMeasure =
VAR AsOfDate =
IF ( ISBLANK ( SELECTEDVALUE ( Employees[HireDate] ) ), BLANK (), TODAY () )
RETURN
IF (
ISBLANK ( SELECTEDVALUE ( Employees[HireDate] ) ),
BLANK (),
DATEDIFF ( SELECTEDVALUE ( Employees[HireDate] ), AsOfDate, DAY )
)
The calculated column is fixed at the last model refresh; the measure evaluates when queried, subject to report and query caching. With an as-of date of 25 November 2026, a hire date of 1 November returns 24. On the next day, a fresh query can return 25 while an unrefreshed column remains 24.
Tip: If your report must show "as of" the report date rather than the server clock, feed a
MAX ( 'Date'[Date] )value or a parameter into the measure instead of callingTODAY()twice.
Five Common DATEDIFF Mistakes and Their Fixes
Before the scenario walkthroughs, front-load the mistakes that generate most of the support threads about the datediff DAX function. Each one has a clean fix.
1. Reversed dates. DATEDIFF(Date1, Date2, ...) returns a negative value when Date1 is later than Date2. If a "days to ship" metric suddenly goes negative, someone swapped the arguments. Fix it by ordering the columns correctly, or wrap the result in ABS() if the direction genuinely does not matter.
2. Aggregated results in a visual. A row-level DATEDIFF computes a value per row, but Power BI may sum those values in a visual by default, producing a number far larger than any individual duration. Change the aggregation to Do not summarize, or move the logic into a measure that returns the value you actually want to display.
3. Using DATEDIFF where a measure needs a single value. DATEDIFF expects scalar dates. Placed directly in a measure over many rows, it raises "A single value for column ... cannot be determined." Use a calculated column, resolve one pair with SELECTEDVALUE, or iterate rows with SUMX so each evaluation sees one date pair.
4. Quoting the interval. The interval must be an unquoted constant keyword. DATEDIFF('T'[A], 'T'[B], "DAY") fails where DATEDIFF('T'[A], 'T'[B], DAY) succeeds. Watch for this especially when adapting SQL snippets, where the unit is often a string.
5. Text or blank date columns. If either date is stored as text or is blank, DATEDIFF returns unexpected or error results. Confirm the column data type is Date or Date/Time, and handle blanks explicitly before calculating.
Keep these five in mind and the majority of "DATEDIFF is broken" moments disappear.
Practical Scenarios to Calculate Date Differences

How does this look in a report? A DAX date difference shows up as a delivery lag column, a tenure measure and a project duration side by side, and a Power BI date difference visual usually mixes all three.
The same function covers delivery lag, tenure and project duration. What changes is the interval and where the result lives — a column for row-by-row truth, a measure for whatever the slicer says.
Calculating Order and Shipping Date Differences
Delivery performance starts with a per-order lag:
DeliveryTime = DATEDIFF ( Orders[OrderDate], Orders[ShipDate], DAY )
An order placed on 2 January 2026 and shipped on 2 January 2026 returns 0 — same calendar day, no midnight crossed. Shipped on 4 January, it returns 2. Averaging that column per region or SKU gives a lag trend; the guard from the previous section keeps undated orders out of the average.
Measuring Employee Tenure in Years
Switch the interval to YEAR and the boundary quirk reappears at calendar scale:
TenureYears = DATEDIFF ( Employees[HireDate], TODAY (), YEAR )
An employee hired 1 March 2020 reports 6 years on 25 November 2026 — correct, since six year-boundaries were crossed. Hired 20 December 2020, they report 6 as well on that same date, even though five years and eleven months have elapsed. For HR reporting that must match an anniversary date, subtract 1 when the hire month/day falls later in the year than today's month/day.
Comparing Start and End Dates for Projects
Projects usually want months, and a monthly boundary count is often too generous. Keep MONTH for a quick estimate and DAY when the delivery contract is measured in days:
ProjectDuration = DATEDIFF ( Projects[StartDate], Projects[EndDate], MONTH )
ProjectDays = DATEDIFF ( Projects[StartDate], Projects[EndDate], DAY )
A project running 15 January 2026 to 14 March 2026 returns 2 months and 58 days. The month figure is a boundary count; the day figure is the one an audit will accept.
Tip: Conditional formatting on the day column — highlight anything above a threshold you define — surfaces delays faster than a table of raw numbers.
Advanced Techniques for Power BI Date Difference Calculations
When a report needs to switch between order-date and ship-date relationships, use the Power BI USERELATIONSHIP guide for order date versus ship date. Relationship selection controls which date filters a measure; DATEDIFF answers a separate question about the interval between two dates.Using Conditional Logic in DAX for Date Calculations
Conditional logic in DAX allows you to create dynamic calculations based on specific date conditions. For example, you can use an IF statement to categorize tasks as overdue, due today, or upcoming. This approach helps you manage deadlines effectively.
Here’s an example of a DAX formula that checks if a task is overdue:
TaskStatus = IF('Tasks'[DueDate] < TODAY(), "Overdue", "On Time")
A calculated column using TODAY() changes at model refresh. Use a measure for query-time evaluation, and guard missing DueDate values before comparing them.
Example: Handling Missing or Null Dates in Calculations
The row-level and measure patterns above already assume this, but it deserves its own walkthrough: a DAX date difference is only as trustworthy as the blanks you filtered out. Open orders without a ship date, orders whose OrderDate arrived as text, and placeholder dates like 1900-01-01 all bend averages if you let them through.
Flag them first, so the size of the problem is visible:
IsDateMissing = IF ( ISBLANK ( 'Table'[DateColumn] ), "Missing", "Present" )
A quick Count of Missing per table tells you whether this is three rogue rows or a broken ingestion pipeline — two very different problems.
Keep unknown dates blank for duration metrics. If a separate display or export requires a sentinel date, the following expression is possible, but never feed the sentinel into DATEDIFF or duration averages.
AdjustedDate = COALESCE('Table'[DateColumn], DATE(1900,1,1))
Caution: neither TODAY() nor 1900-01-01 is a neutral duration input. Both can distort historical metrics. Preserve BLANK for unknown dates and expose a separate missing-data flag.
Another method involves excluding rows with null dates from your calculations. Use a filter to remove these rows when creating measures or visuals. For example:
ValidDuration =
VAR StartDate = SELECTEDVALUE ( 'Table'[StartDate] )
VAR EndDate = SELECTEDVALUE ( 'Table'[EndDate] )
RETURN
IF ( ISBLANK ( StartDate ) || ISBLANK ( EndDate ), BLANK (), DATEDIFF ( StartDate, EndDate, DAY ) )This measure resolves one start/end pair in the current filter context and returns BLANK when either is missing or ambiguous. Use the earlier SUMX measure when you need the sum of valid per-row durations.
By addressing missing or null dates, you can improve the reliability of your Power BI reports. These techniques help you maintain clean data and avoid misleading insights.
Handling Time Zones and Date Formats in Power BI
A DAX date value has no timezone attached to it. Power BI stores date values as local (naive) datetimes without an offset, so the same wall-clock value loaded from Singapore and from UTC is indistinguishable in the model. Any correction has to happen earlier — at ingestion or in Power Query — not inside DATEDIFF.
Normalize source timestamps to a documented canonical timezone, often UTC, before loading. For datetimezone inputs, use DateTimeZone.ToUtc and then DateTimeZone.RemoveZone if a timezone-free model value is required. Derive a separate business-local date upstream when reporting uses local calendar boundaries.
Parsing deserves equal care. Date.FromText ( "25/11/2025", [Format = "dd/MM/yyyy", Culture = "en-GB" ] ) is explicit about both pattern and locale; FORMAT in DAX turns a date into text and is the wrong tool for going the other way. A locale mismatch between source and model is also the usual suspect when dates silently flip month and day.
DateTimeZone.SwitchZone uses an explicit offset, not an automatic regional daylight-saving rule. DateTimeZone.ToLocal depends on the execution environment and can differ between Desktop and Service. Use source-side named-timezone conversion or an explicit, maintained timezone rule table for historical daylight-saving transitions.
Ensuring Correct Data Types for Date Columns
Before any timezone work, confirm both columns are typed Date or Date/Time. A text-typed date column produces unexpected DATEDIFF results, so check the Data view, then use Transform Data to set the type and locale on the source column. This also prevents the locale mismatch that shows up as an "Incorrect date format" warning.
Troubleshooting and Common Errors
Example: Debugging Incorrect Date Difference Results
Incorrect date difference results in Power BI can lead to misleading insights. Debugging these issues requires a systematic approach. Here’s how you can identify and resolve common problems:
Verify Data Types
Ensure your date columns use the correct data type. Power BI requires columns to be formatted asDateorDate/Timefor accurate calculations. If your data appears as text, convert it to the appropriate format. Use the "Data Type" dropdown in the "Modeling" tab to make this adjustment.Check for Null or Missing Dates
Missing dates often cause errors in DAX calculations. Use theISBLANKfunction to identify rows with null values. For example:IsDateMissing = IF(ISBLANK('Table'[StartDate]), "Missing", "Present")Preserve missing dates as BLANK rather than substituting a historical sentinel. Exclude them from duration metrics using the blank-safe formulas above. A display label can be handled separately:
DateStatus = IF ( ISBLANK ( 'Table'[StartDate] ), "Missing", "Present" )Validate Date Ranges
Incorrect results may occur if the start date is later than the end date. Use a calculated column to flag such cases:InvalidRange = IF('Table'[StartDate] > 'Table'[EndDate], "Invalid", "Valid")Filter out invalid rows to ensure accurate calculations.
Review Time Units in DATEDIFF
Double-check the time unit specified in yourDATEDIFFfunction. Using the wrong unit (e.g.,MONTHinstead ofDAY) can produce unexpected results. Confirm that the unit aligns with your analysis goals.
Tip: Use a table visual to display intermediate results side by side with the raw dates. The offending row is usually visible at a glance.
Test with Sample Data
Create a small dataset with known date values. Apply your DAX formula to this dataset to verify its accuracy. Testing with controlled data makes it easier to pinpoint errors.
By following these steps, you can troubleshoot and fix incorrect date difference results in Power BI. Debugging ensures your reports provide reliable and actionable insights.
You now have a repeatable approach for calculating date differences in Power BI. At its core, the DATEDIFF function needs only a start date, an end date, and a time interval — the nuance is remembering that it counts boundaries, not elapsed time. Across seconds, weeks and quarters, it answers almost every duration question a business can ask.
Confirm typed scalar dates in start-then-end order, choose boundaries or elapsed time deliberately, guard blanks, and test known inputs. If source timestamps need centralized timezone rules or quality checks, implement those upstream in the data platform before the Power BI model.
FAQ
How do I calculate the days between two dates from two columns in Power BI?
Add a calculated column with DATEDIFF ( Orders[StartDate], Orders[EndDate], DAY ). Each row returns a signed integer count of midnight boundaries between the two values. Set the column's summarization to "Do not summarize" so a visual doesn't add per-row days into a meaningless total.
How do I calculate a date difference when the dates live in different tables?
Create an active one-to-many relationship from the table holding the date (the "one" side) to the fact table (the "many" side), then use RELATED ( Shipments[DeliveredDate] ) inside the calculated column. If no active relationship exists, RELATED returns an error, so confirm the relationship's cardinality and filter direction before writing the formula.
How do I get days from or to TODAY() without the result drifting?
Use the blank-safe TenureDaysColumn or TenureDaysMeasure above. The column updates at model refresh; the measure resolves one hire date with SELECTEDVALUE and evaluates when queried. For days remaining, reverse the arguments or compare TODAY() with a due date. Validate Service behavior and caching, or use an explicit as-of date.
What happens with BLANK, null, or invalid text dates?
Missing operands can produce unexpected date arithmetic instead of a useful error. Use IF ( ISBLANK ( Orders[StartDate] ) || ISBLANK ( Orders[EndDate] ), BLANK (), DATEDIFF ( Orders[StartDate], Orders[EndDate], DAY ) ). Convert invalid text to typed dates with an explicit locale upstream, and flag or quarantine conversion failures.
Should I use DATEDIFF or plain subtraction for elapsed time?
Use DATEDIFF when "days" means calendar days as a human would count them. Use EndDate - StartDate when you need fractional elapsed days from datetime values, and Duration.TotalDays in Power Query for the same fractional measure during ETL. DATEDIFF counts interval boundaries; subtraction and Duration.TotalDays measure elapsed time.
See Also
Enhancing Performance For BI Ad-Hoc Queries Effectively
Addressing Performance Challenges In BI Ad-Hoc Queries
The Evolution Of Business Intelligence Through The Decades
Strategies For Effectively Analyzing Large Data Sets
The Role Of AI In Business Intelligence Today
Last updated: 2026-11-25