How to Compare Two Years in Power BI

Cody Schneider7 min read

Comparing performance between two different years is one of the most fundamental tasks in data analysis. Whether you're tracking sales, website traffic, or operational costs, a year-over-year (YoY) comparison quickly reveals growth, seasonality, and long-term trends. This guide will walk you through several straightforward methods for comparing two years of data in Power BI, from using powerful DAX functions to simple visual setups.

First Things First: You Need a Proper Date Table

Before you can perform any meaningful time-based analysis in Power BI, you need a solid foundation: a dedicated date table. While you can sometimes get away with using the default date hierarchies, a custom date table gives you complete control and is essential for advanced DAX functions to work correctly.

A date table is just a table containing a continuous list of dates, along with useful columns like year, quarter, month, and day of the week. The most important rule is that your date column must contain an unbroken sequence of dates, from your earliest record to your latest, with no gaps.

How to Create a Basic Date Table with DAX

You can create a new date table directly in Power BI using a simple DAX formula.

  1. Navigate to the Data view on the left side of the Power BI window.
  2. In the Home tab of the ribbon, click New Table.
  3. Enter the following DAX formula into the formula bar:

The CALENDARAUTO() function automatically scans your entire data model for the earliest and latest dates and creates a continuous calendar between them. The ADDCOLUMNS() function then adds extra contextual columns like "Year" and "Month Name" that are invaluable for your reports.

Mark as Date Table and Create a Relationship

Once your table is created, you need to tell Power BI that it's your official calendar.

  • With your new "Date Table" selected, go to the Table tools tab at the top and click Mark as date table.
  • In the dialog that appears, select the "[Date]" column.

Finally, navigate to the Model view. Find your new "Date Table" and your main data (or "fact") table, like a "Sales" or "Orders" table. Drag the "[Date]" column from your "Date Table" to the corresponding date column in your fact table (e.g., "OrderDate") to create a one-to-many relationship. Your model is now set up for powerful time intelligence calculations.

Method 1: Using DAX Time Intelligence Functions (The Best Practice)

The most robust and flexible way to compare years is by writing Data Analysis Expressions (DAX) measures. This method allows you to display values for different years side-by-side in the same visual, which is perfect for direct comparisons.

Step 1: Create a Base Measure

First, you need a measure that calculates the value for the current period. Avoid using raw table columns in your visualizations, creating explicit measures is always the best practice. For example, if you want to compare revenue:

  1. Right-click on your fact table (e.g., "Sales") and select New Measure.
  2. Enter the formula:

This simple measure sums up all the values in the "Revenue" column of your "Sales" table.

Step 2: Create the Previous Year Measure

Now, let's create the measure that calculates the revenue for the same period in the previous year. This is where the magic of time intelligence functions comes in.

Revenue PY = 
CALCULATE(
    [Total Revenue],
    SAMEPERIODLASTYEAR('Date Table'[Date])
)

Breaking Down the Formula:

  • CALCULATE: This is the most powerful function in DAX. It changes the context in which a calculation is performed. Here, we're asking it to calculate [Total Revenue] but with a modified date context.
  • SAMEPERIODLASTYEAR: This function takes a column of dates and returns a table containing a single column of dates shifted one year back in time from the dates in the current context. So, if your chart is looking at data for July 2024, this function tells CALCULATE to evaluate the revenue for July 2023.

Step 3: Visualize the Comparison

With both measures created, you can now easily add them to a visual.

  • Matrix Visual: This is perfect for a side-by-side comparison.
  • Line Chart Visual: Ideal for showing trends over time.

Method 2: Using Slicers and a Matrix for a Simple Side-by-Side View

If you prefer a simpler approach without writing complex DAX, you can configure your visuals to create a natural year-over-year view. The matrix visual is perfect for this.

This method works best when you want a broad overview comparing all years present in your data.

  1. Drag a Matrix visual onto your report canvas.
  2. From your "Sales" table, drag your primary measure field (e.g., [Total Revenue]) into the Values box.
  3. From your "Date Table," drag the Year field into the Columns box.
  4. From your "Date Table," drag the Month Name field into the Rows box.

Instantly, you'll have a pivot-table-style view with each year as a separate column, allowing for easy scanning across rows (months) to compare year performance. To narrow down to specific years:

  • With the Matrix selected, find the Filters pane.
  • Drag the Year field into "Filters on this visual."
  • Use the "Basic filtering" to check the boxes for the specific years you want to compare (e.g., 2023 and 2024).

Method 3: The User-Friendly Relative Date Slicer

Sometimes you want to give the report viewer the ability to make their own comparisons. The relative date slicer is perfect for this, allowing users to quickly see the "last 2 years" of data without you writing any DAX.

  1. Add a Slicer visual to your canvas.
  2. Drag the "[Date]" column from your Date Table into the Field well.
  3. In the top-right corner of the slicer, click the dropdown arrow and select Relative Date.
  4. You can now configure the slicer. For a two-year comparison, set the options to:

Now, any visual on the page connected to this slicer (like a column chart showing revenue by month) will automatically be filtered to display data for the last two complete calendar years. While this approach is very intuitive for end-users, it is less suited for creating calculated columns like "YoY Growth %."

Going Further: Calculating YoY Growth Percentage

Identifying the raw numbers for this year and last year is great, but the most powerful insight often comes from calculating the percentage change. Because you already created [Total Revenue] and [Revenue PY] measures, this step is simple.

  1. Create a new measure with the following formula:

Why use DIVIDE?

We use the DIVIDE function instead of the forward slash (/) operator as a best practice. It automatically handles division-by-zero errors. If [Revenue PY] has no value (like for your first year of data), DIVIDE will return a blank instead of an error that could break your entire visual.

Once you've created the measure, go to the Measure tools ribbon and change its formatting to Percentage. You can now add this YoY Revenue Growth % to your matrix tables or as a tooltip in your charts to provide rich, direct context on performance changes.

Final Thoughts

You’ve now learned several powerful techniques for comparing data across two years in Power BI, from setting up a proper data model with a date table to using DAX time intelligence functions like SAMEPERIODLASTYEAR, and configuring visuals for direct comparisons. Mastering these methods will elevate your reports from simple data displays to powerful analytical tools that reveal meaningful trends.

While Power BI offers deep customization, the initial setup - data modeling, connecting sources, and learning DAX - can take up significant time. At Graphed, we want to help you get straight to the insights. By securely connecting your data sources, you can get answers and build real-time dashboards just by asking questions in plain English. For example, simply ask, "compare revenue by month for this year versus last year," and Graphed will instantly create an interactive, embeddable dashboard for you - no DAX measures or manual chart building required.

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.