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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DeepDive
Helper IV
Helper IV

Error in MTD LY , QTD LY, YTD LY

Hi All,

While using below DAX, I am getting error in Last year calculation for all(like MTD LY, QTD LY and YTD LY).
However Current year (ie. MTD, QTD, YTD) calculations are working fine. When I used Datesbetween for calculating
last year data it gives me correct answer. Pls suggest how to use MTD LY, QTD LY and YTD LY here in this scenario

TotalSales = SUM(Sheet1[Net Sales Value])

TotalSales LY = CALCULATE([TotalSales],DATEADD('Date'[Date],-1,YEAR))

MTD = CALCULATE([TotalSales], DATESMTD('Date'[Date]))

MTD LY = CALCULATE('Date_MeasureTable'[TotalSales LY], DATESMTD('Date'[Date]))

QTD = CALCULATE(Date_MeasureTable[TotalSales], DATESQTD('Date'[Date]))

QTD LY = CALCULATE(Date_MeasureTable[TotalSales LY], DATESQTD('Date'[Date]))

YTD = CALCULATE(Date_MeasureTable[TotalSales], DATESYTD('Date'[Date]))

YTD LY = CALCULATE(Date_MeasureTable[TotalSales LY], DATESYTD('Date'[Date]))


---
LY_.png

1 ACCEPTED SOLUTION

Try changing your calendar code to

VAR StartDate = MIN ( Sheet1[Invoice_Date] )
VAR EndDate = MAX ( Sheet1[Invoice_Date] )
RETURN
CALENDAR ( DATE ( YEAR ( StartDate ) , 1 , 1 ), DATE ( YEAR ( EndDate ) , 12 , 31 ) )

This will extend your date table to include the full years.

View solution in original post

4 REPLIES 4
jdbuchanan71
Super User
Super User

@DeepDive 

Make sure your date table contains full years from Jan 1st - Dec 31st.  I have seen odd behavior if your date table starts on say July 1st.

@jdbuchanan71 am using Calendar(min(Sheet1[Invoice_Date]), max(Sheet[Invoice_Date)).. which creates date calendar for Data captured period only. ( i have data form Jan 2017 to July 2017).... Min date in Calendar is 2-Jan-2017 and Max date till 30th -July-2019.

Try changing your calendar code to

VAR StartDate = MIN ( Sheet1[Invoice_Date] )
VAR EndDate = MAX ( Sheet1[Invoice_Date] )
RETURN
CALENDAR ( DATE ( YEAR ( StartDate ) , 1 , 1 ), DATE ( YEAR ( EndDate ) , 12 , 31 ) )

This will extend your date table to include the full years.

Anonymous
Not applicable

what @jdbuchanan71  and also be sure to set your date table as such:

How to Mark as Date Table.png

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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