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! Request now

Reply
Jason_1981
Helper I
Helper I

How to get miles between with multiple filters?

Hello, 

 

Been trying at this for a week now and keep getting wrong results or else a calculation that results in a time-out memory allocation issue. 

 

What I have is data on tire changes. The key fields are [Unit], [Asy Cd], [Position], [Date Out], & [Odo]. What I want to do is for each tire change event, go back and find the last date the same unit had a hit for same Asy Cd & Position, then calculate the difference between the previous miles [Odo] to the current row miles. 

 

Link to Google sheet sample data:

 

https://docs.google.com/spreadsheets/d/1q8-cR0tmfaBkiiWGpN7Um3vGay0r1J1A/edit?usp=sharing&ouid=11116...

 

Thank You 

3 REPLIES 3
johnt75
Super User
Super User

You could add a calculated column like

Miles difference =
VAR CurrentMiles = 'Table'[Odo]
VAR CurrentDate = 'Table'[Date out]
VAR PrevMiles =
    SELECTCOLUMNS (
        CALCULATETABLE (
            TOPN ( 1, 'Table', 'Table'[Date out] ),
            ALLEXCEPT ( 'Table', 'Table'[Unit], 'Table'[Asy Cd], 'Table'[Position] ),
            'Table'[Date out] < CurrentDate
        ),
        "@val", 'Table'[Odo]
    )
RETURN
    CurrentMiles - PrevMiles

@johnt75  Thanks for the response. When I enter this I get the error message "A table of multiple values was supplied where a single value was expected."

 

Jason_1981_0-1666808785423.png

 

There must be multiple entries for the same unit on the same day. If the table has a unique column then you could add that to the TOPN as an additional sort after the date. If you don't have one, you could sort by date in Power Query and then add an index column and use that.

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.