Forum Discussion
Calculate reference year for all year per month
- 9 months ago
Hichamas4 , I think for sales refer you would still want the month filter while losing the year filter
New Measure =
Calculate( Sum(Sales[Sales refe]), FIlter(All('Date') , 'Date' [Month] = Max( 'Date' [Month] ) && 'Date' [Year] = "2021") )
- 9 months ago
Hichamas4 Hey,
- Your [Sales Ref] is fixed to 2021, but at the YearMonth grain the context includes the current Year (e.g., 2022‑01). Filtering to Year=2021 and 2022‑01 together returns no rows → BLANK.
- Fix: ignore the current Year filter, keep only Month‑of‑Year, and force Year = 2021.
Setup
- Use a proper Date table with columns: Date, Year, MonthNumberOfYear (1–12), YearMonth (YYYY‑MM, sorted by MonthNumberOfYear).
Measures
1) Reference to same month in 2021
Sales Ref (2021 same month) =
VAR m = SELECTEDVALUE('Date'[MonthNumberOfYear])
RETURN
CALCULATE(
[Sales],
FILTER(
ALL('Date'),
'Date'[Year] = 2021 &&
'Date'[MonthNumberOfYear] = m
)
)Alternative (same logic, shorter):
Sales Ref (2021 same month) =
CALCULATE(
[Sales],
ALLEXCEPT('Date', 'Date'[MonthNumberOfYear]),
KEEPFILTERS('Date'[Year] = 2021)
)2) Percentage
Sales % =
VAR Ref = [Sales Ref (2021 same month)]
RETURN IF(NOT ISBLANK(Ref), DIVIDE([Sales] - Ref, Ref), BLANK())Optional: dynamic reference year (What‑If slicer)
Ref Year = SELECTEDVALUE('Ref Year'[Value], 2021)Sales Ref (dynamic) =
VAR ry = [Ref Year]
VAR m = SELECTEDVALUE('Date'[MonthNumberOfYear])
RETURN
CALCULATE(
[Sales],
FILTER(ALL('Date'), 'Date'[Year] = ry && 'Date'[MonthNumberOfYear] = m)
)Notes
- If you want 2021 full‑year repeated across every month, drop the month filter:
CALCULATE([Sales], REMOVEFILTERS('Date'[MonthNumberOfYear]), KEEPFILTERS('Date'[Year] = 2021))- Ensure YearMonth on the visual comes from the Date table.
ThanksHaish K
If I resolve your issue. Kindly give kudos to this post and accept it as a solution so other can refer this.
Hi FBergamaschi
The following is used:
Hichamas4 , I think for sales refer you would still want the month filter while losing the year filter
New Measure =
Calculate( Sum(Sales[Sales refe]), FIlter(All('Date') , 'Date' [Month] = Max( 'Date' [Month] ) && 'Date' [Year] = "2021") )