Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hello,
I have 2 measures as follows:
CY Sales =
Var CY = MAX('Date table'[Year])
return CALCULATE(SUM(Transactions[SalesAmnt], 'Date table'[Year] = CY)
and
PY Sales = CALCULATE([CY Sales], SAMEPERIODLASTYEAR('Date table'[Date]))
but my PY returns the total sales for last year and not the sales for the same period as the current year.
What may be causing this?
Thanks,
Vlado
Solved! Go to Solution.
@Newby_TCO_123 Honestly, lots of things. I would recommend avoiding TI functions in DAX. I have some videos coming out in the next few weeks about these and how quirky they can be. This will help. To **bleep** With Time Intelligence - Microsoft Power BI Community. Specifically:
ToHellWithSAMEPERIODLASTYEAR =
VAR __NumIntervals = -1
VAR __MaxDate = MAXX('Calendar',[Date])
VAR __MinDate = MINX('Calendar',[Date])
VAR __Start = __MinDate
VAR __End =
SWITCH(TRUE(),
__NumIntervals = 0 || __NumIntervals > 0,__MaxDate,
IF(
MONTH(__MaxDate) = 2 && DAY(__MaxDate) > 28,
EOMONTH(__MaxDate,__NumIntervals*12),
DATE(YEAR(__MaxDate) + __NumIntervals, MONTH(__MaxDate), DAY(__MaxDate))
)
)
RETURN
FILTER('Calendar', [Date] >= __Start && [Date] <= __End)
@Newby_TCO_123 Honestly, lots of things. I would recommend avoiding TI functions in DAX. I have some videos coming out in the next few weeks about these and how quirky they can be. This will help. To **bleep** With Time Intelligence - Microsoft Power BI Community. Specifically:
ToHellWithSAMEPERIODLASTYEAR =
VAR __NumIntervals = -1
VAR __MaxDate = MAXX('Calendar',[Date])
VAR __MinDate = MINX('Calendar',[Date])
VAR __Start = __MinDate
VAR __End =
SWITCH(TRUE(),
__NumIntervals = 0 || __NumIntervals > 0,__MaxDate,
IF(
MONTH(__MaxDate) = 2 && DAY(__MaxDate) > 28,
EOMONTH(__MaxDate,__NumIntervals*12),
DATE(YEAR(__MaxDate) + __NumIntervals, MONTH(__MaxDate), DAY(__MaxDate))
)
)
RETURN
FILTER('Calendar', [Date] >= __Start && [Date] <= __End)