in column A first value is 0, second is 0, third is 17, fourth is 0 and fifth is 32
in this case , first non zero value is 17. how to calculate it by formula
In cell B1:
=INDEX(A1:A5,MATCH(TRUE,INDEX(A1:A5<>0,),0))
Explanation for the above formula:
The inner Index function evaluates the values in the A1:A5 range to either TRUE or FALSE based on the specified condition, that is, not equal to 0. So 17 and 32 evaluate to TRUE, everything else to FALSE. The Match function returns the row number where the first instance of the specified condition TRUE is. This occurs on the 3rd row of the range, so Match evaluates to 3. Finally, the outer Index functions returns the value at row number 3 in the specified A1:A5 range, which is 17.
Related
Why does this hlookup function return 0?
A1 = 2, B1 = 0, C1 = 0
=hlookup(3,A1:C1,1,true)
Reading the description here: https://support.microsoft.com/en-us/office/hlookup-function-a3034eec-b719-4ba3-bb65-e1ad662ed95f, it says for the range parameter (the last parameter):
"If TRUE or omitted, an approximate match is returned. In other words, if an exact match is not found, the next largest value that is less than lookup_value is returned"
The next largest value is 2 (in A1) which is less than the lookup value (3).
Using MS Office 365 Apps for enterprise
HLOOKUP will require that the values be sorted when using TRUE:
https://support.microsoft.com/en-us/office/hlookup-function-a3034eec-b719-4ba3-bb65-e1ad662ed95f#:~:text=If%20range_lookup%20is%20TRUE%2C%20the%20values%20in%20the%20first%20row%20of%20table_array%20must%20be%20placed%20in%20ascending%20order
But we can use MAXIFS if they are numbers:
=MAXIFS(A1:C1,A1:C1,"<="&3)
OR XLOOKUP which does not care if sorted or not.
=XLOOKUP(3,A1:C1,A1:C1,"",-1)
The HLOOKUP function returns 0 because the value 3 is not found in the lookup range A1:A3. The HLOOKUP function performs a horizontal search, i.e., it searches for the lookup value vertically in the first row of the lookup range.
Since the lookup value 3 is not found in the range A1:A3, which only contains the values 2, 0, and 0, the HLOOKUP function returns the value specified in the result_vector argument, which in this case is 1. When the value is not found and the range_lookup argument is set to True (which it is in this case), the HLOOKUP function returns the closest match that is less than the lookup value. In this case, since there is no match, it returns 0.
I have an Excel workbook with 1, 4, 0, 100, 0, 0 distributed across the range A1 to A6.
A formula =LOOKUP(2,1/(A1:A6<>0),A1:A6) returns me the last non-zero element in that range: 100 in this case. It's clever enough to step over the 0 between 4 and 100.
It's not my workbook and can't reach the author.
But how does the formula work?
First, the 2 can be any number greater than 1 and work.
The (A1:A6<>0) is returning TRUE/FALSE which when being used as a denominator turns to 1/0 respectively.
So the 1/(A1:A6<>0) returns an array of 1s and #DIV0 error. For your instance: {1,1,#DIV0,1,#DIV0,#DIV0}
The Lookup looks for best fit, as in where the 2 is greater than the value in the array but less than the next or the last number in the array. So it finds the last 1 in the returned array.
It then uses that relative position 4 to return the forth value in the third criterion range: the value in A4 in this case.
May I know what is the meaning of this formula used in one of my worksheet:
=IF(COUNTA(INDIRECT(F3))-3<0,1,COUNTA(INDIRECT(F3))-3)
INDIRECT(F3) takes the contents of cell F3 and uses it as a Range value.
COUNTA counts the number of non-empty cells in the range
The IF function evaluates the boolean expression in the first parameter. If it evaluates to True, it returns the result of the expression in the second parameter. If the first paramater evaluates to False,
So this formula looks at the range specified in F3 and counts the number of cells that are not empty. If that count minus 3 is less than 0 then it returns 1. Otherwise it returns the count minus 3.
I have a row of values - 1,2,3,8,35,7,8,3,5,7,x
X is where I want the formula to be
I'd like to somehow get the value of the row which 8 is the closest to X (so not row 4 in this case, but row 7)
If I use match("8",A:A,0) I get the first match it finds.
How do I find the closest match to the cell where the calculation occurs?
You may use:
{=MATCH(2,1/(A1:A10=8))}
just remember it is an array function, so CTRL+SHIFT+ENTER must be used
The answer is based on a trick and behaviour of the MATCH function. I will allow myself to copy the explanation from ozgrid:
The magic here is actually in the MATCH function more than the array. Two interesting properties of the match function are being used here:
1) With MATCH, if no match is found, then the function will return the position of the last value in the array, so if you did =MATCH(8,{1,2,3,4,5,6,7,6,5,4,3,2,1}), your result is = 13, since there was no 8 to find in the array
2) MATCH will return the position of the last value, but won't return the position of an error (or of a blank value), so if you have =MATCH(8,{1,2,3,4,#DIV/0!,#DIV/0!,7,6,5,4,3,#DIV/0!,#DIV/0!}), your result is = 11, as the 3 in the 11th position is the last value in the array
So daddylonglegs' formula checks each cell against the target value with (A1:A13=B1) in the array formula, giving an array with TRUE (or 1) for the positions where the cells match, and with FALSE (or 0) for the rest. Dividing 1 by this results in 1s wherever that array was TRUE, and #DIV/0! wherever that array was false. So his formula is evaluated as
=MATCH(2,{#DIV/0!,1,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,1,#DIV/0!,1,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!})
Since no '2' is found in the array, and the last value (1) is found in the 9th position, the MATCH returns 9
If you want the last match you can use this formula in A11
=MATCH(2,INDEX(1/(A1:A10=8),0))
[Note: if the values are numeric then 8 is OK - if they are text formatted numbers then you need "8"]
....or do you have values either side of the calculation cell (so nearest might be up or down)?
Here is the array I have:
{=MIN(IF('APRIL 2011'!E3:E999<>"",'APRIL 2011'!E3:E999
*('APRIL 2011'!E3:E999*('APRIL 2011'!D3:D999='APRIL TOTALS'!A2))))}
It still returns zeroes with empty cells!
You can use the ISBLANK() function to test for blank cells. IF cell A1 is blank, then =A1="" evaluates to true, and so does =A1=0
I don't know of an expression to return a blank value to a cell, so I use "" instead, like this:
=IF(ISBLANK([expression]), "", [expression])
Nest your conditions. You are trying to mashup IF criteria with (VALUE)*(TRUE/FALSE) and the when the TRUE/FALSE is FALSE, you are multiplying by zero. In this way, you are discarding blank cells but artificially seeding your result set with zeroes for every row where column D <> 'APRIL TOTALS'!A2.
As an array formula,
=MIN(IF('APRIL 2011'!E3:E999<>"", IF('APRIL 2011'!D3:D999='APRIL TOTALS'!A2, 'APRIL 2011'!E3:E999)))
Array formulas need to be finalized with Ctrl+Shift+Enter↵ (but you already knew that!).
The issue with your formula is that you are returning the minimum of an array of Boolean products. Because these are Boolean products, products with a FALSE multiplier (the ones you intend to exclude) are counted as 0.
I see a way around this as long as Column E contains no zero values. I've made two big changes to your original formula:
To remove the Boolean multiplier problem, I've used an IF statement to choose multipliers instead of 1 and 0 for TRUE and FALSE. TRUE is still 1, but FALSE is now a large number -- make it larger than any value in Column E. This way, the blank entries will only be the minimum value if they are the only value.
To take care of the case where the large number will be returned, I've made it such that the Minimum value is calculated only if there are non-blank values in Col E for Col D values = A2. If there are no such values, "" is returned.
{=IF(COUNT(IF('APRIL 2011'!D3:D999='APRIL TOTALS'!A2,
IF('APRIL2011'!E3:E999<>"",'APRIL2011'!D3:D999)))=0,""
MIN(IF('APRIL2011'!E3:E999<>"",'APRIL2011'!E3:E999,10000000000)
*IF('APRIL 2011'!D3:D999='APRIL TOTALS'!A2,1,1000000000000)))}