Explanation

Note: this example assumes that fuel is added to capacity at each gas stop, in order to calculate miles per gallon (MPG) based on the miles driven and fuel used since the last stop. In addition, this example keeps all data in an Excel Table called “data” to illustrate how Tables can make some formulas easier to maintain.

The formula in E5 subtracts the mileage in the row above from mileage in the current row to calculate distance (miles driven) since the last gas stop:

[@Mileage]-SUM(C4)

The SUM formula is used only to prevent errors on the first row, where the row above contains a text value. Without SUM, the first row formula will return the #VALUE error . The SUM function however will treat the text in C4 as zero and prevent the error.

The formula in F5 calculates MPG (miles per gallon) by dividing miles driven by gallons used:

=[@Distance]/[@Gallons]

The result is formatted as a number with one decimal place.

Summary stats

The formulas in I4:I6 calculate best, worst, and average MPG like this:

=MAX(data[MPG]) // best
=MIN(data[MPG]) // worst
=SUM(data[Distance])/SUM(data[Gallons]) // average

Because we are using an Excel Table to hold the data, these formulas will continue to show correct results as more data is added to the table.

Explanation

In this example, the XOR function contains two expressions, one to test for an “x” in column C, and one to test for an “x” in column D.

C5="x" // TRUE if coffee is "x"
D5="x" // TRUE if tea is "x"

With two logical criteria, XOR has a particular behavior, summarized in the table below:

CoffeeTeaResult
TRUEFALSETRUE
FALSETRUETRUE
TRUETRUEFALSE
FALSEFALSEFALSE

At each row in column E, XOR evaluates values in columns C and D and returns a TRUE or FALSE result. This behavior is sometimes referred to as “exclusive OR”, meaning only one result can be true.

Note: with more than two criteria, XOR behavior changes, as explained on the XOR function page .