I tried to figure it out by myself and with the internet but I need your help.
I need to check a value is in few ranges and assign in the cell the corresponding value:
* all the numbers are integers
If the value is 0, display 1
if the value between 1 to 3, display 2
if the value between 4 to 6, display 3
if the value between 7 to 10, display 4
if the value is above 10, display 5
Tnx
IF Function
=IF(B2=0,1,if(B2<=3,2,if(B2<=6,3,if(B2<=10,4,5))))
This assumes the value you are checking is in B2 AND that it is a positive integer (ie, no -1 or 1.5)
VLOOKUP Function
=VLOOKUP(B2,$F$2:$G$6,2,1)
B2 value you are checking
F2:G6 is the table of break points (F) and values to be displayed (G)
Build a table with the first column being your break points and a column adjacent to it being the values you want to display. In this case your breakpoints would be 0,3,6,10 and we need to add 11 for the values greater than 10. This method assumes positive values and with the exception of the 11 breakpoint could be used for decimals as well as integers. The current problem is values between 10 and 11 would display as 4 instead of 5.
Two more alternatives if you wanted to do it with a single formula without a separate lookup table:-
=MATCH(A2,{0,1,4,7,11})
=HLOOKUP(A2,{0,1,4,7,11;1,2,3,4,5},2)
Syntax:
=COUNTIFS(Range, "condition1", Range, "condition2")**
Example (finding total numbers lies between 25 to 21 in range J9:J110)
=COUNTIFS(J9:J110, "<=25", J9:J110, ">=21")**
Related
I have a three-column table in Excel, called Table1, like this:
Given two values (one for each input variable), one which must be exactly equal to any of the numbers in the first column (2, 4, 6, or 8) and which must be typed in cell F2, and another one which can be any number between the least (1) and greatest (25) numbers in the second column and which must be typed in cell F3, I want to find the corresponding value in the third column. If the value typed for the second variable is not present in the second column of the table, then the output value of the next row is chosen.
For example, suppose the lookup values are 4 (for the first column) and 10 (for the second column), then the output should be E, since both 4 and 10 are present in the first and second columns, respectively, and the row with the output E corresponds to those values for the inputs.
Another example. Suppose the lookup values are 8 (for the first column) and 17 (for the second column), then the output should be K; it is not J because the latter corresponds to a value of 15 for the second column, which is strictly less than 17; so the output is K because it corresponds to the value that is immediately after (or greater than) 17, being 20.
My attempt
To limit the available values the user can choose, I could create data-validated cells. For choosing the values in the first column, the data validation would by of type list and be equal to 2, 4, 6, 8; such cell would be F2. Like this:
For choosing the values in the second column, the data validation would be of the type whole number, with minimum value of 1 and maximum value of 25. Like this:
Now the formulas for the lookup. After googling, I found out that performing a look-up task with two input criteria is known as a two-way lookup. Using the INDEX and MATCH functions, I managed to perform the two-way lookup, unfortunately the formula only allows exact matches, so it works fine when the first and second input values are 4 and 10, but not when they're 8 and 17. The formula is the following, and it is in cell F4:
{=INDEX(Table1[Output], MATCH($F$2 & "|" & $F$3, Table1[1st input variable] & "|" & Table1[2nd input variable], 0))}
(The presence of curly braces means that we must enter the formula with Ctrl + Shift + Enter instead of just Enter.)
Here's a screenshot for the first successful example:
Here's a screenshot for the second failed example:
I tried changing the third parameter of the MATCH function from 0 to 1, but it returns J (which corresponds to 15 in the second column, but 17 < 15) instead of K (which corresponds to 20, since 17 > 20 and 20 is the closest value to 17 that is immediately after it.)
How can I achieve what I want?
if you have Excel 365 then you can use the new Filter-function:
=INDEX(FILTER(Table1[output],(Table1[1st Input variable]=first)*(Table1[2nd input variable]>=second),"no result"),1)
I named F3 "first" and F4 "second".
FILTER returns all output values where
column A = value from F3
column B >= the value from F4.
INDEX selects the first row of the FILTER-result
Not the best way, but you can round the second input to what you need. In your example, all your values are multiples of 5. Just create an exception for number 1 with an IF.
Here's what I tried:
={INDEX($C$1:$C$12;MATCH(F7&IF(ROUNDUP(G7/5;0)=1;1;ROUNDUP(G7/5;0)*5);$A$1:$A$12&$B$1:$B$12;0))}
Notice it's an array formula.
in row 3, I have an array of data that contains numerical values and text in the form of "n.a.". I would be most appreciative if someone could help me construct a formula that looks across the array and returns the nth non-"n.a." value.
Row 3 beginning in column B: 5, 8, n.a., 7, 6 ,3, 9, 7, n.a., 12
Formula would return 7 if n was set to 3.
Formula would return 12 if n was set to 9.
Thanks in advance.
Treat the bold, italic 3 in the formula as your n value:
=INDEX(3:3,SMALL(INDEX(ISNUMBER(B3:K3)*COLUMN(B3:K3),),3+COUNTA(B3:K3)-COUNT(B3:K3)))
Note that given your example, setting n to 9 will result in a #NUM! error because there are only 8 numbers. Expand the B3:K3 to suit your range, but do not use a whole row reference (using whole row reference would greatly decrease performance time). If preferred, you could create a dynamic named range instead of manually setting the B3:K3 range.
Try
=INDEX(3:3,AGGREGATE(15,6,COLUMN(B3:K3)/ISNUMBER(B3:K3),3))
This formula comes almost directly from God, a.k.a. Scott Craner. The way it works is that any cells which don't contain a number will give a #DIV/0! error in the division. Any cells which do contain a number just give the column in B3:K3. Aggregate with 15,6 works like SMALL but ignores the error cells thus giving you the answer you want.
I am trying to make an average of multiple cells, and I want to ignore to zero cells.
Here is my formula =IFERROR(AVERAGEIF(L4:L10;L12:L18;L20:L26;L28:L34;L36:L37);"") and I don't know where to put the condition to ignore zero "<>0" . Am I doing something wrong?
Assuming you only have positive values and zeroes you can average without zeroes, for non-contiguous ranges using this syntax
=IFERROR(SUM(L4:L10;L12:L18;L20:L26;L28:L34;L36:L37)/INDEX(FREQUENCY((L4:L10;L12:L18;L20:L26;L28:L34;L36:L37);0);2);"")
The FREQUENCY part gives you a two element array, one being the count of zeroes, the other the count of positive values, INDEX then retrieves the second of those (the number of positive values), so if you divide the sum by that count you get the average excluding zeroes. FREQUENCY function (unlike AVERAGEIF) accepts a non contiguous range argument (a "union")
....but if you can identify which rows to exclude by using values in another column then it's easier with AVERAGEIFS, e.g. if on the excluded rows, e.g. in K11, K21, K35 etc. they all have the value "Total" you can use this version:
=IFERROR(AVERAGEIFS(L4:L37;L4:L37;"<>0";K4:K37;"<>Total");"")
adjust depending on the exact text, wildcards are possible
Here is another way using SUMIF and COUNTIF.
Example data:
Values
1
-3
0
5
777
3
0
0
8
text
4
5
6
0
6
7
Formulas:
B18=SUMIF(A2:A17,"<>0",A2:A17)-SUM(A6,A11,A15)
B19=COUNTIF(A2:A5,"<>0")+COUNTIF(A7:A10,"<>0")+COUNTIF(A12:A17,"<>0")
B20=B18/B19
I would like to offset the last entry in my data by one week. For example, I just created this example data:
day value
1 4
2 3
3 5
4 6
5 1
6 3
7 9
8 5
To find the last entry in the dataset, I use the lookup function:
=LOOKUP(9.99E+307,b1:b10)
which will return the value 5. (In case that notation is not familiar, 9.99E+307 is the largest number that can be written in Excel).
I would like then to compare this value to last week's value, and thus offset the last entry by 7. I see that OFFSET asks for: offset(reference,rows,cols) but using:
=OFFSET(LOOKUP(9.99E+307,b1:b10),-7,0)
does not seem to work (it returns an error).
What could be the problem?
#user3561813 has explained why, a solution might be:
=INDEX(B:B,MATCH(1E+100,B:B)-7)
MATCH finds the position (row number) of last entry in ColumnB, -7 steps up seven rows and INDEX finds the content of that row in ColumnB.
You could also use a single LOOKUP function with the "return vector" offset by 7 rows, e.g.
=LOOKUP(9.99E+307,B8:B100,B1:B93)
Why not change the lookup to look for the last day in the list?
This formula will return the last day value (8 in your data above):
=LOOKUP(9.99E+307,A1:A10)
You can then use this formula to return the last value for that day (5 in your data above):
=VLOOKUP(LOOKUP(9.99E+307,A1:A10),A1:B10,2,FALSE)
If you wanted to get the value for 7 days earlier just subtract 7 from the results of the LOOKUP formula like this (will return 4 - day 1 value in your data above):
=VLOOKUP(LOOKUP(9.99E+307,A1:A10)-7,A1:B10,2,FALSE)
The Reference is the OFFSET function refers to a Range object (a cell). The result of your Lookup function is a numeric value, in this case 5. You can't OFFSET a numeric value.
Have you considered using VBA?
I am trying to get the average value(s) of some specific entries. I have two columns: A-which is an index column (it goes e.g. from 1 to 1000) and B which is the values column.
I know there is an AVERAGE function and there is an AVERAGE IF function, which will probably help me but I can't seem to get it working the way I need to.
What I need to do is to get the average value of the entries in column B that match this description for the index in column A: 3 + (3*n) in which n >= 0. In this case I need the average of the values in column B, whose entries in A are 3, 6, 9, 12, 15...
Is it possible to do this with excel or do you think it would be better to write a program to get those values?
Thanks for your tips!!
-Jordi
You can use an "array formula" with AVERAGE function, e.g.
=AVERAGE(IF(MOD(A2:A100,3)=0,IF(A2:A100>0,B2:B100)))
confirmed with CTRL+SHIFT+ENTER
To modify according to your comments in simoco's answer you can use this version
=AVERAGE(IF(MOD(A2:A100-11,3)=0,IF(A2:A100-11>=0,B2:B100)))
That will average for 11, 14, 17, 20 etc.
You can use SUMPRODUCT for this:
=SUMPRODUCT((MOD(A1:A1000,3)=0)*B1:B1000)/MAX(1,SUMPRODUCT(1*(MOD(A1:A1000,3)=0)))
Explanation:
MOD(A1,3) gives you 0 only if value in A1 is in form 3*n
MOD(A1:A1000,3)=0 gives you array of true/false values {FALSE,FALSE,TRUE,FALSE,..}
since False is casts to 0 and TRUE casts to 1 when multipliybg by any value, (MOD(A1:A1000,3)=0)*B1:B1000 returns you array of values in column B where corresponding value in column A is in form 3*n (otherwise zero 0): {0,0,12,0,..}
SUMPRODUCT((MOD(A1:A1000,3)=0)*B1:B1000) gives you a sum of thouse values in column B
SUMPRODUCT(1*(MOD(A1:A1000,3)=0)) gives you number of values in form 3*n in column A
and the last thing: MAX(1,SUMPRODUCT(1*(MOD(A1:A1000,3)=0))) prevent you from #DIV/0! error in case when there is no values in column A in form 3*n
UPD:
in general case, say for rule 11+3*n you could use MOD(A1:A1000-11,3)=0