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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.