Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
timosborn
Frequent Visitor

Using Date Table Offsets Instead of Time Intelligence Functions

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).

 

1730070806982.png

 

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.

1 ACCEPTED SOLUTION
divyed
Super User
Super User

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

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/

View solution in original post

3 REPLIES 3
divyed
Super User
Super User

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

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/

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

 SS-0221.png

SamWiseOwl
Super User
Super User

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.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.