Excel: Sum The Values Other Than the Top Three in a Range - arrays

Using Excel I would like to get the total of the values in a range other than the top three values.
The range has #N/A values I would like to ignore.
The range in horizontal.
In the case where as an example the top 4 values are all 8, I would only want three of the 8s to be excluded from the sum.
I have managed to sum the top three values in the range using the following function:
=SUM(LARGE(IF(NOT(ISNA(AW2:BH2)),AW2:BH2),{1,2,3}))
I assume there is a small adjustment I can make to the above, but my brain's not working.

You can use the AGGREGATE function to ignore the errors:
=AGGREGATE(9,6,AW2:BH2)-SUMPRODUCT(AGGREGATE(14,6,AW2:BH2,{1,2,3}))
Function_num 9 = SUM
Function_num 14 = LARGE
Option 6 = Ignore errors
You will get an error if there are less than three values in the row. You could trap for that with either COUNT or IFERROR if that might be an issue.

Array formula**:
=SUM(IF(ISNUMBER(AW2:BH2),IF(1-ISNUMBER(MATCH(AW2:BH2+COLUMN(AW2:BH2)/10^6,LARGE(IF(ISNUMBER(AW2:BH2),AW2:BH2+COLUMN(AW2:BH2)/10^6),{1,2,3}),0)),AW2:BH2)))
Regards
where the values in the range AW2:BH2 are assumed to of an order greater than 1E-6.
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

Related

Makearray function in Office Excel unable to generate proper amount of columns for the array

I am using Office 365 currently and I want to make a visualization tools using MAKEARRAY functions.
For example, if I want to display sequential of 32 items, I would display it in this way:
I use the following formula of Makearray to generate the custom array for me
Note: Formula is pasted at cell value F3 .
=MAKEARRAY(ROUNDUP(B2/B3,0),IF(E3#=ROUNDUP(B2/B3,0),MOD(B2,B3),B3),LAMBDA(row,col,"O"))
but it seems like after debugging, this part of the formula are giving it the problem are these
IF(E3#=ROUNDUP(B2/B3,0),MOD(B2,B3),B3)
as I debugging the formula separately as shown in picture below, it can generate the correct amount of columns as it is supposed to.
Note: Generate exactly same amount to the no of columns if row number is not matching;
Generate modulus remainder formula if row number is matching to roundup of no. of items divided by no. of columns.
But in the end, I put that problematic formula back into the MAKEARRAY function just give only a single columns, which seems like it is quite wrong.
May I know why it display single columns even though by right, it should display the correct amount of no. of columns?
What about:
Formula in C1:
=WRAPROWS(INDEX("O",SEQUENCE(A1,,,0)),A2,"")
Or rather:
=WRAPROWS(EXPAND("O",A1,,"O"),A2,"")
MAKEARRAY does not expect an array in the number of columns. It is a set number. It will iterate the number of rows and number of columns to create the array. It will always be square and not jagged.
So you need to do the math to change the value:
=MAKEARRAY(ROUNDUP(B2/B3,0),B3,LAMBDA(rw,clm,IF(10*(rw-1)+clm>B2,"","O")))
Now as soon as the space is greater than the 32 it puts in "" instead of "O"

Excel: contingent upon column, increment a different column and multiply all sums

So I have column A with mpnths. Column B has percent win and loss. I want to add 1 to the value in column B and then find the product of all values in column B to determine the compound growth of the dataset. Then I want to take this value and put in in my reports sheet.
=PRODUCT(SUM(1,IF(MONTH('#MOMO Trades'!A1:A1000)=4,'#MOMO Trades'!B:B,0)))
Please help me correct this formula.
thanks!
In order for the SUM function to add 1 to each row individually, you will need to use an array formula, rather than a formula. Otherwise, it will try to add 1 to an array, which it can't do.
To do this, enter the formula as you would normally, but when you have typed it press Ctrl+Shift+Enter instead of just Enter. It will show up surrounded by braces, like this:
{=PRODUCT(SUM(1,IF(MONTH('#MOMO Trades'!A1:A1000)=4,'#MOMO Trades'!B:B,0)))}

Excel maximum difference between consecutive values in array

I have an array of numbers:
46.50, 46.50, 46.50, 50.00, 60.00, 57.00, 50.00, 48.00, 44.00, 42.00
I'd like to create a formula that finds the maximum positive difference between two consecutive pairs. So in the above example, the intermediate calculation would be:
0,0,-3.50,-10.00,3.00,7.00,2.00,4.00,2.00
Therefore the answer would be 7.00
Going to go with a basic array formula for this one. Aussuming your data is layed out as per the image below, used to offset ranges and subtract one range from the other. Then take the maximum of those results. This can be achieved using the following formula entered as an array. meaning you need to confirm it with CTRL+SHIFT+ENTER. You will know you have done it right when {} show up around your formula. They cannot be added manually.
=MAX(B3:B11-B4:B12)
as an alternative non array formula you can got with AGGREGATE which will perform array like calculations:
=AGGREGATE(14,6,B3:B11-B4:B12,1)
The above formulas will provide you with the largest positive difference. If how ever you need to know the largest difference, then -10 is a larger difference than 7. Its just in the opposite direction. To find this you would need to add ABS to the above equations as follows:
=MAX(ABS(B3:B11-B4:B12))
OR
=AGGREGATE(14,6,ABS(B3:B11-B4:B12),1)
Use an array formaula. If your values are in column A (rows 1 to 10 in this case), use
=MAX(A1:A9-A2:A10)
And enter it with CTRL-SHIFT-ENTER instead of just Enter.

How to use Round() in an array formula?

I am trying to count the number of unique values in a range of values after the values are rounded to the hundredths place.
This is the formula I am using to count the number of unique values in the range:
=SUMPRODUCT(1/COUNTIF($EZ6:$FD6,$EZ6:$FD6&""))
and this is what I've tried to count the number of unique values in the range after rounding:
=SUMPRODUCT(1/COUNTIF(ROUND($EZ6:$FD6,2),ROUND($EZ6:$FD6,2)&""))
This formula produces an error and doesn't evaluate.
The issue isn't adding the "" at the end, since this formula also produces an error and doesn't evaluate:
=SUMPRODUCT(1/COUNTIF(ROUND($EZ6:$FD6,2),ROUND($EZ6:$FD6,2)))
By produce an error, I mean that a message box appears saying "There is a problem with this formula..."
Yes unfortunately Countif only works with ranges, not arrays - as soon as you introduce the Round function, you are implicitly using arrays.
I would suggest using the Frequencies method for getting unique values:
=SUM(--(FREQUENCY(IF(EZ6:FD6<>"",ROUND(EZ6:FD6,2)),ROUND(EZ6:FD6,2))>0))
This is based on a standard formula see documentation- the only issue is that if you apply the Round function to blank cells, you get zero, which could give you an extra unique value, hence the If statement.
Must be entered as an array formula using CtrlShiftEnter

Array Formula To Find 2nd Largest Number

I currently use the following formula to find the largest number in a dataset (Sheet1K7:K106), conditional on some corresponding values (Sheet2!C7:C106) being less than a certain number (Sheet3!C18):
=MAX(Sheet1!K7:K106*(Sheet2!C7:C106<Sheet3!C18))
I would like to now find the second largest number given the same condition. I would assume that this requires the LARGE function, although I can't seem to apply the aforementioned condition.
If you're using Excel 2010 or later:
=AGGREGATE(14,6,Sheet1!K7:K106/(Sheet2!C7:C106<Sheet3!C18),2)
Otherwise, array formula**:
=LARGE(IF(Sheet2!C7:C106<Sheet3!C18,Sheet1!K7:K106),2)
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

Resources