I am creating a MS Access database to assign numeric values to various columns in a table using the IIf() Function.
The problem I am having is that the calculation is not providing a numeric value, it appears to be Boolean.
Below is an example code and results:
SMR Ind: IIf([SMR Rating]="N/A",1.5,0) Or IIf([SMR Rating]="B",1.2,0)
If SMR Rating is B, I would like the output to be 1.2 not -1.
Variant 1
IIf([SMR Rating]="N/A", 1.5, IIf([SMR Rating]="B", 1.2, 0))
Variant 2
Switch([SMR Rating]="N/A", 1.5, [SMR Rating]="B", 1.2, True, 0)
Related
Am trying to return the minimum value of cells excluding zero but when ever I do it using this function, it returns a zero not the minimum
Function:{=MIN(IF(DW2:EE2 = 0,"",DW2:EE2))}
The values in the cells are created by a function which is:
=IF(BJ2="",0,IF(BJ2="D1","1",IF(BJ2="D2","2",IF(BJ2="C3","3",IF(BJ2="C4","4",IF(BJ2="C5","5",IF(BJ2="C6","6",IF(BJ2="P7","7",IF(BJ2="P8","8",IF(BJ2>="F9","9"))))))))))
enter image description here
This answer is wrong, but it might give you an idea.
=IF(MIN(A1:A5)=0,SMALL(A1:A5,2),MIN(A1:A5))
This means the following (I'm always working from a list of values in the cells "A1" till "A5"):
Verify the minimum of the list.
2.1. If the minimum equals zero, then
take the second smallest value.
2.2. If the minimum does not equal zero,
then take that minimum.
However, there is one problem with the implementation of that approach: I expected =Small(range,2) to give the second smallest number of a list, which it does, but it does not, let me show you:
Range : 0, 1, 2, 3, 4, 5 => Small(Range,2) = 1 => OK
Range : 0, 1, 2, 3, 4, 0 => Small(Range,2) = 0 => NOK
Apparently, Small(,2) just orders the range, and takes the second element, regardless of the fact that it might be equal to Small(,1).
Does anybody know a solution or workaround for this issue?
Excel
Need to find nearest float in a table, for each integer 0..99
https://www.excel-easy.com/examples/closest-match.html explains a great technique for finding the CLOSEST number from an array to a constant cell.
I need to perform this for many values (specifically, find nearest to a vertical list of integers 0..99 from within a list of floats).
Array formulas don't allow the compare-to value (integers) to change as we move down the list of integers, it treats it like a constant location.
I tried Tables, referring to the integers (works) but the formula from the above web site requires an Array operation (F2, control shift Enter), which are not permitted in Tables. Correction: You can enter the formula, control-enter the array function for one cell, copy the formulas, then insert table. Don't change the search cell reference!
Update:
I can still use array operations, but I manually have to copy the desired function into each 100 target cells. No biggie.
Fixed typo in formula. See end of question for details about "perfection".
Example code:
AI4=some integer
AJ4=MATCH(MIN(ABS(Table[float_column]-AI4)), ABS(Table[float_column]-AI4), 0)
repeat for subsequent integers in AI5...AI103
Example data:
0.1 <= matches 0
0.5
0.95 <= matches 1
1.51 <= matches 2
2.89
Consider the case where target=5, and 4.5, 5.5 exist in the list. One gives -0.5 and the other +0.5. Searching for ABS(-.5) will give the first one. Either one is decent, unless your data is non-monotonic.
This still needs a better solution.
Thanks in advance!
I had another problem, which pushed to a better solution.
Specifically, since the Y values for the X that I am interested in can be at varying distances in X, I will interpolate X between the X point before and after. Ie search for less than or equal, also greater than or equal, interpolate the desired X, then interpolate the Y values.
I could go a step further and interpolate N - 1 to N + 1, which will give cleaner results for noisy data.
Currently writing a program in excel that will return a value based on user input. The current formula has 5 different return options which are returned based on the selection of a number by the user. I use the IF() statement embedded into more IF() statements to account for multiple input options. However, when I go to enter in a number beyond the range of the first IF() statement, I am getting 0 even though it should be a different number.
For the code below, C30 is the input cell and it should return .15 if I was to enter 25.
=IF(C30<20, 0.35, IF(20<C30<40, 0.15, IF(40<C30<60, 0, IF(60<C30<80, -0.1, IF(80<C30, -0.2, 0)))))
From the logic statements, it should be returning .15, but all I am getting is 0.
Excel does not use 20<C30<40 it would be:
AND(20<C30,C30<40)
But you can shorten this with a simple MATCH and CHOOSE:
=CHOOSE(MATCH(C30,{0,20,40,60,80}),0.35,0.15,0,-0.1,-0.2)
If you really want a nested if there is no need for the extra tests:
=IF(C30<20,0.35,IF(C30<40,0.15,IF(C30<60,0,IF(C30<80,-0.1,-0.2))))
IF will resolve sequentially and short circuit as soon as it finds the first TRUE, so it does not need the other logic.
The problem here is the logic that you have used to evaluate whether C30 falls within a range of numbers.
IF(20<C30<40,...) will not check whether C30 is in the range of 20 through 40.
Instead, use AND(cond1, cond2, ...) to check whether the values are within the range:
IF(AND(C30 > 20, C30 < 40), ...)
Replace terms like:
20<C30<40
with:
AND(20<C30,C30<40)
etc.
I have a scale, based on which I decide the value of the coefficient for the multiplication. The scale looks as following:
Which means that:
for Category1: when value>=1.000.000 then coef is 1, when value>=500.000 then coef is 0.8 and etc.
Same logic applies for Category2;
Then I have input data in the following format:
Company !MainCat|Sales Amount|
Company1|T1 | 6.500.000|
Company2|T2 | 70.000|
I need to find corresponding coefficient, ratio of the coeffitient and the value (=ratio*MaxCoef). Currently, I am finding coef the following way:
- for company1:
=IF(C8>=$D2;$D$1;IF(C8>=$E2;$E$1;IF(C8>=$F2;$F$1;IF(C8>=$G2;$G$1;IF(C8>=$H2;$H$1;IF(C8>=$I2;$I$1))))))
That is literally hardcoded and doesn't look good. Maybe there is a better way of doing ? Any suggestions?
Formula view:
You can COUNTIF(range, [criteria] < value) * 0.2 as your add 0.2 per coef stage.
To you data do: =COUNTIF(D2:H2, "<"&C8) * 0.2, count how many stages the value passes * the value per stage.
Your count if range needs to be until H2 as I2 is 0, so inferior to value and gets counted.
To combine the COUNTIF() with a dynamic search for the right category based on MainCat you can MATCH() the MainCat with Code which will give the row where the Code is located and utilize INDIRECT() to apply it as range.
=COUNTIF(INDIRECT("D"&MATCH(B8,B:B,0)&":H"&MATCH(B8,B:B,0)),"<"&C8)*0.2
MATCH(B8,B:B,0) - will match the value on B8 (lets say T1) and return the row 2.
INDIRECT("D"&MATCH(B8,B:B,0)&":H"&MATCH(B8,B:B,0) = INDIRECT("D"&2&":H"&2) - will turn the text into an actual range to be use by the COUNTIF().
Create a table ‚Mapping’ that contains two columns, ‚Category’ and ‚Coefficient‘, then use INDEX-MATCH on it as described in https://www.deskbright.com/excel/using-index-match/.
=INDEX(Mapping[Category]; MATCH([Coefficient]; Mapping[Coefficient]; -1))
This example assumes that you put this formula into a table that has a column named ‚Coefficient‘ with the input value to your multiple IFs.
The trick is that as a match_type argument, provide either -1 or 1, according to your needs.
You can do this in VBA. Write your own function which ends in something like that
=MyOwnScale(C8; B8; A2:I3)
The first parameter of your VBA-function is the value, the second the category and the third is the range with the thresholds. So you can move your cascading IF-loops in VBA-Code and you (and your users) see only a clean function call in the cell.
I'm inexperienced in Excel functions and need some help with the following scenario:
Table I has 2 columns:
X Y
3.2 result
4.7 result
1.2 result
Table II has these columns:
A B C D
1 1.2 0.0 2.3
2 4.1 3.2 0.0
3 0.0 4.7 0.0
I will try to illustrate what I want to do in C++/C#/Java programming syntax:
In Y[1] I want to store:
foreach (int value in TableII) //look for X[1] in Table 2
if( value == X[1] ){ //when you find it,
return A[value.rowNumber]; //return the corresponding value from A
//break;
}
In other words, I want to find X[1] in table II (it will always be there, and always just once), and return the corresponding value from column A[of the same index as the match].
I've looked at HLOOKUP but there's more to it that just one command. Please help.
[EDIT]
I've tried this =INDEX(Column1,IFERROR(MATCH(I2,Column2,0),IFERROR(MATCH(I2,Column3,0),IFERROR(MATCH(I2,Column4,0),IFERROR(MATCH(I2,Column5,0),IFERROR(MATCH(I2,Column6,0),IFERROR(MATCH(I2,Column7,0),IFERROR(MATCH(I2,Column8,0),MATCH(I2,Column9,0)))))))))
But I get the "more levels of nesting than are allowed in the current file format" error. If I remove just one IFERROR(MATCH(I2,Column8,0), then it works. But I need Columns 2 to 9, with Column1 holding the index.
I thought Excel 2007 and 2010 do not have nesting limits any more. What gives?
(For anyone new to Excel reading this, "Column1" etc. are made by selecting the column, right clicking on the selection, and "Define Name".)
[EDIT2]
So I "solved" my nesting problem by dividing the formula into 2 parts, with a +, having the ifs return 0 in case there's no match in either side. This way you either have something + 0 or 0 + something, so it works.
Here's the formula I'm using right now:
=INDEX(Column1, IFERROR(MATCH(I3,Column2,0),IFERROR(MATCH(I3,Column3,0),IFERROR(MATCH(I3,Column4,0),IFERROR(MATCH(I3,Column5,0),IFERROR(MATCH(I3,Column6,0),IFERROR(MATCH(I3,Column7,0),0))))))
+
IFERROR(MATCH(I3,Column8,0),IFERROR(MATCH(I3,Column9,0),0))
)
I've accepted Chris' answer, as he did most of the work, but I would still like to know if my workaround is good practice and if there isn't a shorter/better way to do this.
Thank you.
Here's a possible formula for Y (assumes table I is located in columns G:H)
=INDEX($A:$A,IFERROR(MATCH(G2,$B:$B,0),IFERROR(MATCH(G2,$C:$C,0),MATCH(G2,$D:$D,0))))
Note the IsError function was introduced in Ecel 2007
If your tables are actually defined as excel tables you can use
=INDEX(Table2[Column1],IFERROR(MATCH([#X],Table2[Column2],0),IFERROR(MATCH([#X],Table2[Column3],0),MATCH([#X],Table2[Column4],0))))
(substitute your own table and column names)
If your values are unique, you can use the following formula without having to do any nesting:
=INDEX(column1,SUMPRODUCT((Table2=G24)*ROW(Table2)))