Does anyone know how to perform a horizontal xlookup - excel

Does anyone know there is a cleaner way to write XLOOKUP formula to perform this lookup function.
The current formula looks like this, it becomes very long if there are many columns to lookup.
=xlookup(H2,$A$1:$A$9,$F$1:$F$9,xlookup(H2,$B$1:$B$9,$F$1:$F$9,xlookup(H2,$C$1:$C$9,$F$1:$F$9,xlookup(H2,$D$1:$D$9,$F$1:$F$9,"",0))))

A horizontal lookup is not the issue here as the function can both lookup a value in a 1D horizontal or vertical range of cells. But you can't use XLOOKUP() to find a value in a 2D-array like that, however; with those numeric case ID's and the use of Microsoft365, you could try:
=MAX(IF(A2:D6=H2,F2:F6))

You may also try-
=INDEX(F1:F9,MAX((A1:D9=H2)*(ROW(A1:D9))))

You could use: =INDEX($F$2:$F$9,SUMPRODUCT(($A$2:$D$9=H2)*ROW($A$2:$D$9)))
Note: This only works if there's only one match.
It checks if $A$2:$D$9=H2 where TRUE = 1 and FALSE = 0. Than multiplies that with the row number of the cell in that range. All FALSE result in 0*row number = 0 where TRUE results in 1*row number = row number.

Related

How to COUNTIFS only the filetered rows with multiple criteria in Excel? [duplicate]

I was researching a way to count the number of zeroes in a column of data, even if the data gets filtered. I found the following solution:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(B2:B18,ROW(B2:B18)-MIN(ROW(B2:B18)),,1)),ISNUMBER(SEARCH("Pear",B2:B18))+0)
Where, B2:B18 is the total list of data and "Pear" is the criteria being counted.
Can someone explain how this formula is accomplishing this task?
Is there a simpler way of doing this?
I was able to determine that:
SUBTOTAL(3,OFFSET(B2:B18,ROW(B2:B18)-MIN(ROW(B2:B18)),,1))
is used to return an array of which cells are visible and hidden in the range. 1 is returned for visible and 0 is returned for hidden.
ISNUMBER(SEARCH("Pear",B2:B18))+0)
is used to return an array of which cells contain "Pear". If "Pear" is found, 1 is returned, else 0.
SUMPRODUCT(arrayofvisiblecells , arrayofcellswithPear)
is used to sum all of the times when the cell is visible AND "Pear" is present. 1*1 else you will be multiplying by a 0.
With Office 365 we can finally get rid of the volatile OFFSET by using BYROW instead:
=SUMPRODUCT(BYROW(B2:B18,LAMBDA(a,SUBTOTAL(3,a))),ISNUMBER(SEARCH("Pear",B2:B18))+0)
The BYROW(B2:B18,LAMBDA(a,SUBTOTAL(3,a))) does the same as SUBTOTAL(3,OFFSET(B2:B18,ROW(B2:B18)-MIN(ROW(B2:B18)),,1)) without being volatile.
=SUMPRODUCT(SUBTOTAL(3,OFFSET(Sheet1!$A$1:$A$1006,ROW(Sheet1!$A$1:$A$1006)-MIN(ROW(Sheet1!$A$1:$A$1006)),,1)),ISNUMBER(SEARCH(B861,Sheet1!$A$1:$A$1006))+0)
B861 is what ever cell you are referencing.

Formula is is resulting to the left

I have a Vlookup with a Match. The Vlookup looks for a country and the match looks for a weight. Each weight for different countries has a different cost.
My formula seems to return the result to the left of what I would expect. So 65kg is returning the cost of 60kg.
This is the code that I have used. I have tried including 1+ in front of D9. I have had False as 0 and I have tried changing the 0's to 1 and -1.
"=VLOOKUP(D8,Express!C2:AU128,MATCH(D9,Express!D3:AU3,0),FALSE)"
Hope this makes sense.
Thank you for any help.
Match returns the relative position in the range. so the fact that the third criterion in the VLOOKUP is 1 based not 0 based you need to start the range in the MATCH with the same column as in the VLOOKUP:
Change Express!D3:AU3 to Express!C3:AU3
=VLOOKUP(D8,Express!C2:AU128,MATCH(D9,Express!C3:AU3,0),FALSE)
Try this formula:
=VLOOKUP(D8,Express!C2:AU128,MATCH(D9,Express!D3:AU3,0)+1,FALSE)

How to simplify a VLOOKUP formula with multiple criteria

I have a VLOOKUP formula which needs to return true or false depending on certain conditions in another worksheet Sheet2.
In Sheet2, a cell can either be blank, contain a zero or a number.
My formula needs to return TRUE if the cell has a number or is blank, and FALSE if the cell contains a zero. I thought the following formula would work, but it's assuming zero is blank and so returns false for both zero and blank cells.
VLOOKUP(C2,Sheet2!$A$2:$J$100,10, FALSE)<>0
I can solve this by using an OR statement, like this:
OR(VLOOKUP(C2,Sheet2!$A$2:$J$100,10, FALSE)<>0,
VLOOKUP(C2,Sheet2!$A$2:$J$100,10, FALSE)= "")
But I want to know if there is a way of doing this which does not require writing out the whole VLOOKUP formula twice. In other words, is there a way to simplify this?
Appreciate the help!
=NOT(LEFT(VLOOKUP(C2,Sheet2!$A$2:$J$100,10, FALSE),8192)="0")
Just compares the left 8192 char of the text string match to "0" and inverts. Although it would work with any number greater than 1, I chose 8192 is because that is the max cell length allowed in excel. Bonus :P
This seems to work:
=IFERROR(--(""&VLOOKUP(C2,Sheet2!$A$2:$J$100,10, FALSE)),1)<>0

Sum + Countifs formula not working

I'm using Google Sheets and am trying to get this formula to work to give the me the following count:
Count when Column T = Kenneth AND Column U = (Pending OR Contacted) AND Column W has a date that falls between the dates shown in B14 and B15.
This is what I have so far:
=sum(countifs(Users!$T:$T,"Kenneth",Users!$U:$U,{"Pending","Contacted"},Users!$W:$W,">"&$B14,Users!$W:$W,"<="&$B15))
This is giving me the correct count for Pending alone but it is ignoring all the Contacted rows so somehow it is not recognizing that OR operator.
COUNTIFS (and SUMIFS) do not support array arguments for the conditions. You will need to resort to summation of COUNTIFS:
=COUNTIFS(Users!$T:$T,"Kenneth",Users!$U:$U,"Pending",Users!$W:$W,">"&$B14,Users!$W:$W,"<="&$B15)+COUNTIFS(Users!$T:$T,"Kenneth",Users!$U:$U,"Contacted",Users!$W:$W,">"&$B14,Users!$W:$W,"<="&$B15)
or a different approach, eg:
=COUNTIF(FILTER(Users!$T:$T,(Users!$U:$U="Pending")+(Users!$U:$U="Contacted"),Users!$W:$W>$B14,Users!$W:$W<=$B15),"Kenneth")
Use arrayformula, you can sum the boolean values multiplied against each other.
=arrayformula(sum((T:T="Kenneth")*(U:U={"Pending","Contacted"})*(W:W>=B14)*(W:W<=B15)))
A boolean true is 1 and a false is 0. Anything multiplied against a zero is zero so all conditions must be true to add another 1 for each row.
        

Excel: VLOOKUP that returns true or false?

In Excel we have the VLOOKUP function that looks for a value in a column in a table and then returns a value from a given column in that table if it finds something. If it doesn't, it produces an error.
Is there a function that just returns true or false depending on if the value was found in a column or not?
You could wrap your VLOOKUP() in an IFERROR()
Edit: before Excel 2007, use =IF(ISERROR()...)
You still have to wrap it in an ISERROR, but you could use MATCH() instead of VLOOKUP():
Returns the relative position of an
item in an array that matches a
specified value in a specified order.
Use MATCH instead of one of the LOOKUP
functions when you need the position
of an item in a range instead of the
item itself.
Here's a complete example, assuming you're looking for the word "key" in a range of cells:
=IF(ISERROR(MATCH("key",A5:A16,FALSE)),"missing","found")
The FALSE is necessary to force an exact match, otherwise it will look for the closest value.
Just use a COUNTIF ! Much faster to write and calculate than the other suggestions.
EDIT:
Say you cell A1 should be 1 if the value of B1 is found in column C and otherwise it should be 2. How would you do that?
I would say if the value of B1 is found in column C, then A1 will be positive, otherwise it will be 0. Thats easily done with formula: =COUNTIF($C$1:$C$15,B1), which means: count the cells in range C1:C15 which are equal to B1.
You can combine COUNTIF with VLOOKUP and IF, and that's MUCH faster than using 2 lookups + ISNA. IF(COUNTIF(..)>0,LOOKUP(..),"Not found")
A bit of Googling will bring you tons of examples.
We've always used an
if(iserror(vlookup,"n/a",vlookup))
Excel 2007 introduced IfError which allows you to do the vlookup and add output in case of error, but that doesn't help you with 2003...
You can use:
=IF(ISERROR(VLOOKUP(lookup value,table array,column no,FALSE)),"FALSE","TRUE")
ISNA is the best function to use. I just did. I wanted all cells whose value was NOT in an array to conditionally format to a certain color.
=ISNA(VLOOKUP($A2,Sheet1!$A:$D,2,FALSE))

Resources