keeping a running sum of a formula with conditions - excel

I am having an issue with an excel problem and cannot use vba or add any extra columns. The problem goes along with the format of this image. I could not find anything on google that helped me with this problem and im sorry if it has been asked before.
Example Image
On a separate page in a cell i need to write a function that will check if Info 2 = "z" and Info4 = "x" and if that is true then i need to do the following equation with the numbers in Info1 and Info3: Info1*(1 - Info3)
I will also have to keep a sum of these numbers.
For this example I would want the cell with the formula to equal -34 by doing the following:
3*(1-4)+5*(1-6) = -34
I would want the cell to just display the finished sum
Any help would be greatly appreciated,
Thank you!

You are looking for the mighty powers of SUMPRODUCT
=SUMPRODUCT((B:B="z")*(D:D="x")*(A:A)*(1-C:C))
The first two multipliers will make sure we only evaluate those rows having z for B and x for D. While the latter two are your desired function. Excel will evaluate this for each row and sum up the results.

I am using psuedo values below but this should work:
= [value of cell above] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
so basically starting in the middle, you have a two truth tests,
[info2] = "z", [info4]= "x"
using AND() requires they both pass
and([info2] = "z", [info4]= "x")
if they do pass you want to do your formula:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),FALSE)
but since we want to sum all values for each iterative row we make not passing this test 0:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
Ok so this works for one row, but doesn't sum the numbers from the tests on the previous row:
= [value of cell above or 0 for first row] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
an example written with real excel ranges that you may have to tweak depending on where your values are stored:
Sample picture

Related

2D vector lookup [x;y]

I've got a matrix, with two coordinates [i;j]
I'm trying to automatize a lookup:
As an example, this would have the coordinates of [1;2]
Here's a table of all the coordinates:
So here, obviously [1;2] would equate to 143,33
To simplify the issue:
I'll try to go step by step over what I'm trying to do to make the question bit less confusing.
Think of what I'm trying to do as a function, lookup(i, j) => value
Now, refer to the second picture (table)
I find all rows containing index [i] (inside column C) and then
only for those rows find row containing index [j] (inside column D ∩ for rows from previous step)
Return [i;j] value
So if u invoked lookup(2, 4)
Find all rows matching i = 2
Row 5: i = 2 ; j = 3
Row 6: i = 2 ; j = 4
Row 7: i = 2 ; j = 5
Lookup column j for j=4 from found rows
Found row 6: i = 2 ; j = 4.
Return value (offset for yij column = 143,33)
Now this isn't an issue algorhitmically speaking, but I have no idea how to go about doing this with excel formulas.
PS: I know this is reltively simple vba issue but I would prefer formulas
PSS: I removed what I tried to make the question more readable.
You can use SUMPRODUCT, which return 0 for not found values:
=SUMPRODUCT(($C$4:$C$18=$I4)*($D$4:$D$18=J$3)*$E$4:$E$18)
or AGGREGATE, which returns an error that can be hidden by the IFERROR function:
=IFERROR(AGGREGATE(15,6,(1/(($C$4:$C$18=$I12)*($D$4:$D$18=J$3)))*$E$4:$E$18,1),"")
You can use SUMIFS here assuming you will not have exact duplicate combinations of [i, j]. If you did have a duplicate combination, the amounts will be summed and placed in the corresponding cell
In cell B2 place this equation: =SUMIFS($Q$2:$Q$16,$P$2:$P$16,B$1,$O$2:$O$16,$A2) and drag across and over as needed
IF you want to convert the 0's to blanks you can nest the above formula inside a text formatter like so:
=TEXT([formula], "0;-0;;#")

Excel formula using more if

I have a problem with my nested if condition as an Excel formula. I know it would be easier by using VBA, but I have to do it this way.
This is my formula, but it returns FALSE:
=IF(D:D="SUPER";IF(AND(AA:AA="0";AA:AA="1");"V";IF(AA:AA="3";"R";"O")))
The D:D column has 3 filters, I have to apply the same formula with each filter.
The AA:AA column has the following conditions:
- if 0 and 1 -> V
- if 3 -> R
- if anything else -> O
I don't know why it doesn't work, but I would appreciate any advice!
This will return R, because there is 3 in there
enter image description here
I think this is more a matter of prioritizing logic flow. It seems that at least a single occurrence of SUPER with 3 supersedes the rest. The next priority would be SUPER with 0 and SUPER with 1 (both must occur). If none of those apply, default to O.
=if(countifs(d:d, "super", aa:aa, 3), "R", if(not(and(countifs(d:d, "super", aa:aa, 0), countifs(d:d, "super", aa:aa, 1))), "O", "V"))
'with semi-colons
=if(countifs(d:d; "super"; aa:aa; 3); "R"; if(not(and(countifs(d:d; "super"; aa:aa; 0); countifs(d:d; "super"; aa:aa; 1))); "O"; "V"))
=IF(COUNTIFS(D:D;"super";AA:AA;3)<>0;"R";IF(COUNTIFS(D:D;"super";AA:AA;1)*COUNTIFS(D:D;"super";AA:AA;0)=0;"O";"V"))
The order of the criteria was wrong, also you generally can't refer to entire columns in the way you did. This formula first checks whether there's any cell with the value 3. Then if there isn't it multiplies the count of 1s and 0s to check whether there are both numbers present.

Excel adding more conditions in a formula

I believed the condtions written will be quite long and i am not really good in writing this long formula
There are 6 columns i've used which is D ,E, M, N, O, P
Sample data:
D3=123456(Changing variable as it can be 12345, 12345A,123456A)
E3=1
M3=31
N3=_
O3=00
P3=0
The formula are design based on this Column D field(the variable changes is in this field) let say
if length of D3 = 6 then (the current formula i've done)
=IF(LEN(D3)=6,CONCATENATE(M3,D3,N3,O3,E3),CONCATENATE(M3,D3,O3,E3))
The outcome for this will be 31123456_001, if let say the D variable is changed to 123456A( the else
in the formula i've shown as no concatenate N3)
then the outcome will be 31123456A001.
I have added in column p, so that i can use it to concatenate to the format that i need.
There are a few more conditions i need to add in,
Which is
1. If the D3= 12345, the format outcome will be 31012345_001 (concatenate M3,P3,D3,N3,O3,E3)
2. If the D= 12345A, the format outcome will be 31012345A001 (concatenate M3,P3,D3,O3,E3)
3. Data for the column D3 field, 12345A, the A alphabet can be in A-Z.
These are the list of all conditions and outcome that i required in a formula.
1. D3 = 123456 then the outcome will be 31123456_001
2. D3 = 123456A then outcome will be 31123456A001
3. D3 = 12345 then outcome will be 31012345_001
4. D3 = 12345A then outcome will be 31012345A001
Additional info:
These are just format as it can be any numbers combinations, the last letter alphabet can be A-Z
D3 = 123456
D3 = 123456A
D3 = 12345
D3 = 12345A
As I couldn't quite catch all the conditions and outcomes, here is an example of how your formula could look:
=IF(LEN(D3)=5,Outcome_1_Concatenation,IF(LEN(D3)=7,Outcome_2_Concatenation,IF(ISNUMBER(VALUE(RIGHT(D3,1))),Outcome_3_Concatenation,Outcome_4_Concatenation)))
Outcome_1_Concatenation => replace with formula when LEN = 5
Outcome_2_Concatenation => replace with formula when LEN = 7
Outcome_3_Concatenation => replace with formula when LEN = 6 and all are numbers
Outcome_4_Concatenation => replace with formula when LEN = 6 and last is character
If you give all examples in a condition => outcome list, I would be glad to help further.
I would look at creating a lookup table range with 3 options for lengths of 5,6,7.
I named my lookup table range "Length".
First setup this lookup table like this:
5 |
=CONCATENATE(M$3,P$3,D$3,IF(ISNUMBER(VALUE(RIGHT(D3,1))),N3,""),O$3,E$3)
6 |
=CONCATENATE(M$3,IF(ISNUMBER(VALUE(RIGHT(D$3,1))),"",P$3),D$3,IF(ISNUMBER(VALUE(RIGHT(D3,1))),N$3,""),O$3,E$3)
7 |
=CONCATENATE(M$3,D$3,IF(ISNUMBER(VALUE(RIGHT(D$3,1))),N$3,""),O$3,E$3)
For any D3 value, it is checking if that last character is a letter, and if not it will insert N3, otherwise it leaves it out.
Also, for any 6 character value, it checks if the last character is a letter, and if so, it will insert P3, otherwise it leaves it out.
Then, your output formula should be:
=VLOOKUP(LEN(D3),Length,2,FALSE)
This makes it clean and simple.
This is your formula plus the added conditions 1 and 2:
=IF(D3=12345,CONCATENATE(M3,P3,D3,N3,O3,E3),IF(D3="12345A",CONCATENATE(M3,P3,D3,O3,E3),IF(LEN(D3)=6,CONCATENATE(M3,D3,N3,O3,E3),CONCATENATE(M3,D3,O3,E3)))
If you want a more generalized version you can check if D3 is a number, the length of it, if D3 ends with a letter, and replace the nested ifs according to your needs
I got my answers, it's
=IF(AND(LEN(D3)>=6,ISNUMBER(RIGHT(D3,1)*1)),M3&D3&N3&O3&E3,IF(AND(LEN(D3)<6,ISNUMBER(RIGHT(D3,1)*1)),M3&P3&D3&N3&O3&E3,IF(AND(LEN(D3)=6,ISTEXT(RIGHT(D3,1))),M3&P3&D3&O3&E3,M3&D3&O3&E3)))

Creation of vector of unknown size in Excel

I am attempting to translate my existing Matlab code into Numbers (basically Excel). In Matlab, I have the following code:
clear all; clc;
n = 30
x = 1:(n-1)
T = 295;
D = T./(n-x)
E = T/n
for i=1:(n-2)
C(i) = D(i+1) - D(i)
end
hold on
plot(x(1:end-1), C, 'rx')
plot(x, D, 'bx')
I believe everything has been solved by your formulas, there are parts of them that I don't understand otherwise I would try to figure the rest out myself. Attached is the result (Also you might like to know that the formulas you gave work and are recognized in Numbers). Im trying to figure out why (x) begins at 2 as I feel as though it should start at 1?
Also it is clear that the realistic results for the formulas only exist under certain conditions i.e. column E > 0. That being the case, what would be the easiest way to chart data with a filter so that only certain data is charted?
(Using Excel...)
Suppose you put your input values T & n in A1 & B1 respectively.
You could generate x, D & C In columns C,D & E with:
C1: =IF(ROW()<$A$1,ROW(),"")
D1: =IF(LEN(C1)>0,$A$2/($A$1-C1),"")
E1: =IF(LEN(D2)>0,D2-D1,"")
You could then pull all 3 columns down as far as you need to generate the full length of your vectors. If you then want to chart these, simply use these columns as inputs.

Trying to construct an IF statement in Excel with multiple conditions

Basically I need to calculate a column that sum's previous columns only if:
The number in column Q > 4,
Column S = 'N' (its a 'Y' or 'N' flag in this column and I only want to sum if there is an 'N'
P != 0 (There is a number in column P.)
This is the incorrect statement which I came up with:
=IF((Q2>4) AND (S2='N') AND (P2 != 0), V2)
(Column V contains the calculation I want to make, given that these conditions are met.
Kinda lost here guys, would really appreciate any help.
All the best.
EDIT: fixed single-quote>>double and != >> <>
=IF(AND(Q2>4, S2="N", P2<>0), V2, "")

Resources