Comparing an array to an array with IF statement in Excel - excel-formula

I am trying to simulate a portfolio rebalancing strategy with Excel.
Assuming there are 10 stocks each with a target allocation weight and an upper and lower band that is acceptable. If the band is exceeded in either direction, rebalancing is mandated. Each stock has a different weight. I am now trying to come up with an if statement to compare the actual allocation weight (after simulated returns) of each stock with its individual upper/lower band.
E3:E13 is the actual allocation weight after returns of a period.
C3:C12 is the lower acceptable value
D3:D12 is the higher acceptable value.
I tried the following formula to populate a cell with either "yes" (= rebalance) or "no" (= not rebalance) based on which the next term allocation will be based:
=IF(E3:E12<$C$3:$C$12,"yes",IF(E3:E12>$D$3:$D$12,"yes","no"))
I was hoping this would compare E3 with C3, E4 with C4 etc, and also E3 with D3, E4 with D4, and so forth. Unfortunately, the formula does not create the right output, it often says "no" when some of the bands are exceeded. How could I fix this?

Something like this? You need to compare a cell's value with 2 other cells, then you can use OR (in case you want to match either) ... or you may use AND (if you want to match both cells)
EDIT: Based on your request - you can use an ArrayFormula to get that (press Ctrl+Shift+Enter)

Related

Matching all combinations (values) from matrix-like-table using drop-down

On my workbook (WB) there are 2x sheets. One is Test1 or where I have my drop-downs (from A22 and below) and on A8-A11 are matching fields that are being colored if correspoding match is "hit". In my case FALSE is (_) and TRUE (1) if you are looking on Matrix table on sheet2.
On sheet 2 (Matrix) is matrix-table that has horizontal/vertical axis same (headers), and (_'s) (1's) if there is an interesection. Meaning, it has to be all FALSE so that the System is in "green (all FALSE)" and can be sold, if only one part is "red (TRUE)" then the combination is not supported.
Example from matrix:
070FX has (_) on intersect has (1) on CE0, D01 and it that case it should hit TRUE. So all three parts should be "red (TRUE)", as it is on 3rd picture.
If you check my TRUE/FALSE results from formula (in A13 and A14) you can understand it slightly better:
=SUMPRODUCT((Matrix!$A$2:$A$103=A12)*((Matrix!$B$1:$CV$1=$A$9)+(Matrix!$B$1:$CV$1=$B$9)+(Matrix!$B$1:$CV$1=$C$9)+(Matrix!$B$1:$CV$1=$D$9)+(Matrix!$B$1:$CV$1=$E$9)+(Matrix!$B$1:$CV$1=$F$9)+(Matrix!$B$1:$CV$1=$G$9)+(Matrix!$B$1:$CV$1=$H$9)+(Matrix!$B$1:$CV$1=$I$9)+(Matrix!$B$1:$CV$1=$J$9)+(Matrix!$B$1:$CV$1=$K$9)+(Matrix!$B$1:$CV$1=$A$12)+(Matrix!$B$1:$CV$1=$B$12)+(Matrix!$B$1:$CV$1=$C$12)+(Matrix!$B$1:$CV$1=$D$12)+(Matrix!$B$1:$CV$1=$E$12)+(Matrix!$B$1:$CV$1=$F$12)+(Matrix!$B$1:$CV$1=$G$12)+(Matrix!$B$1:$CV$1=$I$12)+(Matrix!$B$1:$CV$1=$J$12)+(Matrix!$B$1:$CV$1=$K$12))*(NOT(ISERROR(1/VALUE(Matrix!$B$2:$CV$103)=1))))>0
Maybe you are asking why two rows of formulas (A13 and A14), it is actually one formula but I separated into two rows because of printing, this document should fit on one page only.
*The problem what I have is making this more dynamic, and easier to read/understand. If you see my formula it is SUMPRODUCT but it does have hard-coded arrays, and that is not what I need, I realise recently that we have many changes within our document and sometimes parts are being added or deleted. But my array is hard-coded, so you can imagine how much effort is to adjust it. And to explain to someone how it works is also pain in the ss.
I hope there is some different way to do this, maybe another set of functions or even with Power Query as best dynamic thing in Excel.
https://docs.google.com/spreadsheets/d/1UC0cgsVCm0ekbtu7Wsjpy8PdJ76o8HNq/edit?usp=sharing&ouid=101738555398870704584&rtpof=true&sd=true
The formula below could be used in cell A13 and then copied across
=SUMPRODUCT((_0359_matrix[_]=A9)*(IFNA(IF(MATCH(COLUMN(_0359_matrix[[#Headers],[070FX]:[YS1]])-1,MATCH($A$9:$K$9,_0359_matrix[[#Headers],[070FX]:[YS1]],0),0),1,0),0)+IFNA(IF(MATCH(COLUMN(_0359_matrix[[#Headers],[070FX]:[YS1]])-1,MATCH($A$12:$K$12,_0359_matrix[[#Headers],[070FX]:[YS1]],0),0),1,0),0))*(NOT(ISERROR(1/VALUE(_0359_matrix[[070FX]:[YS1]])=1))))>0
and the formula below could be used in cell A14 and then copied across
=SUMPRODUCT((_0359_matrix[_]=A12)*(IFNA(IF(MATCH(COLUMN(_0359_matrix[[#Headers],[070FX]:[YS1]])-1,MATCH($A$9:$K$9,_0359_matrix[[#Headers],[070FX]:[YS1]],0),0),1,0),0)+IFNA(IF(MATCH(COLUMN(_0359_matrix[[#Headers],[070FX]:[YS1]])-1,MATCH($A$12:$K$12,_0359_matrix[[#Headers],[070FX]:[YS1]],0),0),1,0),0))*(NOT(ISERROR(1/VALUE(_0359_matrix[[070FX]:[YS1]])=1))))>0
Both formulae are longer than they could be, since they're using table referencing but, since you wanted your formulae to be dynamic, I think it's appropriate (without table referencing the formulae are approximately half the length of the originals).
The formulae are just shorter versions of your originals but there is a LOT of duplication of calculations in both sets, i.e. ALL 22 cells calculate the mid portion (the middle multiplicand) and the last portion (the last multiplicand) so, for the sake of performance, it would be sensible to have 2 helper cells (or 2 named formulae) which calculate these values once, and then just have the 22 formulae referring to these, thus shortening the formulae considerably.
(the table referencing may, or may not, make the formula less readable so I'm including below a screenshot of my 'research'
the data in row 1 are proxies for your table headers, and the data in row 3 are proxies for your row 9 (of Test1) - the formula effectively does all the matching for a single row in aggregate, rather than having to sum individual results, as was the case in your original formulae; in this way there are 2 'copies' of the formula, since your headers (on Test1) are on 2 different rows due to your 'printing constraint' - you could make my formula shorter if all headers were in a single row, e.g. by putting the formula =A12 in cell L9, =B12 in M9 etc (and possibly hiding those columns, to keep the sheet 'clean') - if you implemented this suggestion, then the formula for cell A13 could be shortened to this
=LET(hdrs,_0359_matrix[[#Headers],[070FX]:[YS1]],SUMPRODUCT((_0359_matrix[_]=A9)*(IFNA(IF(MATCH(COLUMN(hdrs)-1,MATCH($A$9:$V$9,hdrs,0),0),1,0),0))*(NOT(ISERROR(1/VALUE(_0359_matrix[[070FX]:[YS1]])=1))))>0)
which is less than 1/3 the length of your original formula)

How to work out a % increase in value up to or above a range of numbers

Got a task to work out the value of some shares but only if the value is up to or between a certain amount.
The value in C2 can be between 0-25.
For Class B, I need a formula that represents 5% of the value in C2 but only up to 10.
For Class D, the formula needs to show the value of 2.5% but only when the value in C2 is between 10-25
Have no idea where to start, any help is much appreciated.
We try not to answer people's homework for them, but here are some hints for you to get you started:
Functions begin with =. That's what tells Excel to do a calculation.
Reference cells directly, so you could do something like =c2*0.05 in any cell to find 5% of the value in c2.
Use if to make things happen sometimes. So, if you want to only do something if c2 is over 10, use =if(c2>10, over_ten_answer, below_ten_answer) (over_ten_answer and below_ten_answer are just placeholders for bits of formula that you could use in those spots.)
Hopefully, that should be enough to get your going.
I would recommend looking into learning how to nest if statements if you're going to do a lot if this type of data manipulations. See below for a simple nested if formula to resolve
=IF(A1<26,IF(A1<11,A1*0.05,A1*0.025),0)
I have the value that you want the 2.5% or 5% of in cell A1 in the above. If the number is above 25, The formula that I have here will set it to 0(just replace the 0 at the end with whatever you want it to return).

need help using/choosing excel function

ive been trying to break into some excel just to get a little bit familiar with the program but im a little lost on some of the prebuilt functions. Here is one of the exercises ive been attemping.
In cell B5 calculate the projected sales for January 2015. Use the Average 2014 Monthly Sales in B2 and the Growth Rate in cell B1. In cell C5, use appropriate cell referencing to calculate the projected sales for February 2015 based on the projected January sales and the Growth rate.
which function would be best suited for this ?
This would be a straight forward math problem
future amount = current amount + (current amount * percentage increase)
or simplified:
future amount = current amount * (1 + percentage increase)
in B5:
=B2*(1+B1)
Then in C5:
=B5*(1+$B$1)
And copy/drag across. The B5 reference will change appropriately and it will fill in the correct amounts across.
You want a single formula for it all:
In B5 put:
=FVSCHEDULE($B$2,INDEX(($B$1*ROW(INDIRECT("1:" & COLUMN(A:A))))/ROW(INDIRECT("1:" & COLUMN(A:A))),))
And drag across.
I prefer Scott's original answer and it works really well in in this case. I just want to expand on this as it appears to me to be a compound interest problem and finding out what the nth value of an investment is based on a fixed interest rate. So a more general equation would be:
=P*(1+i)^(n)
P - Principal or starting value
i - Interest rate for the period (not annual unless you period is annual)
n - period number, 1 for first period 2 for 2nd etc.
Scott's formula works really well because all the months are side by side and there are no gaps. This is what the OP presented to us in the example. However, if months had been missing a different approach would have been necessary.
An alternative approach using the OPs orignal setup could be:
=$B$2*(1+$B$1)^(COLUMN(A1))
B2 is the starting principal P
B1 is the interest for the period
COLUMN(A1) is a way to count the nth period as the formula is copied across.
If the date was stored in B4 and formatted to display a month, we could substitute the following for determining the nth period:
Month(B4)
Of course this assumes that the whole thing started in the first month, but an alternate form could be used to adjust the value based on a supplied starting month/date.
And of course the entire header row of month could simply be changed to an integer representing the nth period of interest
On a side note, one of the nice parts of using this method, is that it is independent of what is happening in adjacent cells. Should a column in the middle of the series be erased, you will not be faced with a series of errors.

How can write a formula in an excel 2010 cell that returns an answer based on 3 different conditions?

I am trying to get my invoice to autofill a cell when I pick a category from a combobox and then fill in a number in another cell. If the category is Residential, Duplex or Multi-Family the cost is the value entered into B28xthe value of the constant in F28 and this does work.
If I pick Deck I need it to use the same formula unless the Product is less than 60 in which case it should enter 60 as a minimum which does happen.
It's when I need it to return a value greater than 60 which would mean B28 is >400 that the problem arises. The value won't go over 60.
N41 is kind of a holding cell for the value for Deck. When the combobox is empty the formula returns false which I don't want to show in the cell.
Here is my formula
=IF(I13="Residential",(B28*F28),IF(I13="Duplex",(B28*F28),IF(I13="Multi- Family",(B28*F28),IF(I13="Deck",IF(N41=0,MAX(0),IF(N41<112.5,MAX(60),IF(N41>=60,MIN(N41),"")))))))
Min() and Max() are usually used with two arguments, to deliver the smaller or the bigger of two values respectively. You use it with one parameter only, which will return exactly that number. That does not make any sense.
Also, consider using OR() to bundle the first three IFs into one.
It is not clear what the last part of the formula is meant to achieve.
=IF(OR(I13="Residential",I13="Duplex",I13="Multi- Family"),B28*F28,IF(I13="Deck",IF(N41=0,0,<here is where it gets unclear>))))
Please edit your question and clarify, making sure to post the values and formulas of the contributing cells.

IF formula not working

What is wrong with this Excel formula?
=IF((C7-$C$2)<=$C$2,(C7*C3),IF((AND((C7-$C$2)>(2*$C$2),(C7-$C$2)<=($C$2*2),((C7-$C$2)*($C$4)),IF(AND((C7-($C$2*2)>($C$2*2),(C7-$C$2)>($C$2*2),(C7-(C7-($C$2*2)),(C7*$C$5)))
It's a sales calculation where:
if you sell over a certain number you get one level of commission per deal and
if you sell 2X a specific number you get a higher pay out for every deal
I entered your formula into D7 and immediately got an error "The formula you typed contains an error" with the whole formula highlighted. That indicated that Excel couldn't find one explicit error. I also noticed that the last ")" wasn't black so that suggested a nesting error. My usual way for finding these is to F2 while on the cell and left arrow through the brackets - go over the last bracket and its corresponding bracket should turn bold in the cell/formula bar. If it's not the first bracket you've got a problem!
Bracketing can be good but it can be confusing if over-used - multiplications will always be calculated first by Excel before addition/subtraction so you could try getting rid of some bracket pairs but read on because there may be a better solution.
Formula are sometimes easier to understand if you define your parameters within Named Ranges (i.e. Base Sales Volume in C2 named as BSV or BaseSales) which you can then see in the formula. BaseSales is a lot easier to comprehend than $C$2.
After naming your ranges for the Base Sales, create Named Ranges for your three commission rates in $C$2, $C$3 and $C$4. Replace the references to the absolute cells in your formula. In 2007+ on the Formula tab go Define Name...Apply Name and highlight all the names you made then apply. Your formula should have names instead of cell references.
Nested formulae are good but sometimes you need to build them up from simple formulae over many columns and then consolidate the crucial bits to put into your mega-formula.
Instead of testing from the bottom up through the target levels consider top down -
IF sales > top target
sales * top rate
ELSE
IF sales > 2nd target
sales * 2nd rate
ELSE
sales * base rate
Then you should be able to do it with just two IF functions.

Resources