How to Compare Two Dates in Power BI

Cody Schneider8 min read

Calculating the time between two events is a fundamental part of business analysis. Whether you're tracking how long it takes to ship an order, measuring the duration of a marketing campaign, or analyzing customer support ticket resolution times, comparing dates is a constant necessity. This guide will walk you through exactly how to compare two dates in Power BI using DAX, covering the most common and practical methods.

Why Compare Dates in Power BI?

Before jumping into the formulas, it’s helpful to understand the kinds of questions date comparisons can answer. Performing these calculations in Power BI allows you to create dynamic, interactive visuals to track key performance indicators (KPIs) such as:

  • Lead Time: The duration between when an order is placed and when it's shipped or delivered. This helps in understanding operational efficiency.
  • Sales Cycle Duration: The time it takes for a sales lead to convert into a customer, from the first contact date to the close date.
  • Employee Tenure: The length of time an employee has been with the company, calculated from their hire date.
  • Project Duration: The time elapsed between a project's start and end dates, crucial for resource planning.
  • Time to Resolution: In customer service, the time it takes to resolve a support ticket from the moment it's opened.

You can accomplish all of these and more using Power BI's data modeling language, DAX (Data Analysis Expressions).

The Key Function for Date Comparisons: DATEDIFF

The primary tool for finding the difference between two dates in Power BI is the DATEDIFF function. If you’re familiar with Excel formulas, the concept of a function with specific inputs (or "arguments") will feel very similar. Its structure is simple and easy to remember.

The syntax for the function is:

DATEDIFF(<start_date>, <end_date>, <interval>)

Breaking Down the DATEDIFF Arguments:

  • <start_date>: The first date in your calculation. This is typically a column in your data, like 'OrderDate' or 'TicketCreatedDate'.
  • <end_date>: The second date. This would be a column like 'ShipDate' or 'TicketClosedDate'.
  • <interval>: This tells Power BI what unit of time you want the result in. You have several options to choose from.

Available Intervals for DATEDIFF:

  • SECOND: Total seconds between the two dates.
  • MINUTE: Total minutes between the two dates.
  • HOUR: Total hours between the two dates.
  • DAY: Total days between the two dates.
  • WEEK: Total weeks between the two dates.
  • MONTH: Total months between the two dates.
  • QUARTER: Total quarters between the two dates.
  • YEAR: Total years between the two dates.

Now, let's explore the two primary ways to implement this function: as a calculated column or as a measure.

Method 1: Creating a Calculated Column for Row-Level Analysis

A calculated column is the most straightforward method. It adds a new column to your existing data table where each row contains the calculated difference between the two dates in that specific row. This is best when you need a static, predefined value for every single entry in your dataset.

Let's use a common e-commerce scenario: calculating the number of days it takes to ship an order after it has been placed. Assume we have a 'Sales' table with an 'OrderDate' column and a 'ShipDate' column.

Step-by-Step Guide to Creating the Calculated Column:

1. Go to the Data View

In Power BI Desktop, look at the left-hand panel and click on the 'Data' icon (it looks like a small table) to view your underlying data tables.

2. Select Your Table

In the 'Fields' pane on the right, click on the table that contains your dates. In our example, we'll select the 'Sales' table.

3. Create a New Column

At the top of the window, you'll see a 'Table tools' tab. Click on 'New column'. This will open up the formula bar where you can enter your DAX expression.

4. Write the DATEDIFF Formula

In the formula bar, type the following DAX formula. Power BI will suggest column names as you type, making it easier to avoid typos.

Days to Ship = DATEDIFF('Sales'[OrderDate], 'Sales'[ShipDate], DAY)

Let's break that down:

  • Days to Ship is the name we're giving our new column.
  • DATEDIFF(...)" is our function.
  • 'Sales'[OrderDate] is the start date.
  • 'Sales'[ShipDate] is the end date.
  • DAY tells the function to return the result in days.

Once you press Enter, Power BI will instantly calculate the difference for every row in your table and populate the new 'Days to Ship' column with the results. You can now use this column in your visuals just like any other field.

More Calculated Column Examples

The pattern is the same for different scenarios:

  • Calculating Employee Tenure in Years (against today's date): Employee Tenure (Years) = DATEDIFF('Employees'[HireDate], TODAY(), YEAR)
  • Calculating Project Duration in Months: Project Duration (Months) = DATEDIFF('Projects'[StartDate], 'Projects'[EndDate], MONTH)

Method 2: Using a Measure for Dynamic Aggregation

What if you don't need to see the difference for every single row, but rather an aggregated value like the average shipping time? This is where measures come in.

A measure is a calculation that runs on-the-fly based on the context of your report. For example, if you create a visual and filter it by a specific product category, the measure will recalculate to show you the average shipping time for only that category. A calculated column, on the other hand, is pre-calculated and static.

To create a measure for average delivery time, we'll need to combine DATEDIFF with an iterator function like AVERAGEX.

Step-by-Step Guide to Creating a Measure:

1. Go to the Report View

Click on the 'Report' icon (top icon in the left-hand panel) to go back to the report canvas.

2. Create a New Measure

Click on the 'Home' tab at the top and then select 'New measure'. This opens the DAX formula bar again.

3. Write the AVERAGEX with DATEDIFF Formula

Enter the following DAX expression:

Average Delivery Days = AVERAGEX( 'Sales', DATEDIFF('Sales'[OrderDate], 'Sales'[ShipDate], DAY) )

Here's what this formula does:

  • AVERAGEX is a function that goes through each row of a table you specify.
  • The first argument, 'Sales', tells it which table to iterate over.
  • The second argument is the expression it should calculate for each row — in this case, our familiar DATEDIFF formula.
  • Finally, AVERAGEX computes the average of all the individual results it calculated.

After creating the measure, you won’t see a new column in your data table. Instead, a new item will appear in your 'Fields' pane with a small calculator icon. You can now drag this 'Average Delivery Days' measure into visuals like a Card, Gauge, or Table to display the aggregated result.

Handling Common Issues and Best Practices

When working with dates, you might run into a few common hurdles. Here’s how to handle them:

Ensure Correct Data Types

For DATEDIFF to work correctly, both columns you are comparing must be in a 'Date' or 'Date/Time' format. To check this, go to the 'Data view', select the column, and look at the 'Data type' in the 'Column tools' tab at the top. If it's set to 'Text' or 'Whole Number', change it to 'Date'.

Handling Blanks Or Missing Dates

What happens if an order has been placed but not yet shipped? The '[ShipDate]' field might be blank. DATEDIFF can throw an error or an inaccurate result in these cases. You can create a more robust formula using an IF statement to handle these situations cleanly.

For a calculated column:

Days to Ship (Clean) = IF( ISBLANK('Sales'[ShipDate]), BLANK(), DATEDIFF('Sales'[OrderDate], 'Sales'[ShipDate], DAY) )

This formula checks if 'Sales'[ShipDate]' is blank. If it is, it returns a blank. If not, it proceeds with the DATEDIFF calculation.

Understanding How DATEDIFF Calculates Intervals

It's important to know that DATEDIFF calculates the difference by counting the number of interval boundaries crossed between the two dates. For example:

DATEDIFF("December 31, 2023", "January 1, 2024", YEAR) will equal 1.

Even though only one day has passed, it has crossed a year boundary (from 2023 to 2024). This is a critical detail, especially when working with quarters, months, and years. When you need a more precise calculation based on the total number of days, always use 'DAY' as your interval and perform division if needed (e.g., divide by 365.25 for a more accurate year count).

Final Thoughts

Comparing two dates in Power BI is a common task made simple with the powerful DATEDIFF function. Whether you're adding hard values to your data with a calculated column for row-by-row analysis or creating dynamic, responsive measures for your reports, this DAX function is the foundation for almost any time-based KPI.

Though DAX unlocks incredible possibilities, we know that there's often a steep learning curve. The process of setting up data sources, cleaning data, and writing correct DAX logic still takes time and technical skill. For many of our users analyzing marketing and sales data, we built Graphed to remove this complexity. It connects directly to platforms like Salesforce, HubSpot, Shopify, and Google Analytics and allows you to create dashboards and reports using simple, natural language. Instead of writing DAX, you can just ask questions like, "What was our average close time for deals last quarter?" and get the answer instantly, letting you focus on insights instead of formulas.

Related Articles

How to Connect Facebook to Google Data Studio: The Complete Guide for 2026

Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.

Appsflyer vs Mixpanel​: Complete 2026 Comparison Guide

The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.