Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I've been tryign to limit my use of time intelligence functions and also calculate as I find they are generally better way of coding for various reasons.
One of the things I have found is that using offsets to do something like return sales for Last Year with the Financial Year Offset as - 1, is incompatible with a month granularity.
For example, we have the following measure.
Revenue LY NO CALCULATE FYear Offset =
VAR __sel_offset =
SELECTEDVALUE(Dates[FYearOffset])
VAR __sel_prev_offset =
__sel_offset -1
VAR __vTablePrev =
FILTER(
ALL(Dates),
Dates[FYearOffset] = __sel_prev_offset
)
VAR __LY_Sales =
SUMX(
__vTablePrev,
[Revenue]
)
RETURN
__LY_Sales
This works in a table with financial years but if I change the granularity of the table to month & year, the whole financial year amount is returned (example attached).
Because of this issue, I still find myself using DATEADD for LY calculations:
Revenue LY DATEADD =
VAR __LY =
CALCULATE(
[Revenue],
DATEADD(Dates[Date],-1,YEAR)
)
RETURN
__LY
As it appears to be the most flexible and easy to use. However I realise the drawback in using TI functions as they are "black box" features that don't really let you see what is going on inside of them.
Does anyone know a way to solve for this while retaining the use of offsets?
I have worked out a way to do it using ISINSCOPE to see if we are on the month or year level in the table, but this method is quite verbose and appears unessesarily complex.
Solved! Go to Solution.
Hello @timosborn ,
Not sure about exact requirement but if you want your calculation to work for different hierarchy without calculate and TL, try using below dax :
Revenue LY NO CALCULATE FYear Offset =
VAR __sel_offset = SELECTEDVALUE(Dates[FYearOffset])
VAR __sel_prev_offset = __sel_offset - 1
// virtual table for the previous period
VAR __vTablePrev =
FILTER(
ALL(Dates),
Dates[FYearOffset] = __sel_prev_offset
)
// Apply the selected date context dynamically with TREATAS for various hierarchies
VAR __LY_Sales =
SUMX(
TREATAS(__vTablePrev, Dates[Year], Dates[Month], Dates[Day]), // Modify this as per your requirement
[Revenue]
)
RETURN
__LY_Sales
Modify this as per your need.
Did I solve your query ? Mark this as solution , appreciate Kudos always.
Cheers
Hello @timosborn ,
Not sure about exact requirement but if you want your calculation to work for different hierarchy without calculate and TL, try using below dax :
Revenue LY NO CALCULATE FYear Offset =
VAR __sel_offset = SELECTEDVALUE(Dates[FYearOffset])
VAR __sel_prev_offset = __sel_offset - 1
// virtual table for the previous period
VAR __vTablePrev =
FILTER(
ALL(Dates),
Dates[FYearOffset] = __sel_prev_offset
)
// Apply the selected date context dynamically with TREATAS for various hierarchies
VAR __LY_Sales =
SUMX(
TREATAS(__vTablePrev, Dates[Year], Dates[Month], Dates[Day]), // Modify this as per your requirement
[Revenue]
)
RETURN
__LY_Sales
Modify this as per your need.
Did I solve your query ? Mark this as solution , appreciate Kudos always.
Cheers
thanks divyed that worked, now all I need to do is fix the table totals. It wouldn't be PBI without an incorrect table total 😂
My end code:
VAR __sel_offset =
SELECTEDVALUE(Dates[FYearOffset])
VAR __sel_prev_offset =
__sel_offset -1
VAR __vTablePrev =
FILTER(
ALL(Dates[FYear],Dates[FYearOffset],Dates[Month], Dates[Period]),
Dates[FYearOffset] = __sel_prev_offset
)
VAR __LY_Sales =
SUMX(
TREATAS(
__vTablePrev,Dates[fyear],Dates[FYearOffset],Dates[Month],Dates[period]
),
[Revenue]
)
RETURN
__LY_Sales
Hi @timosborn
Do you have a seperate Month column, if so you could apply that as a secondary filter.
Var _vMonth = SelectedValue(Dates[Month])
VAR __vTablePrev =
FILTER(
ALL(Dates),
Dates[FYearOffset] = __sel_prev_offset && Dates[Month] =_vMonth
)
If you are happy with this answer please mark as a solution for others to find !
Kudos are always appreciated! Check out our free Power BI video courses.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
68 | |
68 | |
40 | |
29 | |
26 |
User | Count |
---|---|
88 | |
49 | |
45 | |
38 | |
37 |