Forum Discussion
Calculate reference year for all year per month
Hello masters,
I have a question, I would like to calculate the percentage (Sales %) = DIVIDE( ( Sales Ref - Sales), Sales Ref, 0)
Where the values for Sales Ref should be deduplicated for all YearMonths.
At the moment we use 2021 as Sales Ref, but I cannot somehow get the numbers across 2022 and 2023, I will always get 0% because the Sales Ref is Blank.
For year level it works fine:
But on YearMonth does not:
Any suggestions?!
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") )
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.
9 Replies
- HarishKM
Super User
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.
- FBergamaschi
Super User
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
- Hichamas4Frequent Visitor
Hi FBergamaschi
The following is used:CALCULATE([Sales],'Date'[Year] = 2021,ALL('Date'[Year]),USERELATIONSHIP('Date'[Date], 'Sales'[ClosingDate]))- amitchandak
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") )
- Ashish_Mathur
Super User
Hi,
The second image is very small so i cannot understand anything. Share some data to work with.
- v-karpurapud
Community Support
Hi Hichamas4
Thank you for posting your query in the Microsoft Fabric Community Forum, and thanks to @FBergamaschi , amitchandak and HarishKM for sharing valuable insights.
Could you please confirm if your query has been resolved by the provided solution?If you have any more questions, please let us know and we’ll be happy to help.
Regards,
Microsoft Fabric Community Support Team
- v-karpurapud
Community Support
Hi Hichamas4
We have not received a response from you regarding the query and were following up to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.
Thank You.
- Hichamas4Frequent Visitor
All solutions are usefull :). Thank you all for the great support.