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
Anonymous
Not applicable

Optimize MAXX

How can I find the maximum of previous rows with rescpect to the current row? currently I get a memory error when I run this DAX. 

 

maxbi:= MAXX(
FILTER( Allexcept('TI'; 'TI'[Assignment group]; 'TI'[Type]); [date] <= MAX([date])); 'TI'[Stock])

7 REPLIES 7
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this measure

 

maxbi =
VAR md =
    MAX ( 'TI'[Date] )
RETURN
    CALCULATE (
        MAX ( 'TI'[Date] ),
        FILTER (
            ALL ( 'TI' ),
            'TI'[Assignment group]
                = MAX ( 'TI'[Assignment group] )
                && 'TI'[Date] < md
        )
    )

 

 

Regards,

Harsh Nathani

lbendlin
Super User
Super User

Put the max(date) in a variable to compute it only once

 

maxbi:= 
var md = MAX([date])
return MAXX(
    FILTER( Allexcept('TI'; 'TI'[Assignment group]; 'TI'[Type])
           ; [date] <= md )
; 'TI'[Stock])

yes, that filter is still there. But now you only compute the upper limit once, instead of for every row.

Anonymous
Not applicable

Thanks for the input. That did not help. I have over 3 million rows. This formula iterates previous rows to find the maximum value of the measure. Is there another way to formulate?

3M is not a big number, can share your file?
Anonymous
Not applicable

I cannot share the data set as it is confidential. can it be because I refer TI[stock] as a measure?

Anonymous
Not applicable

I mean by that to calculate dates previous to the selected row date.

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.