

FlashChat  Actuarial Discussion  Preliminary Exams  CAS/SOA Exams  Cyberchat  Around the World  Suggestions 
DW Simpson Global Actuarial & Analytics Recruitment 

Thread Tools  Search this Thread  Display Modes 
#1




Excel: sum of squares(or any operation) on a set of cells.
Say in A1:A4 I have 1, 2, 3, and 4 respectively.
Is it possible to take the sum of each of those #s squared in one cell? Sure, I could set B1=A1^2, copy that down, then take sum(B1:B4), but is there any way to do this directly in cell A5? Maybe with an array? Peace, Noonien Soong. 
#2




sumproduct(range,range)

#3




You'd think a guy with this pseudonym would know something about manipulating data.
Sorry, that was just lowhanging fruit, there.
__________________
"Facebook is a toilet."  LWTwJO Last edited by Dr T NonFan; 10172018 at 07:23 PM.. 
#7




To be fair, the OP asked about other functions. A feature of sumproduct (which, I admit, I have never used) is that you can include more than two columns, so you can compute the sum of nth powers with it. Using multiplicative coefficients and summing, any sum of polynomial functions (or even rational functions) of the cells is computable this way.
__________________
"What do you mean I don't have the prerequisites for this class? I've failed it twice before!" "I think that probably clarifies things pretty good by itself." 
#8




Would he? You need the dark arts and lore to manipulate data. Dr. Soong is a scientist, not a witch.
__________________
I live near the cows. 
#9




Aren't array formulae what the OP is looking for? SUMPRODUCT is a built in function which will handle a specific type of manipulation but array formulae will handle a much wider range of calculations.
e.g. {=SUM(A1:A4*A1:A4)} is the array formula equivalent of SUMPRODUCT(A1:A4, A1:A4) However, with array formulae, you can do much more. For example, you can do the following: for each cell in column A, take the greater of 20 or the cell value and then multiply it by the corresponding cell in column B. Finally take the greatest value of each of these. {=MAX(IF(A1:A4<20,20,A1:A4)*(B1:B4))} (Note that 20 could also be a reference to another single cell which contains the value 20. Or for something slightly different, it be another range of cells, e.g. C1:C4) Note that you don't actually type in the curly braces. You use Ctrl+Shift+Enter to enter the formula and the braces appear.* So array formulae are sometimes known as CSE formulae. Also, note that an array formula return an array result. However, apply a function that returns a single value such as SUM or MAX will give a a single number. Thus {=(A1:A4*A1:A4)} is actually returning a range of 4 rows x 1 column. The SUM in {=SUM(A1:A4*A1:A4)} is then adding these up to produce a scalar value. To see the full results of {=(A1:A4*A1:A4)}, you'd need to CSE the formula in range of 4x1. But entering this formula in a single cell won't produce an error  it will just give you the first row's result. If you accidentally enter {=(A1:A4*A1:A4)} in a range of 5x1, the last row will produce a #N/A error. However, you cannot delete part of a range of a CSE formula. You have to delete (or change) the entire range. But there is a way to get rid of that annoying error. In order to delete just the offending fifth row, you need to "undo" the CSE formula by highlighting the whole range and then using Ctrl+Enter (NO Shift) to reenter the formula  you'll see that the curly braces have disappeared.** Then delete the fifth row (allowable because its now longer part of a CSE formula) and then finally reenter the first rows as a CSE formula again. This sounds messy but you get used to it quickly and you only have to worry about it if you've selected the "wrong" output range. CSE formulae also work with matrices, not just vectors. Overall, I don't use CSE formulae very often but they can be extremely useful. I hope this was what you were looking for. * The technical explanation is that behind the scenes, Excel releases a small, invisible troll which quickly puts in the curly braces. ** The troll collects them again, obviously. Last edited by Hedges; 10182018 at 05:51 AM.. 
#10




Array functions are not ever my first solution. Last resort. I'd rather waste space in a separate column with a Min(20,A1) function, because it's easier to document and for a firsttime viewer to follow.
__________________
"Facebook is a toilet."  LWTwJO 
Thread Tools  Search this Thread 
Display Modes  

