Subtract one row from another and add up absolute value of differences

I haven't used Numbers very much and need help with a Formula. What I want to do is subtract the value of each cell in a row from the cell in the same column of another row, and add up the absolute values of all the differences. I'm wondering if there is any way to use a range (:) indicator to do this.

Posted on Dec 30, 2013 6:42 PM

Reply
14 replies

Dec 31, 2013 2:18 AM in response to Barry

Thanks, guys. Looking at the documentation, I think you're right - no practical way to do it in one step. This will double the number of rows in my sheet, and there would have been near a thousand without this doubling. I'm calculating genetic distance for Y-chromosome STR haplotypes, which probably means nothing to you unless you're into genealogy.

Dec 31, 2013 5:44 AM in response to preston186

Hi Preston,


You are moving the goalposts. Your original question was:


What I want to do is subtract the value of each cell in a row from the cell in the same column of another row, and add up the absolute values of all the differences


In my humble opinion, SGIII and Barry have given helpful solutions to your original question. Now your question has moved to:


calculating genetic distance for Y-chromosome STR haplotypes, which probably means nothing to you unless you're into genealogy.


Perhaps you should ask your new question in a genealogy forum. This is the Numbers for Mac forum. And you are correct; very few users here are qualified to calculate genetic distance for haplotypes.


Regards,

Ian

Dec 31, 2013 9:45 AM in response to papalapapp

@papalapapp



"Why not just substract the sum of row 1 from the sum of row 2?"


Subtracting the sum of one row from the sum of the other gives a different result than called for. Using the examples above, the result would be 30-50 = -20 or ABS(30-50) = 20.


Using the calculations in the two examples the result is 40.


Regards,

Barry

Dec 31, 2013 4:30 PM in response to Yellowbox

Sorry for the confusion - wasn't meaning to ask another question. Just explaining what the purpose of the exercise was.


I ended up using the formula =ABS(B2 - B$1) in the B3 cell and then copying to all the columns and summing across the result row. The object was to subtract each data row (for an individual) from the first row (the test case) and sum up the amount of absolute difference.


I was looking for the simplest way to code this since the sheet is 75 columns wide and over 1000 rows.

Dec 31, 2013 6:00 PM in response to papalapapp

@ papalapapp,


According to your result, I don't think that's going to do the job either.


You've calculated the differences of the absolute values, which it not the same as the absolute value of the differences of the actual values.


The three differences in your example are either 10, 30 and 10 OR -10, -30 and -10, depending which row was subtracted from the other. In eihter case, the absolute values of the differences are 10, 30 and 10, and the SUM of the absolute values of the differences is 50, not 30.


Preston's method will give the same results as Badunit's or mine.


Regards,

Barry


PS: Thanks for the German version of your formula—it gave me an Aha! moment regarding the English name of the root vegetable Mangelwurzel!

Dec 31, 2013 6:23 PM in response to Barry

Try this formula against your coulmn of ABS formulas. Replace the B4's with whatever your last column is


=SUMIF(B2:B4,">="&B1)−SUMIF(B2:B4,"<"&B1)+B1×(COUNTIF(B2:B4,"<"&B1)−COUNTIF(B2:B 4,">="&B1))


Note that the forum seems to be adding a space in the formula in the middle of the B and 4 of the last "B4". It shouldn't be there


EDIT: Oops, replied to the wrong person.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Subtract one row from another and add up absolute value of differences

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.