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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Lenastray
Helper I
Helper I

Help previous sum

Hello. For calculating the cumulative total I make use of the following dax pattern:

 

CALCULATE (
        SUM ( Table[numericValue] ),
        ALLEXCEPT ( Table, Table[Dates], Table[Attribute1], Table[Attribute2] ),
        Table[Dates] < EARLIER ( Table[Dates] )
    )

Calculate makes a context transition between the row context to an equivalent filter context, where in combination with allexcept, behave similar to partition over (Attribute1, Atributte2 order by Date) from SQL. Now, instead of retrieving the cumulative total, I need the get the sum only for the previous date for each date. It would be something like the maximum date that is smaller than the current date, but I´m having some difficulties mixing the max(Table[date]) and the earlier(Table[date]) and not loosing the context transition that makes the partition possible.

 

Thanks

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

@Lenastray

Something like this should work. All I've done is change the first argument of the CALCULATE function to a further CALCULATE, with Table[Dates] filtered to the latest date subject to the filters of the outer CALCULATE. Also removed Dates from ALLEXCEPT.

 

=
CALCULATE ( CALCULATE ( SUM ( Table[numericValue] ), LASTDATE ( Table[Dates] ) ), ALLEXCEPT ( Table, Table[Attribute1], Table[Attribute2] ), Table[Dates] < EARLIER ( Table[Dates] ) )

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

@Lenastray

Something like this should work. All I've done is change the first argument of the CALCULATE function to a further CALCULATE, with Table[Dates] filtered to the latest date subject to the filters of the outer CALCULATE. Also removed Dates from ALLEXCEPT.

 

=
CALCULATE ( CALCULATE ( SUM ( Table[numericValue] ), LASTDATE ( Table[Dates] ) ), ALLEXCEPT ( Table, Table[Attribute1], Table[Attribute2] ), Table[Dates] < EARLIER ( Table[Dates] ) )

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

It works like a charm. The innermost calculate is the last one in excecute, so it filter the lastdate there. Excelent, thank you so much Owen.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors