I'm trying to do something in Excel without using VBA macros. I suspect it is possible, but have some up empty so far. Basically for values in a table, I'd like to retrieve a list of all values in Column A conditionally where Column B equals a value I provide.
For example I'd like a function that essentially returns a range/description of cells for Column A if Column B is equal to zero.
Column A Column B
1 0
2 0
3 1
4 0
would return a range describing cells a2, a3, and a5 (1, 2, 4). I'd prefer to be able to do this using a formula, and not manually using pivot tables. I would be willing to create a view of the data using pivot tables if that table could then be referenced via a function to give me the appropriate results. I am also able to sort Column B in any way if it makes it easier to do this.
Ultimately I need to pull out a random value from Column A that meet the criteria of Column B in case that matters in the final solution.
Thanks.
Use an array formula.
Type in:
=INDEX($A$1:$A$4,SMALL(IF($C$1=$B$1:$B$4,ROW($B$1:$B$4)),ROW(1:1)),1)
then press Ctrl+Shift+Enter. Drag and fill the cells below until #NUM! shows up. This formula assumes the value you're looking for is in C1 and there are no headers (data starts in 1st row rather than 2nd).
Related
I have a Table in excel like the following one:
col1 col2
A 1
B 0
A 2
B 2
B 3
I was not able to find a way to select a subset of the table like this one using an excel function.
col11 col22
B 0
B 2
B 3
based on the value "B" of column col1 or just be able to select the col22' from the given subset.
I would like to have a solution that does not require to VBA nor array formula. I found on Internet the function FILTER, but it is not available yet and Structured References does not have such functionality.
I would like to use for example the result col22 as a column at another place of my spreadsheet. Other languages such as R, provide a function subset that does this in a pretty simple way. In excel it is really easy to filter using the Excel interface (filter button), but I am not aware of a function that does something similar programatically.
I had the same problem and the only thing I found on the internet was the FILTER function too.
I wanted to vlookup a subset of a table based on another column. My solution was to make another column that is the concatenation of the two. Then I used vlookup on this column.
I don't know what are you going to do with the subset table that you want to have. But you can do it in a different way as I did. May it helps.
Assuming col1 is A and col 2 is B and your result set's col1 and col2 are E and F respectively, try this formula in column C: =IF(A2=$E$2,MAX($C$1:C1)+1,0)
Now, in cell E2 (i left the first row for a header), i physically typed "B" to make this the input source and allowing for dynamic reporting. for as many cells below that as you wish, the following formula will only show the total number of "B"s that are in your input source: =IF(ROW(A2)>MAX(C:C),"",E2) Notice i did not fix the cells with $ as your following row depends on the former.
Cell F2 (the top of your col2 field for the result set) include: =INDEX(B:B,MATCH(G2,C:C,0)) and in G2 put: =IF(E2="","",G1+1) and copy both down as far as you have formulas in column E (or result set col1).
The reason for the IF statements is for formatting rather than displaying errors on failed lookups.
Goal: extract a subset of the current sheet only when values in the first column match a value in the first column of another 'Sheet1':
=VLOOKUP(A2,Sheet1!$A:$B,2,FALSE)
Add the formula above in the first cell of the first empty column, then sort Z-A this column and remove all "#N/A" rows, then re-order again A-Z the first column and remove this temporary column.
I am in need of an advanced lookup formula that will search through data from one table and produce a value based on conditions from another table.
What I am trying to achieve is this:
If Column J in Table 1 is equal to column A in Table 2 and
Column L in Table 1 is equal to Column D in Table 2
But Column D in Table 2 is blank but there are values in Column L of Table 2 except the value specified in Table 2 previously
And Column G in Table 1 is equal to Column B in Table 2
But Column B in table 2 is blank but Column G in Table 1 has values except the one specified previously in Table 2
And if Column O in Table 1 is equal to Column C in Table 2
But Column C in Table 2 is Blank and Column O in Table 2 contains values other than previously specified in Table 2
The end result should be column E in Table 2.
I used this formula but it is showing a value error
=IF(AND(Trans!J:J=Mapping!A:A),Mapping!E:E),IF(AND(Trans!L:L=Mapping!D:D),Mapping!E:E),IF(AND(Mapping!D:D="",Trans!L:L<>""),Mapping!E:E), IF(AND(Trans!G:G=Mapping!B:B),Mapping!E:E),IF(AND(Mapping!B:B="",Trans!G:G<>""),Mapping!E:E),IF(AND(Trans!O:O=Mapping!C:C),Mapping!E:E),IF(AND(Mapping!C:C="",Trans!O:O<>""),Mapping!E:E)
The formula can also be searching by row. I would just like something that works!
Please help.
Your formula is doing nothing, it seems you are combining all the logics you thought in one place, but it is not in a form that excel can understand.
As per my understanding you have to remove the blank checks, as per your data they may return unexpected results, if their is one blank or if there are more in both cases result would be different, you would not know the reason of a returned value. (it is not logical to make a check like that)
A logic like this may return more than one value, you have to put some formula in case there are more values returned.
AS for the formula, you are comparing a full column with a full column. It is not recommended to do that, the recommended way is to compare one value to a range of values and the function AND() is not required in the way you are using it
a comparison in the formula would be something like
=IF(Trans!J3=Mapping!A3:A20,Mapping!E3:E20,"")
and it is an array formula that can return multiple values
At the end summary is that first you have to define the logic you are making, it is not clear and not accounting for all possibilities after that learn how to apply such formulas and then apply it on your data.
In large dataset - 250 rows and 1000 columns I need to compare each value in cell with each other in one column and iterate over all column. Heres simplified example of source data:
And this is what I need (formatting not necessary and 2 empty rows not necessary) - if match if found "1" is produced, if no match "2" is produced, if one or both were N/A - "3" is produced:
Comparison should only be "one sided" for example Terry and Joey is the same as Joey and Terry, thus further comparison of already compared pairs is not needed.
Is it possible to do this in Excel 2016 or are there better tools for this?
My thanks to all.
This alternative is a bit complex, but we all solve problems like this differently. If it helps you, please feel free to use it. If not, I can understand since some of these techniques are not particularly common and the resulting formula is a bit unreadable. I did it this way so that I would be able to organize the rows better and read the matching/unmatching indicators more easily. I started by creating a helper column rather than repeat the rows for each individual so that each row shows the two names being compared. This is the formula I used to compare using B8's information is:
=IF(OR(INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A",INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A"),3,IF(INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)<>INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE),2,1))
I am going to try to explain the formula I used as follows:
Without using the helper column, the basic formula for cell B8 is this:
=IF(OR(B$2="N/A",B3="N/A"),3,IF(B$2<>B3,2,1))
and this would work for the range B8:H11. However, when I skip down to B13, the formula would need to change to:
=IF(OR(B$3="N/A",B4="N/A"),3,IF(B$3<>B4,2,1))
and this would work for the range B13:H15. Likewise B17, and B20 would be:
=IF(OR(B$4="N/A",B5="N/A"),3,IF(B$4<>B5,2,1))
=IF(OR(B$5="N/A",B6="N/A"),3,IF(B$5<>B6,2,1))
for their respective ranges. I shy away from formulas where I have to remember what I need to change for each section (heaven forbid I should write any notes or read them if I did).
In order to do this, I used the person column (A) and my helper column (I) to determine which rows to compare.
MATCH($I8,$A$1:$A$6,0)
gives the row of the person value in the Chart from A1:H6 in the comparison
MATCH($A8,$A$1:$A$6,0)
gives the row of the helper value in the Chart from A1:H6 in the comparison
Since the data being compared is always in the same column, I just use COLUMN() to determine which column to use.
In cell B8, MATCH($I8,$A$1:$A$6,0) will tell me it is row 2 and MATCH($A8,$A$1:$A$6,0) will tell me it is row 3. Thus, I want to use the values in Row 2, Column 2 compared against Row 3, Column 2.
To tell Excel to compare Row 2, Column 2 against Row 3, Column 2 is fairly simple, but creating a formula that you can copy from cell to cell without having to modify it each time is not as easy, since each section is a bit different and there could be blank rows in between sections. What I did was to use indirect cell notation using "R1C1" syntax rather than the more common "A1" cell referencing.
In other words in column B8 this:
INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)
gives the value in Row 2 (for Terry), Column 2 and
INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)
gives the value in Row 3 (for Joey), Column 2 and
In both of the above, I am concatenating and R and a C to the numbers returned by the MATCH() and COLUMN() functions and using the FALSE parameter to tell Excel to treat the concatenated result as "R1C1" notation. In other words, this:
OR(INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A",INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A")
translates to this:
OR(R2C2="N/A",R3C2="N/A")
I realize that the helper column is a burden you did not ask for and I realize that the formula is overly complicated, but I can freely copy this formula to any column that has the two names and it will do a comparison for that day of the week.
Here is a picture of what I am describing:
Added comments
Just to carry the above a bit further, suppose you had a Sheet1 which had the rows of data to be compared and suppose this were limited to 250 rows with the same 7 columns (rather than 1000). I could create another sheet similar to the above along with another helper cell (I put it in A1) to automatically populate the person column and the helper column like this:
New Helper Cell value: 1 (essentially saying to start at the top). This would populate Cell A2 with the following formula:
=IFERROR(IF(INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(RIGHT($A$1,3)+ROW()))=0,"",INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(RIGHT($A$1,3)+ROW()))),"")
Basically this is just this formula:
=INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(RIGHT($A$1,3)+ROW()))
but is checking first to see if it results in zero and then is replacing it with blanks if it is an error. Copying this cell down Column A will populate that column with the names starting at the first row after the data row specified by A. If you have more headings or other data you would need to add additional amountst to the +ROW() portion in both occurrences in the formula. Column I gets populated siimilarly with this:
=IF(A2="","",INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(LEFT($A$1,3)+1)))
However, this value does not vary from row to row.
Now that the helper columns are populated, you can populate the formula a bit differently from the above (which had used the same sheet) for example in B2:
=IF($A2="","",IF(OR(INDIRECT("Sheet1!R"&MATCH($I2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE)="N/A",INDIRECT("Sheet1!R"&MATCH($A2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE)="N/A"),3,IF(INDIRECT("Sheet1!R"&MATCH($I2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE)<>INDIRECT("Sheet1!R"&MATCH($A2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE),2,1)))
The main difference from the first formula is the off sheet references to "Sheet1" that were added and the extension of the formula to cover 250 rows.
Here is a picture with Cell A1 set to 1:
Here is a picture with Cell A1 set to 3:
Using this, your Sheet1 values remain where they are and you can create a generic comparison sheet to compare the values of various rows of Sheet1. These can be dynamically built by changing the value in A1 or you can create dozens of similar sheets, each differing by the value in A1.
Not sure if any of this makes sense.
Good Luck
Just use a function like this(exemple for cell B4):
=IF(B3=B2;1;IF(B3="N/A";3;2))
Print of it working
Do it for each line and just drag it from the begining to the end.
EDIT: You should do an or in the 2nd if to make surre neither is "N/A"
=IF(OR(B3="N/A";B2="N/A";3;IF(B3=B2);1;2))
So this seems like it should be pretty easy. I could just concatenate and make another column in the data to make a unique combo and get my answer. But that just seems so messy. So here I am reaching out to you fine folks to pick your brains.
I want to look up HQLine and Description in the MPCC tab to return the correct MPCC Code. I tried a couple IF statements with VLOOKUPS but couldn't get it right.
So I need to look up BK3 Positive Crankcase Ventilation (PCV) Connector in the MPCC tab. So it needs to match BK3 and the Long description and then give me the correct code.
Here is the missing data file
Here is the MPCC export list that I want to search
Use SUMIFS.
SUMIFS will find the sum in a table of rows that meet certain criteria. If the MPCC is always a number, and the MQAb-LongDescription is always unique, SUMIFS will find the correct ID.
=SUMIFS(Sheet1!C$2:C$100,Sheet1!A$2:A$100,A2,Sheet1!B$2:B$100,B2)
where Sheet1!A$2:A$100 is the HQAb data, Sheet1!B$2:B$100 is the Long Description data, Sheet1!C$2:C$100 is the MPCC Number data, A2 is the HQLine, and B2 is the Description.
The formula would go in C1.
More information on VLookup with Multiple Criteria
You can use an Index/Match with multiple criteria.
I'm assuming that you will put this formula in "Sheet1", cell C2, and your lookup data is in a sheet called "Sheet2", columns A, B, C from row 2 to 30.
Put this in Sheet1, C2:
=INDEX(Sheet2!$C$2:$C$30,MATCH(A2&B2,Sheet2!$A$2:$A$30&Sheet2!$B$2:$B$30,0))
(Enter with CTRL+SHIFT+ENTER) and drag down.)
Adjust the ranges as necessary.
lets assume your first Table is on sheet 1 in the range A1:C11 and the MPCC codes are located on Sheet 2 in the range A1:C32. Each table has a header row so your data really starts in row 2.
Similar to BruceWayne's answer of using an array formula, you can bring the array calculation inside of a formula and avoid the special array treatment. There are a few functions that can do this. I will demonstrate with the SUMPRODUCT function;
On Sheet 1, Cell C2, use the following formula:
=INDEX('Sheet 2'!$C$1:C$32,SUMPRODUCT((A2='Sheet 2'!$A$2:A$32)*(B2='Sheet 2'!$B$2:B$32)*row('Sheet 2'!$A$2:A$32))
Explanation:
When the value in A2 matches the value in the range in the second sheet it will be true and false when it does not. when True False get used in math operations they are treated at 1 and 0 respectively. Therefore the only result from your two search criteria will be the rows where A2 match is true and B2 match is true and this will have a value of 1. The 1 will then be multiplied by the row number. Since all other results will be 0 since your list is a unique combination, the sum part of sumproduct will sum up to the row number where your unique row is located. This in turn is used by the indext function to return the row to give your unique number.
I have a sheet in Excel where the columns contain different names of people that are in different teams in my department (i.e. Names in Column 1 are in Team 1).
For another sheet, I need to have a formula that achieves the following:If I write a name in Cell B2 that can be found in the first column of that other sheet (Team 1), Excel should populate cell B6 with "Team 1".
If instead, the name I wrote is found in the second column, then the text should read "Team 2".
I've tried a couple of different formulas w/o success, and stringing a lot of IF and OR functions together is way too cumbersome. Anybody has a better solution?
If you need this formula for more then only two column then id use the formula
=INDEX(Sheet1!C1:G1,SUMPRODUCT((Sheet1!C2:G6=B1)*COLUMN(Sheet1!C2:G6)))
Say you have a set-up like:
And in B1 of Sheet2 you enter Name3, you want it to return TEAM1 as shown below:
The only catch to this formula is that you will need to tell it how many columns are before your data so if you have a table more like:
Then you need to tell the formula that there are 2 rows before your data starts, your new formula will be
=INDEX(Sheet1!C1:G1,SUMPRODUCT((Sheet1!C2:G6=B1)*COLUMN(Sheet1!C2:G6))-2)
Notice the -2 before the last parenthesis this is to indicate that there are 2 columns BEFORE you data.
and the new result for looking up say NAME20 would become as follows:
*EXPLANATION: *
The formula works as follows , I will do it all on one page for easier viewing and instead of Sheet2!B2 and B6 I will use G2, and G6 on the same sheet as the data.
First we look at all values in the Range A1:E6 and find the one with the matching name so we use
=A1:E6=G2
Now when you enter this into the cell you will recieve a #VALUE,but if you goto the Formula Bar and press F9 it will shwo you the full value of the formula
{FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,TRUE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE,FALSE}
In this we know that one cell contains the Name we searched for, this is represented by the TRUE
Now when using a formula like SUMPRODUCT, FALSE = 0 and TRUE = 1
So to get the column we mutiply every result by the column they are in.
=SUMPRODUCT((A1:E6=G2)*COLUMN(A1:E6))
So any cells that don't =G2 are FAlSE or 0, and when you multiply the column of that cell by 0 (because false = 0) it will simply result in 0. But for the one cell that IS TRUE or 1 When you multiply the column of that cell by 1 (because TRUE = 1) The product will be the cells column number
So as shown in the picture when looking for NAME13 the result of the sumproduct is 3 (its column)
Then to return the TEAM for that name, we use the INDEX function will return the value in a cell at the given cordinates.
In this case we want the value from A1:E1 that is in the same column as the Name we matched. When looked at as an Array A1:E1 looks like
{"TEAM1","TEAM2","TEAM3","TEAM4","TEAM5"}
And we want to return the value in that array at the same position as the column number of our cell, Minus any nonincluded column before the data, thus the reason for the -2 in the secon example I gave you.
So:
=INDEX(A1:E1,SUMPRODUCT((A1:E6=G2)*COLUMN(A1:E6)))
In this example excel interprets this formula as
Return the 3rd value (the 3 comes from the sumproduct as explained earlier) in the list of value from A1:E1. And that value would be TEAM3.
use a MATCH() or VLOOKUP() function inside an IF(). SOmthing like:
IF(NOT(ISERROR(MATCH(...)));"Team1";"")
Did you know you can browse functions by catergoty (such as Search), just clikc the fx left of your formula bar and use the drop down box. Each formula comes with a description with usually rather clear information...