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

# arrays – How to subtract values in Excel?

Posted by: admin May 14, 2020 Leave a comment

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

### Answer：

# 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:
Desired answer is: 378
Because 2501 minus 2123

For model J2254008:
Desired answer is: 178
Because 1231 minus 1053

… And so on for the remaining 6,000 models

Would a dynamic array be needed?

How to&Answers:

# 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. ### Answer：

If I am understanding you correctly, it looks like you just need to add a sum of the “Odometer Reading Change” column in your pivot table. When I sum them for J2253993 I get 378 like you say.

Pivot table will total all of the rows by model based on the way you have built it, no matter how many rows are there.