Excel IF statement Not returning the appropriate Value - excel

I'm trying to grade students by giving them A or B depending on their score. If someone is having absent instead of a score, I return a value of the cell.
However, it does not return the value of the cell. The reference records are in a separate sheet called raw. I think it may be because I'm trying to return a string data.
I am using Excel 2007. Here's the formula:
=IF(raw!E6>=75,"AA",IF(raw!E6>=70,"AB",IF(raw!E6>=60,"B",IF(raw!E6>=50,"C",IF(raw!E6>=40,"D",IF(raw!E6<40,"RT",raw!E6))))))

Don't use Nested IFs if you can avoid it. Instead, use a banded VLOOKUP: it's many times more efficient, and a heck of a lot simpler to troubleshoot. Something like this:
=IF(ISNUMBER([#Score]),VLOOKUP([#Score],Table1,2,TRUE),"Absent")
Notes:
The above uses Tables and the associated Table Notation. I always use
Tables when I can, because they reduce spreadsheet administration and
the Structured Table References have intrinsic meaning.
The VLOOKUP must have TRUE as the forth argument, and the lookup
table must be sorted in ascending order.
The lowest score must be zero, so that anything below 40 gets a "Retake" grade.

Depending on whether or not the students' scores are in whole percentage figures (i.e. 75, 63, etc), you could use the INT-function to force interpretation of the input field as an integer (not that it always round down a score, which I suppose seem to be ok with the nested if-structure you're using here. Your function would then be:
=IF(INT(raw!E6>=75),"AA",IF(INT(raw!E6)>=70,"AB",IF(INT(raw!E6)>=60,"B",IF(INT(raw!E6)>=50,"C",IF(INT(raw!E6)>=40,"D",IF(INT(raw!E6)<40,"RT",raw!E6))))))

you just need to change you last IF condition (raw!E6<40,"RT) because excel will give RT to all the score which is below 40 so add a and condition like if raw!E6>0 , this should resolve your work
if(and(raw!E6<40mraw!E6>0),"RT,raw!E6)
Hope this helps

Related

Excel formula to sum an array of items from a lookup list

I'm trying to make my monthly transaction spreadsheet less work-intensive but I'm running up against problems outputting my category lookups as an array. Right now I have a table with all my monthly transactions and I want to create another table with monthly running totals. What I've been doing is manually summing each entry from each category, but I'd love to automate the process. Here's what I have:
=SUM(INDEX(Transactions[Out], N(IF(1,MATCH(I12,Transactions[Category],FALSE)))))
I've also tried using AGGREGATE in place of SUM but it still only returns the first value in the category. The N(IF()) was supposed to force INDEX to return all the matches as an array, but it's not working. I found that trick online, with no explanation of why it works, so I really don't know how to fix it. Any ideas?
Just in case anyone ever looks at this thread in the future, I was able to find a simpler solution to my problem once I implemented the Transactions[Category]=I12 method. SUM, itself will take an array as an argument, so all I had to do was form an array of the values I wanted to keep from Transactions[Out] range. I did this by adjusting the method Ron described above, but instead of using 1/(Transactions[Category]=I12 I used 1/IF(Transactions[Category]=I12, 1,1000) and surrounded that by a FLOOR(*resulting array*, .01) which rounded all the thousandth's down to zero and didn't yield any #DIV/0! errors.
Then! I realized that the simplest way to get the actual numbers I wanted, rather than messing with INDEX or AGGREGATE, was to multiply the range Transactions[Out] by the binary array from the IF test. Since the range is a table, I know they will always be the same size. And SUM automatically multiplies element by element and then adds for operations like this.
(The result is a "CSE" formula, which I guess isn't everyone's favorite. I'm still not 100% clear on what it means: just that it outputs data in a single cell, rather than over multiple cells. But in this context, SUM should only output a single number, so I'm not sure why I need CSE... A problem for another day!)
In your IF, the value_if_true clause needs to return an array of the desired row numbers from the array.
MATCH does not return an array of values; it only returns a single value which, with the FALSE parameter, will be the first value. That's why INDEX is only returning the first value.
One way to return an array of values:
Transactions[Category]=I12
will return an array of {TRUE,FALSE,FALSE,TRUE,...} depending on if it matches.
You can then multiply that by the Row number to get the relevant row on the worksheet.
Since you are using a table, to obtain the row number in the data body array, you have to subtract the row number of the Header row.
But now we are going to have an array which includes 0's for the non-matching entries, which is not good for us as a row number argument for the INDEX function.
So we get rid of that by using the AGGREGATE function with the ignore errors argument set after we do change the equality test to 1/(Transactions[Category]=I12) which will create DIV/0 errors for the non-matchers.
Putting it all together
=SUM(INDEX(Transactions[Out],AGGREGATE(15,6,1/(Transactions[Category]=I12)*ROW(Transactions)-ROW(Transactions[#Headers]),ROW(INDIRECT("1:"&COUNTIF(Transactions[Category],$I$12))))))
You may need to enter this with CSE depending on your version of Excel.
Also, if you have a lot of these formulas, you may want to change the k argument for AGGREGATE to use the INDEX function (non-volatile) instead of the volatile INDIRECT function.
=SUM(INDEX(Transactions[Out],AGGREGATE(15,6,1/(Transactions[Category]=I12)*ROW(Transactions)-ROW(Transactions[#Headers]),ROW(INDEX($A:$A,1,1):INDEX($A:$A,COUNTIF(Transactions[Category],$I$12),1)))))
Edit
If you have Excel/O365 with dynamic arrays and the FILTER function, you can greatly simplify the above to the normally entered:
=SUM(FILTER(Transactions[Out],Transactions[Category]=I12))

Finding the right range from excel table

What is the best way to find the right column for the travelled miles using visual basic coding or some excel function and return the price from that column? HLOOKUP can't be used here because the lookup value isn't exact and the ranges in the table are also not with specific intervals (If they were, I could use e.g. FLOOR(travelled miles/100)*100 and find the price with HLOOKUP). Obviously, it's easy to find the price manually with a small table but with a big table computer will be faster.
Note that, if x is between a and b, then MEDIAN(x,a,b)=x. Combine this with some nested IFs:
=IF(MEDIAN(B5,B1,C1-1)=B5,B2,IF(MEDIAN(B5,C1,D1-1)=B5,C2,IF(MEDIAN(B5,D1,E1-1)=B5,D2)))
I'm on my phone, so just done the first three cases, but hopefully you can see how it continues.
(should note you need to remove the dashes for this to work)
Edit:
I also want to answer your question in the comments above. You can use the following to keep the dash, but get a number to work with.
Assume cell A1 has got the value 10-. We can use the FIND function to work out where the - occurs and then use the LEFT function to only return the characters from before the dash:
=LEFT(A1,FIND("-",A1)-1)
This will return the value 10, but it will return it as a string, not a number - basically Excel will think it is text. To force Excel to consider it as a number, we can simply multiply the value by one. Our formula above therefore becomes:
=(LEFT(A1,FIND("-",A1)-1))*1
You may also see people use a double minus sign, like this:
=--LEFT(A1,FIND("-",A1)-1)
I don't recommend this because it's a bit complex, but combining with the formula above would give:
=IF(MEDIAN(B5,--LEFT(B1,FIND("-",B1)-1),--LEFT(C1,FIND("-",C1)-1)-1)=B5,B2,IF(MEDIAN(B5,--LEFT(C1,FIND("-",C1)-1,--LEFT(D1,FIND("-",D1)-1-1)=B5,C2,IF(MEDIAN(B5,--LEFT(D1,FIND("-",D1)-1,--LEFT(E1,FIND("-",E1)-1-1)=B5,D2)))

NetSuite saved search filter records with min quantity

How do I apply following requirement in Saved Search criteria?
Filter all inventory items
Where min( {memberitem.quantityavailable} / {memberquantity} ) <> custitem_quantity
Note: custitem_quantity is a custom numeric field.
Note2: NetSuite is throwing error when I use min function in filters.
There is more than one issue here.
You have to be careful with custom numerics in Netsuite.
When your inner condition evaluates, it does not have the same type because it is fractional. At some point it has to be rounded and / or truncated internally. The other side of the expression would need to call a floor or ceiling function to remove everthing past the decimal.
Also, the min function evaluates after the <> conditional, which will be dependent upon whether your custom numeric is type compatible to begin with.
In the expression you provided us, it would have to be an exact match (and an exact type), and that is before you consider whether MIN gets to be evaluated.
Look at how the datatypes are cast and what columns you are processing because memberitem.quantityavailable may need a secondary index depending upon your dependencies and where the formula is being called. If this formula is being used over multiple products, it may not be logically consistent.
When I have similar items in inventory that I want to generate stats for I try to process it separately, even if I have to make a second pass.
What are you trying to isolate exactly - - I cannot think of a quantity-related situation where there would be a need to use division in this way - - please refer to the formula Mike Robbins listed above for a properly structured evaluation and see if it achieves the desired result.
If you post the rest of your code, I will help you resolve this.
The entire expression is not valid and will not evaluate due to the conditional shown, the MIN, nor the division. Index the count on the memberquantity if you are looking to sum over values. Otherwise, CountIF will work for quantities. MIN will only finds the lowest value in a given column, so SumIF appears to be what you are after. You can create a second expression which bounds the values you are searching for as a preliminary step.
I am new here, so please elaborate on what you are trying to accomplish so I can earn the bounty.
You may want to take into account null values as well to avoid errors or inconsistent data.
If you're using formula numeric, try this:
Formula(Numeric):
case when min((NVL({memberitem.quantityavailable},0) / NVL({memberquantity},0)) - (NVL{custitem_quantity},0)) then 1 else 0 end
'IS EQUAL TO' 1
I believe you can use the Formula Text or Formula Numeric Search Filter for that.

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.

Excel Serial If statements

I'm new to Excel, and I'm struggling with a formula. Essentially, what I'm looking for is to filter a cell through a set of procedures using a formula (this part isn't strict).
For example
Let's say I have a cell, A1. I'm trying to perform different calculations on this based on whether it is between a certain range of values. The problem is, it can be within several ranges.
Pseudo-Code representation
If(A1 > 187.5) {
// Run some code here.
}
If(A1 > 150) {
// Run some code here.
}
NOTE : The above example is only to illustrate the logic of sequential if statements.
Note that I Do not want a nested If statement. I'm just trying to run the same value through various checks. How do I do this in an Excel formula?
The best I can come up with is something like the following.
=(A1>187.5)*<some expression>+(A1>150)*<some expression>+....
The result of this will be some single value. (The straightforward way to get multiple values is to have the individual terms in separate cell.
If you want the result to reflect one among several mutually exclusive outcomes, then you would want to go with:
=(A1>187.5)*<some expression>+(A1>150)*(A1<=187.5)*...etc.
There are many ways to achieve this. One way is to use nested conditions like this:
=IF(Something, do something, IF(something else, do something, do something))
This is good if you want to condensate the formula a bit but arguably leads to more cluttered formulas. According to the FAST-Standard organization, those cases of nested conditions should be replaced by the use of flags. The most simple case would be, for example, where you would be looking for a rebate percentage according to a sales amount. In multiple cells you would have IF conditions evaluating to true only if the value matches that specific range. Then, your formula can be as simple as a SUMPRODUCT of your flags with your rebates percentages.
This is one example, but it can be applied to other cases very well too.
if there is a relationship between the numbers your checking for its very likely you can use
=CHOOSE(FLOOR(A1/160,1)+1,"<160",">160")
Which would put your 150 in the first and leave your 185 in the second

Resources