Find MAX Value that Recognizes Date Filter

I’m working with data from an email log that notifies a customer each week of the status of items that are on backorder. I’m trying to create a measure that shows the MAX time a customer has waited for the product based on an applied date filter.

The log includes a numeric field for “DaysOnBackorder”, so the DAX I’ve written looks like this:

MAX Days Pending =
VAR CurrentItem = SELECTEDVALUE(BackorderLines[Item Nbr])
RETURN
CALCULATE(
MAXX(
FILTER(ALL(BackorderLines), BackorderLines[Item Nbr] = CurrentItem),
BackorderLines[DaysOnBackorder]),
USERELATIONSHIP(BackorderLines[DateSent],Dates[Date]))

This returns the correct value if there isn’t a date range selected as a filter. However, when I apply a filter to the page, the data is still returning the MAX value for dates not in the filter. How do I modify the DAX to recognize the filter?
MAX Backorder Last 7 Days.pbix (180.4 KB)

@npeterson

MAX Days Pending = 
    CALCULATE ( 
        MAX ( BackorderLines[DaysOnBackorder] ),
        REMOVEFILTERS ( BackorderLines ),
        SUMMARIZE ( BackorderLines, BackorderLines[Item Nbr], BackorderLines[DateSent] ),
        USERELATIONSHIP ( BackorderLines[DateSent], Dates[Date] )
    )
1 Like

Hello @npeterson

Did the responses above help solve your query?

If not, can you let us know where you’re stuck and what additional assistance you need?

If it did, please mark the answer as the SOLUTION by clicking the three dots beside Reply and then tick the check box beside SOLUTION

Thank you

Thanks @AntrikshSharma. This is what I was looking for.