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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
krisstok
Frequent Visitor

Previous Year MTD shows me wrong sum

Hi, 

 

I got problem with proper sum of Previous Year up to specific day in current month using time intelligence. 

 

It looks like this:

upto12.PNG

Actual month is up to 12 day, but previous year shows me sum of whole month, not to this day, it should be 92.

 

Current dax formula:

 

Customers Qty MTD PY =
CALCULATE([Customers Qty],
DATESMTD(DATEADD('Calendar'[Date], -1, YEAR))
)

If I filter day 1 to 11 is ok (to 11 day)

 

upto11.PNG

I want to have always day slicer in default from 1 to 31. It works fine in other months.

 

I have a date table marked as date table with date up to max sales date (so 08-12-2022) and its connected to sales fact table by date 

 

datamodel.PNG

I have tried many ways to solve this and none have the desired result, what I'm doing wrong?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@krisstok , seem like GT getting last year full month

 

try like

LMTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = date(Year(_max1), month(_max1)-1, day(_max))
var _min = eomonth(_max1,-2)+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

 

Comments after return are additional options

 

LYMTD QTY forced=
var _max = date(year(today())-1,month(today()),day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

 

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...

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

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@krisstok , seem like GT getting last year full month

 

try like

LMTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = date(Year(_max1), month(_max1)-1, day(_max))
var _min = eomonth(_max1,-2)+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

 

Comments after return are additional options

 

LYMTD QTY forced=
var _max = date(year(today())-1,month(today()),day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

 

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...

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

Wow man! It works! 

 

I adapted first formula and now sum is correct. Many thanks! 😄

done.PNG

 

Customers Qty MTD PY =
VAR _FilteredDate =
IF ( ISFILTERED ( 'Calendar' ), MAX ( 'Calendar'[Date] ), TODAY () )
VAR _max =
DATE ( YEAR ( _FilteredDate ) -1 , MONTH ( _FilteredDate ) , DAY ( _FilteredDate ) )
VAR _min =
EOMONTH ( _max, -1 ) + 1
RETURN
CALCULATE ( [Customers Qty], DATESBETWEEN ( 'Calendar'[Date], _min, _max )
)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.