Nested IF statements with VLOOKUPs - excel

I'm trying to created a nested IF statement that says, for example, IF A2 is equal to x, x, x posting codes then pull data from the revenue column, IF A2 is equal to y, y, y posting codes then pull data from Bad Debt column and so on for 6 different possible results. Only 3 of the 6 are VLOOKUPs. The other 3 are just if A2=Z then "1024".
I will copy what code I currently have, but it's not pretty. Any help is appreciated. Thank you.
=IF(G2="100",G2="101",G2="102",G2="105",G2="106",G2="170",G2="171",G2="173",G2="200",G2="210",G2="220",G2="230",G2="250",G2="300",G2="301",G2="302",G2="304",G2="305",G2="306",G2="307",G2="308",G2="309",G2="310",G2="312",G2="313",G2="314",G2="315",G2="316",G2="317",G2="318",G2="319",G2="320",G2="321",G2="322",G2="323",G2="324",G2="325",G2="326",G2="327",G2="328",G2="329",G2="330",G2="331",G2="332",G2="333",G2="334",G2="335",G2="336",G2="337",G2="338",G2="339",G2="340",G2="341",G2="342",G2="343",G2="344",G2="345",G2="346",G2="360",G2="370",G2="372",G2="379",G2="382",G2="383",G2="385",G2="390",G2="402",G2="403",G2="404",G2="405",G2="414",G2="415",G2="416",G2="417",G2="418",G2="419",G2="420",G2="421",G2="425",G2="427",G2="428",G2="429",G2="440",G2="441",G2="442",G2="443",G2="444",G2="445",G2="447",G2="472",G2="477",G2="480",G2="501",G2="600",G2="700",G2="800",G2="900",vlookup('AR Credit'!A2,Guarantors!A:D,3,FALSE),IF(G2="347",G2="384",G2="399",G2="406",G2="499",G2="801",vlookup('AR Credit'!A2,Guarantors!A:D,5,FALSE),IF(G2="348",G2="354",G2="355",G2="357",G2="377",G2="601",vlookup('AR Credit'!A2,Guarantors!A:D,4,FALSE),IF(G2="120",G2="150",G2="151",G2="152",G2="153",G2="154","1051",IF(G2="400","1385",IF(G2="500","2036",IF(G2="172","3783","Null"))))))))

One way of fixing your issue is by using OR, specifically wrapping your cases in it like in this example:
=OR(G2="100",G2="101",G2="102",G2="105")
This will result in TRUE if any of conditions is met, otherwise FALSE.

There are numerous errors with your formula. You could get it working by following Zipa's answer and using the OR function. However, it would be a nightmare to maintain if anything changes in future.
I would recommend creating a look up table for the values and results. It could then be queried like so:
=IF(COUNTIFS($E$2:$E$98,$A2)>0,$E$1,
IF(COUNTIFS($F$2:$F$98,$A2)>0,$F$1,
IF(COUNTIFS($G$2:$G$98,$A2)>0,$G$1,
IF(COUNTIFS($H$2:$H$98,$A2)>0,$H$1,
IF(COUNTIFS($I$2:$I$98,$A2)>0,$I$1,
IF(COUNTIFS($J$2:$J$98,$A2)>0,$J$1,
IF(COUNTIFS($K$2:$K$98,$A2)>0,$K$1,"NULL")
)
)
)
)
)
)
See the image below for illustration:
Where I have put "Opt1", "Opt2" in the results row, you can put your VLOOKUPs (although I would recommend INDEX/MATCH instead) or your hard coded values.
This way, you can easily see (and modify) which group each code is in. Even adding more groups wouldn't be too difficult.
Obviously, you could move the table onto a different sheet if you wished.

Related

Excel percentage increase based on formula

I am trying to fill the sell price column in an Excel spreadsheet with the increased values in colors based on the round up columns value (1 to 50 green, 50 to 100 blue, 100 to 150 yellow, 150+ pink).
I've opted for the percentage table because some items can be sold for a lot more than what I have purchased them for, so that's just for my benefit. I am open to any other suggestions and I am new to this whole business thing.
I was using IF in my formula which would work great for using one percentage increase in the formula:
=IF($E27<50,ROUNDUP(I$27,-1))
If I try to enter a second argument like
=IF(OR($E28<50,ROUNDUP(I$28,-1)OR($E28>50,<100,ROUNDUP(J$28,-1))))
I will get an error.
I'm probably using the formulas wrong, I've tried "AND" and a couple other formulas, but I can't find anyone else trying to achieve the same or similar.
So something like this:
=IF($E28<50,ROUNDUP(I$28,-1),IF($E28>50,ROUNDUP(J$28,-1),"Error"))
But not sure what the <100 was for.
Although the problem is not completely clear, I understand that you want to add a formula with nested if statements.
I will recommend you to try nested ifs in parts.
=IF($E27<50,ROUNDUP(I$27,-1),"First if condition is false")
If everything is working as per the requirement then edit that text in the formula to add another if statement.
=IF($E27<50,ROUNDUP(I$27,-1),IF(OR(condition 1, condition 2,more conditions),"value if true","value if false"))
In the second argument provided by you, the arguments of the OR function has not been properly provided. Ensure that all the arguments of an OR function are conditions separated by a comma.
$E28<50 This is a condition so it's ok.
But other arguments are not making sense.
Also, using OR multiple times inside the first OR arguments is not clear.
It would be beneficial if you could provide the basic table and mention the requirement clearly.

Define Status depending on Criteria

I have advanced Excel/Google Sheets skills. I have more of a conceptual question. I am happy with any solution (Excel or for Sheets, no difference for me).
I have a sheet where various coworkers have access and work with. It is used to define which product needs to go through which steps. Then when a part of a job is done, the status of the product is changed depending on criteria.
You can also think of it as projects and the status of a project.
The 3 examples shows how the data is input by the workers. Sometimes, the "No" cells are empty, sometimes they have a "No", sometimes for the same product, one criterion is empty, the other has a "No".
If I do a nested IF formula, I would have to create 32 of them (I believe, since its 5 criteria with each 2 options).
Obviously I can do that. I was wondering anyone has a better solution for me? Something more practical.
Thanks in advance!
Based on the data you've provided, it looks like your statuses are based on the number of Yes's in the input columns. Also you don't have a status shown for zero Yes's so I'll make an additional for that.
Given that assumption you can use a combination of the COUNTIF function (to count the Yes's), and the IFS function (to manage nested Ifs better) to drastically reduce the size of your function.
To make this cleaner I suggest you add a column and hide it containing: =COUNTIF([InputCriteria1to5Range],"Yes")
For the next formula assume the formula above is in B2. In your status column put the following:
=IFS(B2=5, Status1, B2=4, Status2, B2=3, Status3, B2=2, Status4, B2=1, Status5, B2=0, Status6)
Solution: Thanks to all for your help, I ended up firstly, creating ALL scenarios. This was actually the most complex part. See https://www.mrexcel.com/forum/excel-questions/654871-how-generate-all-possible-combinations-two-lists-without-macro.html (Answer from "Tusharm") where I had to repeat this process 5 times to have all possible outcomes. In the end, there were 192 combinations.
Then, I assigned a status for each combination.
Finally, for each product/row, I created another column where I concatenated the different criteria so that it looks exactly like my above combinations. Then finally index match the concatenated criteria to my combinations.

Sum with text conditions

Good afternoon, I'm stuck with a small problem of formulas in excel:
I have a table in another sheet and I have to perform the following operations:
1. number of units sold in Bogota.
2. number of units sold in different cities to Bogota.
I'm trying to use the formula:
=SUMIF(DATOS!$G$4:$G$146;"BOGOTA";DATOS!$H$4:$H$146)
For the first requirement works, but at the moment of using it to know which city is different from Bogota, I do not know how to do it; try to use the <> operator but I get an error and placing the formula as follows:
=SUMIF(DATOS!$G$4:$G$146;NOT("BOGOTA");DATOS!$H$4:$H$146)
do not add the data (Summation gives 0). Someone has an idea of the problem.
I believe you have to put quotes "like this" around the entire logical statement ""<>BOGOTA"
It can be used like this:
=SUMIF(DATOS!$G$4:$G$146;"<>BOGOTA")
Hope this helps

Conditional standard deviation? STD.S with IF not working; trying to apply to data after using AVERAGEIFS with same conditions

(I am working with a Spanish interface, so please forgive the code in Spanish (the ; is a , in English, PROMEDIO.SI.CONJUNTO is AVERAGEIFS, INDICE is INDEX, FILA is ROW, DESVEST.M is STD.S, SI is IF, Y is AND).
I have look through all the threads about a "stvifs" (which Excel really should think about in the future!) and I am still unable to apply what I've learned to my data, even though it seems exactly like what I've seen! After successfully applying the following to my data:
=PROMEDIO.SI.CONJUNTO(E:E;A:A; INDICE(I:I; 2+(FILA(1:1)-1));D:D; 1;F:F; "BC")
I automatically got my column with "BC" and their means for each participant. (I have four conditions in total.) Now I want the SD for the SAME conditions. I tried applying this code as an array formula:
{=DESVEST.M(SI(Y((A:A)=INDICE(I:I; 2+(FILA(1:1)-1));(D:D)=1;(F:F) ="BC");E:E))}
I get a #DIV/0! error. I debugged the formula, and it is giving me FALSE as a result within the STD.S, hence the error. But what I don't understand is why it's not giving me an array with all the values in the column E that comply with the given conditions! The interesting thing is that when I apply the formula normally, it gives me STD.S(E:E) correctly, so I feel that this should work! I have done something similar with other data, but there weren't multiple conditions. Please help!
The formula would look something like this (in English) but not sure about ROW part and can't test it properly without some sample data:-
=STDEV.S(IF((A1:A10=INDEX(I1:I10, 2+ROW(1:1)-1))*(D1:D10=1)*(F1:F10 ="BC"),E1:E10))
Have limited it to 10 rows to make debugging easier with 'Evaluate Formula'.
This gives the stdev (sample) of the three shaded cells:-

SUMIFS with intermediate VLOOKUP in the criteria

I have 3 tables, 1 of which I want to fill in columns with data based on the other 2. Tables are roughly structured as follows:
Table 1 (Semi-Static Data)
SubGroup Group
----------- -----------
subgroup(1) group(a)
subgroup(2) group(b)
subgroup(3) group(b)
subgroup(4) group(c)
etc.
Table 2 (Variable Data)
SubGroup DataValue
----------- -----------
subgroup(1) datavalue(i)
subgroup(2) datavalue(ii)
subgroup(3) datavalue(iii)
subgroup(4) datavalue(iv)
etc.
Table 3 (Results)
Group TotalValue
----------- -----------
group(a) totalvalue(m)
group(b) totalvalue(n)
group(c) totalvalue(o)
etc.
Where the TotalValue is the sum of all DataValue's for all subgroups that belong to that particular Group.
e.g. for group(b) ---> totalvalue(n) = datavalue(ii) + datavalue(iii)
I am looking to achieve this calculation without adding any additional columns to the Data tables nor using VBA.
Basically I need to perform a COUNTIFS where there is an additional VLOOKUP matching the subgroup criteria range to the group it belongs to, and then only summing for datavalue's that match the group being evaluated. I have tried using array formulas but I'm having issues making it work. Any assistance would be very appreciated. Thank you,
EDIT: Wanted to add some details surrounding my question. First all Google searches did not provide a suitable answer. All the links had solutions to a slightly different problem were the VLOOKUP term is not dependent on the SUMIFS criteria but rather another single static variable. Stack Overflow offered similar solutions. Please let me know if anymore details are required to make my post suitable for this forum. Thank you again.
You can use the SUMPRODUCT function to do it all at once. The first reference $B$2:$B$5 is for the Group names, the second reference $E$2:$E$5 is for the datavalues. The G2 reference is for the group names in the third table, you can enter this formula for the first reference and then drag and fill for the rest.
=SUMPRODUCT($E$2:$E$5 * (G2 = $B$2:$B$5))
Some cell references, and sample data, would be helpful but something like this might be what you want:
=SUMIF(C:C,"="&INDEX(A:A,MATCH(E5,B:B,0)),D:D)
WADR & IMHO, this is simply bad worksheet design. For lack of a single cross-reference column in Table2, any solution would have to be a VBA User Defined Formula or an overly complicated array formula (the latter of which I am not even sure is possible). The data tables are not normalized database tables you can INNER JOIN or GROUP BY ... HAVING.
The formula you are trying to achieve is akin to,
=SUMPRODUCT(SUMIF(D:D, {"subgroup(2)","subgroup(3)"}, E:E))
That only works with hard-coded values as arrayed constants (e.g. {"subgroup(2)","subgroup(3)"}). I know of no way to spit a dynamic list back into the formula using additional native Excel functions but VBA offers some possibilities.
HOWEVER,
The simple addition of one more column to Table2 with a very basic VLOOKUP reduces all of your problems to a SUMIF.
     
The formula in the new column D, row 2 is,
=VLOOKUP(E2, A:B, 2, FALSE)
The formula in I2 is,
=SUMIF(D:D, H2,F:F )
Fill each down as necessary. Sorry if that is not what you wanted to hear.
Thank you everyone that responded and reviewed this post. I have managed to resolve this using an array formula and some matrix algebra. Please note that I am not using VLOOKUP (this operator cannot be performed on arrays) nor SUMIFS as my title states.
My final formula looks like this:
{=SUM(IF([Table2.xlsx]Sheet1!SubGroup=TRANSPOSE(IF([Table1.xlsx]Sheet1!Group=G2,[Table1.xlsx]Sheet1!SubGroup,"")),[Table2.xlsx]Sheet1!DataValue))}
Very simply, I create an array variable that compares the Group being evaluated (e.g. cell G2) with the Groups column for Table 1 and outputs the corresponding matching SubGroups. This results in an array with as many rows as Table 1 had (N) and 1 column: Nx1. I then transpose that array (1xN) and compare it to the SubGroups column (Mx1, M being the number of rows in Table 2) and output the DataValues column for the rows that have a corresponding SubGroup (MxN). Then I perform a sum of the whole array to return a single value.
Notice that as I didn't include a value_if_false output return on either IF operators, it will just populate with FALSE in the arrays were the conditions are not met. This does not matter though for the final result. In the first IF, FALSE will not match the SubGroups so will be ignored. For the second all values FALSE passed to SUM will be calculated as 0. The more complicated question is that it grows the amount of memory required to process as we are not filtering to just have the values we want.
For this application I decided against filtering the subarray as the trade-off in resource utilization was acceptable. If the data sets were any bigger though, I would definitely try doing it. Another concern was that I did not understand fully the filtering logic that I was using based on http://exceltactics.com/make-filtered-list-sub-arrays-excel-using-small/ so decided to simplify. Will revisit this concept latter as I think it will work. I might have completed this solution but was missing transposing the array to compare properly so abandoned this route.

Resources