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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
FletchNZ
Frequent Visitor

DAX Help - Prior year rolling total

Hey all,

I'm stuck trying to get a prior year 12 month rolling total dax Query working.

 

So first I have a 12 month rolling total which works great

12M Total Service Request:= 

CALCULATE (
    [Total Service Request],
    DATESBETWEEN (
        'Date'[Date],
   NEXTDAY (   SAMEPERIODLASTYEAR (  LASTDATE ( 'Date'[Date] ) ) ),
        LASTDATE ( 'Date'[Date] )
    
)
)

and for the Prior year I use the below, however for the very first date for this formula it returns the total for everything because the "samePeriodLastYear" is referencing a date that doesnt exist. I've tried a vew things but i've found nothing that works. 

 

Prior 12M Total Service Request:=  Calculate('Service Request'[12M Rolling Total Service Request], SAMEPERIODLASTYEAR('Date'[Date]))

Anyone have any recomendations on how to resolve this?

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @FletchNZ,

 

I think it may related to filter conflict between different time intelligence functions.

Time Intelligence in Power BI Desktop

Optimizing DAX expressions involving multiple measures

 

If this is a case, I'd like to suggest you manually point out date range which dax formula calculate instead to nested multiple measures with specific filters.

 

Sample:

12M Total Service Request :=
VAR currDate =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        [Total Service Request],
        FILTER (
            ALLSELECTED ( 'Date' ),
            [Date]
                >= DATE ( YEAR ( currDate )-1, MONTH ( currDate ), DAY ( currDate ) )
                && [Date] <= currDate
        )
    )

Prev 12M Total Service Request :=
VAR currDate =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        [Total Service Request],
        FILTER (
            ALLSELECTED ( 'Date' ),
            [Date]
                >= DATE ( YEAR ( currDate ) - 2, MONTH ( currDate ), DAY ( currDate ) )
                && [Date]
                    <= DATE ( YEAR ( currDate ) - 1, MONTH ( currDate ), DAY ( currDate ) )
        )
    )

 

Regards,

Xiaoxin Sheng

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

HI @FletchNZ,

 

I think it may related to filter conflict between different time intelligence functions.

Time Intelligence in Power BI Desktop

Optimizing DAX expressions involving multiple measures

 

If this is a case, I'd like to suggest you manually point out date range which dax formula calculate instead to nested multiple measures with specific filters.

 

Sample:

12M Total Service Request :=
VAR currDate =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        [Total Service Request],
        FILTER (
            ALLSELECTED ( 'Date' ),
            [Date]
                >= DATE ( YEAR ( currDate )-1, MONTH ( currDate ), DAY ( currDate ) )
                && [Date] <= currDate
        )
    )

Prev 12M Total Service Request :=
VAR currDate =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        [Total Service Request],
        FILTER (
            ALLSELECTED ( 'Date' ),
            [Date]
                >= DATE ( YEAR ( currDate ) - 2, MONTH ( currDate ), DAY ( currDate ) )
                && [Date]
                    <= DATE ( YEAR ( currDate ) - 1, MONTH ( currDate ), DAY ( currDate ) )
        )
    )

 

Regards,

Xiaoxin Sheng

 

Thanks for that it worked a charm!

 

I end up having to move from a Dax generated date table to a M date generated table and that along with your formulas it all worked perfect. No idea why I was getting weird results from the www.SQLbi.com Dax date code.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.