Home » excel » arrays – How to subtract values in Excel?

# arrays – How to subtract values in Excel?

Questions: Referring to the snippet of a pivot table below in the image, there are 6,000 J

# models (i.e. J2253993, J2254008, J2254014 … etc).

How can the difference between the last Odometer reading and the first Odometer reading for each model be calculated? There is no consistency in the number of recorded months for each model and there is no consistency between the first and last timestamps for each model.

i.e.
For model J2253993:
Because 2501 minus 2123

For model J2254008:
Because 1231 minus 1053

… And so on for the remaining 6,000 models

Would a dynamic array be needed?

# Messy SUM/INDIRECT Solution

EDIT: A similar formula for Max-Min in column B (my first idea):

``````=INDEX(INDIRECT("B"&MATCH(E4,A\$1:A\$50000,0)+1&":B50000"),MATCH("",INDIRECT("B"&MATCH(E4,A\$1:A\$50000,0)+1&":B50000"),0)-1)-INDEX(B\$1:B\$50000,MATCH(E4,A\$1:A\$50000,0)+1)
``````

I abandoned it because the image wasn’t showing any empty cells.

EDIT-END

The formula is calculating the `C` column sums. A drawback is that you have to insert `=""` in all the empty cells of column `C` unless you know a way how the `MATCH` function returns an empty cell. In the `E` column write the ID-s starting from the 4th row and in `F4` write the formula:

``````=SUM(INDIRECT("C"&MATCH(E4,A\$1:A\$50000,0)+2&":C"&MATCH("",INDIRECT("C"&MATCH(E4,A\$1:A\$50000,0)+2&":C44"),0)-1+MATCH(E4,A\$1:A\$50000,0)+2))
``````

Copy/Paste down. 