The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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)