Excel - Conditional row from an array to COUNTIF from VLOOKUP - excel

I don't know if I'm going about this the wrong way but it seems like it should be simple. Column A has a list of Names. Along each row is several "W"'s. Another separate field has a drop down representing Column A names. I want to count the number of "W"'s in a row corresponding to what name I select. I've tried using VLOOKUP and COUNTIF but I can't figure out how to select the entire array and then single out the one row that matches my selected name. I can get it working with a bunch of IF statements but thats far too time consuming as I'm manually matching the name to the row (and it isn't future proof).

There are a few ways to first 'narrow in' on the row you're looking for, after which point you can use a simple COUNTIFS to check the number of W's in that row.
One method would be to simply use INDIRECT, and create the row reference on the fly, like so [assumes your search cell is C1]:
=COUNTIFS(INDIRECT(MATCH(C1,A:A,0)&":"&MATCH(C1,A:A,0)),"W")
This first uses MATCH to find the appropriate row, and then builds a reference to that row [like "24:24"], which becomes the row that INDIRECT passes to COUNTIFS, which counts that row for W's.
For only one use of INDIRECT, the high computing costs of INDIRECT should not be an issue.
Another method would be to point out the full possible box that data could be contained in [let's assume that at most only column H would be used], and then use INDEX to give us the appropriate row number, like so:
=COUNTIFS(INDEX(A:H,MATCH(C1,A:A,0)),0,"W")
This again uses MATCH to find the row which contains the value found in C1 within column A. Then it takes the full possible box from INDEX, and returns all columns from the particular row [note that telling index to return 0 for the column # actually returns all columns instead].
Other methods would be possible [for example OFFSET], but I believe these two show the principle fairly well.

You could use the "Helper" Column method:
In the helper column:
=COUNTIF(B2:H2,"W")
Then use SUMIF() in the totals column:
=SUMIF($A$2:$A$9,K2,$I$2:$I$9)

Related

Excel - looking for coincidence of two different values in two different columns and extract another column

I am trying to extract the value like what we can do with vlookup, but in this case it has to coincide with the value on two different columns.
I want to extract the values which match with the two columns in yellow.
Sheet1 (where I am looking for coincidence of two values)
For that I am using the formula IF(COUNTIFS(....)=1;"value that I am looking for"; no match)
But I donĀ“t know what to put on "value that I am looking for", because if I add directly the cell from the row, it delivers directly a wrong value.
Sheet2 (where I want to add these two values, and formula that I am testing)
If you have O365, you can use a combination of INDEX and FILTER function to do this
=INDEX(FILTER('Sheet 1'!$A$2:$E$10,('Sheet 1'!$A$2:$A$10='Sheet 2'!$B192)*('Sheet 1'!$E$2:$E$10='Sheet 2'!$C192),""),1,2)
You need to update the 'Sheet 1'!$A$2:$E$10 range according to your data.
Also note that this will return the 1st match of both Partner object and Value in Obj. Crcy row, even if there are multiple matches
Edit:
As suggested by #P.b in the comments below, you can also use:
=#FILTER('Sheet 1'!$B$2:$B$10,('Sheet 1'!$A$2:$A$10='Sheet 2'!$B192)*('Sheet 1'!$E$2:$E$10='Sheet 2'!$C192),"")

Given an array, how can I index match each value and sum them without a helper column?

I have multiple rows 34 columns wide with a reference Designator(RefDes) in each one that correlates to a value. I am trying to find a way to match each RefDes to its value and sum those together without the use of a helper cell for each column to give each row a total value.
My current formula will work with a helper cell but that adds 34 more columns and makes it very messy and hard to read.
=INDEX(FullFlow2[[Category Times]:[Category Times]],MATCH(N4,FullFlow2[[REFDES]:[REFDES]]))
Followed by a =sumproduct()in another column to collect the values.
Not sure if this is something I will need to use VBA for or if I can make it work without it.
This is the RefDesTable below
This is the FullFlow2 Table below
Use SUMIFS wrapped in a SUMPRODUCT:
=SUMPRODUCT(SUMIFS(FullFlow2[[Category Times]:[Category Times]],FullFlow2[[REFDES]:[REFDES]],YourFirstTableName[1st]))
Replace YourFirstTableName with the correct name for the table.

Excel - Retrieving a cell based off of multiple criteria

I am attempting to return the value of a cell from within a different sheet based upon two cell values in the second sheet.
As an example the Main and Second sheet have three columns each (Item, Code, Number), the difference being that the second sheet has only one row and two drop down lists that are populated with the Item(s) and Code(s) (from the Main sheet - i.e like a database table). From within the Second sheet I would like the Number to be returned from the main sheet, once the Item and Code had been selected from the drop down lists on the Second sheet.
Unfortunately I'm unsure as how to do this based off of multiple criteria. As far as I'm aware VLOOKUP only used one criteria over a range. I've attempted the following below which is accepted by Excel as a valid formula, however it doesn't return the correct value.
{=SUMPRODUCT((Main!A:A='Second'!A7) * (Main!C:C='Second'!E2) * (Main!G:G))}
I've interpreted the above as the first two sets of brackets being the range and condition to match and the last set being the range of values to return from. Is this a correct assumption and is this the correct use of that function?
Are there any other functions I could use?
Thank you, I have very little experience with Excel!
Have you taken a look at the magic INDEX combined with MATCH, and perhaps MATCH again?
INDEX returns the contents of a cell from a table provided a row and a column. Usage:
=INDEX([table to look in]; [COLUMN index]; [ROW index])
MATCH returns the indexes that match a criteria in the table. Usage:
=MATCH([Criteria];[table to look in])
And you can nest one inside the other the following way:
=INDEX([table to look for in];MATCH([Criteria];[Table to look for the particular Row]);[COLUMN, or a second MATCH to find the right column])
Or even combine a couple of MATCH as in
=INDEX([table to look for in];AND(MATCH(1);MATCH(2)); [Column to look for, or MATCH to look for in column])
Which I think is what you want.
If you need a SUM of something (as you used a SUM function before), just nest it inside the proper SUM function

Excel: Vlookup in named range and return a value outside of range

I need to find a way to search for a value in a named range and to return the column next to that range. The reason is simple: I do use list validation with a named range in column A. In this list there are complete name of product types (ex. Relay, Contactor, Enclosure) and I need to return a short description from column B (ex. Rly, Cont, Encl) so that when the user searches the list it's easy to find what he is looking for. I know I could extend my range to $A:$B but if I do then all the values of $B will be included in the list...
This shows a way to figure out what I need: =VLOOKUP(A1;"RANGE+1C",2,0)
I tried so many ways with offset and index but couldn't find a way to do so... I even thought it would be possible of doing it with relative reference (ex. =VLOOKUP(A1,Description;1"RC[1]",0) or something like that...
Also looked in Google to find some info but it seems to be something very unfamiliar...
I need to do this in a formula and not in VBA.
Here is the link to an example file:
http://www.filedropper.com/descriptionbuilder
Any hint?
Thank you!
What you probably want instead of VLOOKUP is the MATCH & INDEX combo.
MATCH is a function which tells you the row number where a duplicate value is found from your selected list - it's like half of VLOOKUP. INDEX is a function which pulls a value out of a list, based on its position # that you give it - it's like the other half of VLOOKUP.
I see your one Range in column A with your ID data is Description - I'll assume that column B has no 'named' range that aligns with yours. I'll assume that column B has other data, and that column A starts somewhere after row one [specifically, I'll assume it starts at row 5]. Together the formula would look like this:
=INDEX(B:B,ROW(A5)-1+MATCH(A1,Description,0))
This says: find the row # within Description that matches the text in A1. Then add the row # of A5 - 1 (this then alignts the top of Description with the top of column B). Then pull that value from column B.
Alternative Method using VLOOKUP and OFFSET
Another method would be to first define how many rows are in Description, and then using that information and the OFFSET function, create a new area which essentially represents Description but going across column A & B instead of just column A. This would look as follows (again, assuming Description starts at A5):
=VLOOKUP(A1,OFFSET(A5,0,0,ROWS(Description),2),2,0)
This says: count how many rows are in Description. Build an array with OFFSET which starts at A5, with as many rows as there are in Description, and 2 columns. (So with 3 items in Description, this would be A5:B7). Then use that new Range in VLOOKUP, and try to find A1 the Description area in column A, and return the result from that row in column B.
You can use Offset to expand a named range by one column and then feed it into Vlookup Something like:
=VLOOKUP(C1,OFFSET(RANGE,0,0,,1+COLUMNS(RANGE)),1+COLUMNS(RANGE))
To test is, I created a named range (called "RANGE") in Column A, I placed values in Column B adjacent to the named range, put a lookup value in C1 and the entered the above formula. It succeeds in retrieving the desired value.
On edit: I think that Grade'Eh'Bacon's answer is excellent and is probably the best approach to this specific problem, but it strikes me as potentially useful to know how to expand the reference of a named range without changing the name itself, so I am keeping this answer.

I have multiple IDs for items, how can I use VLOOKUP to scan next column if it doesnt find it in the first?

Imagine my dataset has multiple IDs in columns, for the same item. How can I use VLOOKUP to scan the next column in the order up until it finds the same ID in another dataset? Or if it does not exist just stop searching after 6 columns? Thanks!
You could do this with 6 nested IFERROR statements; that would look like this: (Assuming your ID columns are A->F, your results column is G, and your search term is in J1):
=IFERROR(IFERROR(IFERROR(IFERROR(IFERROR(VLOOKUP(J1,A:G,7,0),VLOOKUP(J1,B:G,6,0)),VLOOKUP(J1,C:G,5,0)),VLOOKUP(J1,D:G,4,0)),VLOOKUP(J1,E:G,3,0)),VLOOKUP(J1,F:G,2,0))
This looks at each column (starting with F and working outwards), and if it can't find a match, it creates an error, so goes to the next column. It is not very clean to read. A better way using this same methodology could be to use a combination of INDEX & MATCH, like so:
=INDEX(G:G,IFERROR(IFERROR(IFERROR(IFERROR(IFERROR(MATCH(J1,A:A,0),MATCH(J1,B:B,0)),MATCH(J1,C:C,0)),MATCH(J1,D:D,0)),MATCH(J1,E:E,0)),MATCH(J1,F:F,0))
Though this is a little shorter [because we don't need to specify the entire block of data, or which column to pull from, as it always pulls from column G], it is still not very readable.
Let's try this instead using an Array Formula which runs the same function multiple times over many cells, gets the result for each cell, and provides an array of results. Then we just need to collapse that array into a single value, like so:
=INDEX(G1:G14,MIN(IFERROR(IF(SEARCH(J1,A1:A14&B1:B14&C1:C14&D1:D14&E1:E14&F1:F14)>0,ROW(A1:A14),""),"")))
Confirm this formula with CTRL + SHIFT + ENTER instead of just ENTER. This adds all strings of all search columns together, basically making a single column of values. It then takes that column, and searches each cell for the word found in J1. If it finds it, it returns that row number, otherwise it returns "". The function then uses MIN to take the lowest row number found (to tie-break to the earliest row, if there is a duplicate), and then uses that with INDEX to return the value from that row in column G.
Note that the logic here is a little different from the options I gave above, as it defaults to the earliest row #, rather than the earliest column #, of a match.

Resources