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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
willfarkas
New Member

Difference between two rows

Hi folks,

 

I am trying to create a matrix that shows the fuel consumption from different equipments of a fleet, given the difference between the last reffuling and its previous refuelling.

 

The formula would be like: [(today refuelling mileage) - (previous refuelling mileage)] / (quantity of fuel filled today)

 

The issue is how to bring the penultimate refuelling entry, as min and max cannot work as I can have 3 or 4 entries but it only interests the last and the penultimate entries.

 

The database has the following key columns:

 

Equipment IDRefuelling DateQuantity litersRegistered Mileage
Amay-01101000
Bmay-011599999
Cmay-01108888
Aapr-2920900
Bapr-281099988
Capr-27158800
Aapr-2010850
Bapr-202099777
Capr-20108700

 

So, the fuel consumption for equipment "A" between refuelling on may 01 and april 29 was:

 

Fuel consumption (mileage/liter): (1000) - (900) / (10) = 10 mi/liter

 

Any suggestions on how can I get this on PowerBI, please?

 

 

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @willfarkas,

 

In this scenario, please first create a Rank column:

Rank =
RANKX (
    FILTER (
        'Difference between two rows',
        'Difference between two rows'[Equipment ID]
            = EARLIER ( 'Difference between two rows'[Equipment ID] )
    ),
    'Difference between two rows'[Refuelling Date],
    ,
    ASC,
    DENSE
)

Then, use this rank column to calculate 'Fuel consumption':

Fuel consumption =
 (
    'Difference between two rows'[Registered Mileage]
        - LOOKUPVALUE (
            'Difference between two rows'[Registered Mileage],
            'Difference between two rows'[Equipment ID], 'Difference between two rows'[Equipment ID],
            'Difference between two rows'[Rank], 'Difference between two rows'[Rank] - 1
        )
)
    / 'Difference between two rows'[Quantity liters]

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @willfarkas,

 

In this scenario, please first create a Rank column:

Rank =
RANKX (
    FILTER (
        'Difference between two rows',
        'Difference between two rows'[Equipment ID]
            = EARLIER ( 'Difference between two rows'[Equipment ID] )
    ),
    'Difference between two rows'[Refuelling Date],
    ,
    ASC,
    DENSE
)

Then, use this rank column to calculate 'Fuel consumption':

Fuel consumption =
 (
    'Difference between two rows'[Registered Mileage]
        - LOOKUPVALUE (
            'Difference between two rows'[Registered Mileage],
            'Difference between two rows'[Equipment ID], 'Difference between two rows'[Equipment ID],
            'Difference between two rows'[Rank], 'Difference between two rows'[Rank] - 1
        )
)
    / 'Difference between two rows'[Quantity liters]

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.