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
RVLee
Frequent Visitor

Dynamic previous year's date

Hi,

 

I would like to calculate previous year's value, but I only get the correct number if I don't apply any slicer or filter.

The result I need is in the Total LY or in Total LY exact date column in below table

YearTotal CYTotal LYTotal LY exact date
2017121  
2018219121121
2019179219208
Total (shown when the measure is displayed as single value such as in KPI Card) 179219208

 

The scenario is that 2019 is still the current year of the data, thus the latest transaction date is not 31 Dec 2019, but before, let's say 27 Aug 2019.

Total LY shows the measurement at the end of the year, which is 31 Dec 2018 and 31 Dec 2017.

Total LY exact date shows the measurement at the same date of the each previous year, which is 27 Aug 2018 and 27 Aug 2017.

I managed to show the Total LY and Total LY exact date, if I use a single value visual, such as KPI card. And when I apply filter/slicer of a certain date, even though 2019, it showed blank value. There must be something I missed in the formula. Hope that I can get help on what is missed out and the correct formula.

 

To get the picture of what happened, here's the formula I used to get Total LY. The formula for Total LY exact date is similar, just a slight change on the filter date used. Appreciate if there's any input on this formula also

 

SUMX (
VALUES ( 'Contract'[Location] ),
VAR _maxDate =
CALCULATE (
MAXX ( 'Production', 'Production'[Production Date] ),
DATESYTD ( SAMEPERIODLASTYEAR ( 'Calendar Date'[Date] ) )
)
VAR _ProductionatLastYearDate =
CALCULATE (
SUM ( 'Contract'[Amount] ),
'Contract'[Date]
= _maxDate
)

RETURN
_ProductionatLastYearDate
)
2 REPLIES 2
amitchandak
Super User
Super User

@RVLee , Not sure why you are using  max date

Try like

CALCULATE (
lastnonblankvalue ( 'Production'[Production Date],SUM ( 'Contract'[Amount] ) ),
DATESYTD ( SAMEPERIODLASTYEAR ( 'Calendar Date'[Date] ) )
)

 

Can explain with example what is wrong

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak 

 

I used max date to get the latest transaction date from Production table, and sometimes the latest transaction date of production in each location is different.

While the amount to sum is in the Contract table, which contains the transaction of contracts of all periods, even future dates.

Both dates have a one-to-many relationship to Calendar table.

 

Tried your suggestion, however it returns incorrect number. Any other suggestion?

 

Regards,

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.