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.
Hi Everyone,
I'm trying to set up a measure similar to SAMEPERIODLASTYEAR. I can;t use this formula any longer because the calendar is now customised to 4-4-5. my approach is to filter the calendar table by the "MonthYear" column(using Last year month) , which would give me the correct range of dates , and then used the minimum and maximum dates to calculate my measure. HOwever I am struggling to get an answer.
Act LY =
VAR CurrentDatex = SELECTEDVALUE('Calendar'[Date])
VAR CurrentYear = YEAR(CurrentDatex)
VAR CurrentMonth = MONTH(DATEVALUE(SELECTEDVALUE('Calendar'[MonthYear])))
VAR LastYear = CurrentYear - 1
VAR PreviousYearStartDate =
DATE(LastYear, CurrentMonth, 1)
VAR filteredmindate =
CALCULATETABLE(
'Calendar',
FILTER(
ALL('Calendar'),
'Calendar'[MonthYear] = FORMAT(PreviousYearStartDate, "Mmm-YY")
)
)
Return
CALCULATE(
[Actuals],
FILTER(
ALL('Calendar'),
'Calendar'[Date] >= MINX(filteredmindate, 'Calendar'[Date])
&& 'Calendar'[Date] <= MAXX(filteredmindate, 'Calendar'[Date])
)
)
Any help would be appreciated
Solved! Go to Solution.
Hi Again,
Given the complexity of my calendar table, I have managed to get what I wanted with an actual easy solution
Hi Again,
Given the complexity of my calendar table, I have managed to get what I wanted with an actual easy solution
Hi
Try the below Code,
Act LY =
VAR CurrentDateX = SELECTEDVALUE('Calendar'[Date])
VAR CurrentYear = YEAR(CurrentDateX)
VAR CurrentMonth = MONTH(CurrentDateX)
VAR LastYearStartDate =
DATE(CurrentYear - 1, CurrentMonth, 1)
VAR LastYearMonthYear = FORMAT(LastYearStartDate, "Mmm-YY")
VAR FilteredMinDate =
CALCULATETABLE(
'Calendar',
FILTER(
ALL('Calendar'),
'Calendar'[MonthYear] = LastYearMonthYear
)
)
RETURN
CALCULATE(
[Actuals],
FILTER(
ALL('Calendar'),
'Calendar'[Date] >= MINX(FilteredMinDate, 'Calendar'[Date]) &&
'Calendar'[Date] <= MAXX(FilteredMinDate, 'Calendar'[Date])
)
)
Hi @anilkapkoti,
Thank you for that I tried this before, but unfortunatelythe results are zero
Act LY =
SWITCH(
TRUE(),
ISINSCOPE('Calendar'[MonthYear]),
CALCULATE(
[Actuals],
FILTER(
ALL('Calendar'),
'Calendar'[CurMonthOffset] = MAX('Calendar'[CurMonthOffset]) - 12
)
),
ISINSCOPE('Calendar'[FiscalQuarter]),
CALCULATE(
[Actuals],
FILTER(
ALL('Calendar'),
'Calendar'[CurQuarterOffset] = MAX('Calendar'[CurQuarterOffset]) - 4
)
),
ISINSCOPE('Calendar'[FiscalYear]),
CALCULATE(
[Actuals],
FILTER(
ALL('Calendar'),
'Calendar'[CurFiscalYearOffset] = MAX('Calendar'[CurFiscalYearOffset]) - 1
)
)
)
Thank you though
User | Count |
---|---|
24 | |
10 | |
8 | |
6 | |
5 |
User | Count |
---|---|
31 | |
12 | |
10 | |
10 | |
9 |