Forum Discussion
Calculate reference year for all year per month
- 8 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") )
- 8 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.
The problem is the filter on yearmonth when yearmonth is included in the visual
you need to remove that filter in the SalesRef measure
Include an additional
REMOVEFILTERS ( Calendar[YearMonthNr] )
If you show your actual DAX code I can be more precise
If this helped, please consider giving kudos and mark as a solution
me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
Hi FBergamaschi
The following is used:
- amitchandak8 months ago
Super User
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") )
- FBergamaschi8 months ago
Super User
Use this DAXCALCULATE([Sales],'Date'[Year] = 2021,ALL('Date'),USERELATIONSHIP('Date'[Date], 'Sales'[ClosingDate]))If this helped, please consider giving kudos and mark as a solution
me in replies or I'll lose your threadWant to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI