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.
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]))
---
Solved! Go to 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.
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.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
99 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
110 | |
91 | |
84 | |
66 |