Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
ERing
Post Partisan
Post Partisan

How to fix DAX measures to provide dates for prior year?

I'm been handed a dashboard which is currently not providing an accurate output and I'm trying to determine where the errors in the DAX are.

 

The report has a slicer where the user selects a date range and budget, actual, and % vs budget data is supposed to be shown for the current period (Range), QTD, & YTD.

 

 

Example.png

I believe I've identified an issue with the DAX below.

 

The Prev Range Spend measure uses variables for Prev_Year_Start and Prev_Year_End. It appears the DAX for Selected_Prev_Year_Start will provide the MIN of the dates in my DIM_CALENDAR[Prev_Year_Start] column. This will be the January 1st of the previous year. Similarly it appears the DAX for Selected_Prev_Year_End will provide the MIN of dates in my DIM_CALENDAR[Prev_Year_End]. This will be December 31st of the previous year.

 

Instead what I want is the DAX for Selected_Prev_Year_Start and Selected_Prev_Year_End to provide the same dates selected in the slicer but for one year prior.

 

How can I Selected_Prev_Year_Start and Selected_Prev_Year_End so that they provide the same dates in the slicer but for one year prior?

 

Prev Range Spend = 
VAR SelectedDate = SELECTEDVALUE('DIM_CALENDAR'[DATE]) 

VAR Prev_year_Start = 
[Selected_Prev_Year_Start]

VAR Prev_year_End = 
[Selected_Prev_Year_End]

RETURN  
CALCULATE(
    SUM(FACT_SPEND[SPEND]), 
    'DIM_CALENDAR'[DATE] >= Prev_year_Start &&
    'DIM_CALENDAR'[DATE] <= Prev_year_End
)

 

Selected_Prev_Year_Start = 
CALCULATE(
    MIN('DIM_CALENDAR'[Prev_Year_Start]), 
    ALLSELECTED('DIM_CALENDAR')
)

 

Selected_Prev_Year_End = 
CALCULATE(
    MIN('DIM_CALENDAR'[Prev_Year_End]), 
    ALLSELECTED('DIM_CALENDAR')
)

 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @ERing 

You can use EDATE to get the date months back. For example

EDATE ( [Selected_Prev_Year_Start], -12 )

 

Or you can use SAMEPERIODLASTYEAR

CALCULATE (
    [your measure],
    SAMEPERIODLASTYEAR ( Dates[Date] ),
    REMOVEFILTERS ( Dates )
)

 

REMOVEFILTERS is necessary is the Dates table hasn't been marked as a dates table.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

5 REPLIES 5
v-saisrao-msft
Community Support
Community Support

Hi @ERing,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

danextian
Super User
Super User

Hi @ERing 

You can use EDATE to get the date months back. For example

EDATE ( [Selected_Prev_Year_Start], -12 )

 

Or you can use SAMEPERIODLASTYEAR

CALCULATE (
    [your measure],
    SAMEPERIODLASTYEAR ( Dates[Date] ),
    REMOVEFILTERS ( Dates )
)

 

REMOVEFILTERS is necessary is the Dates table hasn't been marked as a dates table.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

@danextian 

I don't believe this solves my problem. I need a way to create Selected_Prev_Year_Start so that its the slicer selection minus one year and a way to create Selected_Prev_Year_End so that its the slicer selection minus one year. 

Hi @ERing,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

Hi @ERing,

Thank you for reaching out to the Microsoft Fabric Forum community.

 

I understand your challenge—you need the prior-year dates (Selected_Prev_Year_Start and Selected_Prev_Year_End) to dynamically match the slicer’s selected range but shifted back by one year (e.g., March 10–16, 2025 → March 10–16, 2024). Here’s how to fix it: 

  • Selected_Prev_Year_Start = Slicer’s start date minus 1 year. 
  • Selected_Prev_Year_End = Slicer’s end date minus 1 year. 
  • Use MIN and MAX on your date column to dynamically grab the slicer’s selected range. 
  • Apply a year-shift function (like DATEADD or EDATE) to subtract 1 year from those dates. 
  • Leap Years: Ensure February 29, 2024, correctly maps to February 28, 2023. 
  • Partial Ranges: Confirm dates like December 25–31, 2025, compared to December 25–31, 2024. 

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

 

Thank you. 

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.