I would like to know how to use a combination of Index/Match to pull data from one column to another by referencing multiple criteria. From the image attached, Column R should be auto populated (with a formula) with values from column A based on its corresponding reference in Column S.
Column S will match with Row 1 to find its column location in the array B2:K11. In the matched column, excel should then find the Row number that contains any value equal to or greater than 0 (or not blank). When it finds the row with a value it will pull the value from column A into Column R.
For example, in R2, it will look at S2 and see it needs the location for X1. It will go to the array and find X1 in B1. It will go down the column and find a value in B3 since the "10" is there. It will pull A3 into R2.
Im trying to do this without using VBA and as clean and efficiently as possible (i.e if possible without helper columns, and less processing power required). I have provided an example image of what I am trying to accomplish as I am unable to upload the actual file.
I have tried a variety of Index/Match combinations but have been unable to modify the array not to be fixed to a specific column. I have also tried ADDRESS() to create a custom array but this did not work, Attempted formulas are shown below:
In R2 to find column location: =MATCH(S2,A1:K1)
To Find Row number in B2:B11 (single column):
{=MATCH(TRUE,ISNUMBER(B2:B11),0}
{=MATCH(TRUE,B2:B11>=0,0)}
=MATCH((LOOKUP(2,1/(B$2:B$11<>""),B$2:B$11)),B$2:B$11,0)
I need to combine these, but the array of the column to look in should be addressed to the column which was matched.
To Index column A:
=INDEX($A:$A,ROW,0)
Overall:
=INDEX(A:A,(=MATCH((LOOKUP(2,1/(COLUMN NUMBER MATCHED<>""),COLUMN NUMBER MATCHED)),COLUMN NUMBER MATCHED,0)),0)
If the values in your Array are all numeric, you can use:
R2: =LOOKUP(9.9+307,INDEX($B:$K,0,MATCH(S2,$B$1:$K$1,0)),$A:$A)
If the values might be numeric or alpha, then try:
R2: =LOOKUP(2,1/LEN(INDEX($B:$K,0,MATCH(S2,$B$1:$K$1,0))),$A:$A)
In each case, the formula will match the last entry in the particular X labelled column.
Related
I have a dataset looking at ratings over time:
A B C D E
ID Date Rating-1 Rating-2 Rating-3
1 01/01/20 Y
2 01/05/19 Y
3 15/12/19 Y
I want to extract the rating for a particular ID at a particular date. As the rating is not specified in the data (as each is represented by a Y value), I need to reference either the column heading or the column reference.
To get the relevant row, I can use a Match formula:
=MATCH(1,(1=$A$1:$A$4)*(DATE(2020,01,01)=$B$1:$B$4),0) - this will give row 2.
To get the column reference for a specific row, I can use a second Match formula: =MATCH("Y",$A3:$E3,0) - this will give column 4.
Is there a way to combine the two formulas to give me the column reference for a specified row (based on ID/Date criteria) and a specified column (the column with a Y value)?
I have tried a Index Match Match formula, but this seems to require the column reference to be specified, rather than finding a column with a Y value.
Try to avoid INDIRECT as it's volatile! There are other options such as below:
=INDEX(A1:E1,MATCH("Y",INDEX(A1:E4,MATCH(1,INDEX((A1:A4=1)*(B1:B4=DATE(2,020,1,1)),),0),0),0))
BTW, the nested INDEX is there to avoid necessity to CSE the formula. If you have ExcelO365 this could be removed.
Found a solution using INDIRECT, CONCATENATE and MATCH:
{=MATCH("Y",INDIRECT(CONCATENATE("$A",MATCH(1,(1=$A$1:$A$4)*(DATE(2020,01,01)=$B$1:$B$4),0),":$E",MATCH(1,(1=$A$1:$A$4)*(DATE(2020,01,01)=$B$1:$B$4),0))),0)}
Effectively, the CONCATENATE and INDIRECT parts of the formula creates a range specified by ID and Date criteria. This range takes the form of a single row in which to the MATCH function then searches for the Y value and returns the column number.
So, I would like to return the contents of all rows where the value in column A is, let's say, 1.
My thought process is that I could use:
=INDEX(row_range,MATCH(1,A:A,0),0))
But Match will only return one value here, i.e. the number of the first row which contains a 1 in column A.
Is there a way of creating an array with the Match formula (thus returning the multiple row numbers, all of which contain '1' in column A) and then place that in the Index array so that it then runs through each of the Match-array values and creates a big long list of values in one array which I can then list out on a separate sheet?
Hope this makes sense...
Here is a demonstration of what I'm hoping for, if that helps! The idea would be that the array as shown would be created, which could then be extended down the column as per the part underneath.
https://i.stack.imgur.com/nCusM.png
Use the file you showed in your example (as "Sheet1") and put these formulas into indicated cells in Sheet2:
Into cell A2 put
=AGGREGATE(15;6;ROW(Sheet1!A:A)/((Sheet1!A:A=1)*1);ROW(A1))
this will give you all the rownumbers where value in A column of sheet1 equals 1.
Into cell B2 put
=COUNTA(INDIRECT("Sheet1!"&A2&":"&A2))-1
this will give you how many cells are filled in that row.
Into cell C2 put
=TEXTJOIN(",";TRUE;OFFSET(Sheet1!$A$1;A2-1;1;1;B2))
This will give you all the cells with data from that row concatenated. If you dont have this formula (first time in 2016 I believe) you can use OFFSET function to list the values in separate columns and then CONCATENATE them.
Copy these three down as many times as you want and into cell C1 put
=TEXTJOIN(",";TRUE;OFFSET(C2;0;0;COUNTIF(Sheet1!A:A;1);1))
I need to sum all values in Column A where Column B is a duplicate.
Above is a sample of the data. Column B has urls and Column A has counts for the urls. What I want is to sum the values in Column A for duplicate values in Column B.
Example:
The output for _.apelabs.net should be 6.
How can I achieve this?
I think you are looking for the function =COUNTIF(Range,Criteria)
Here is a link that shows a usage example.
As #Andresson stated, if you're trying to count the number of times a specific url appears, you might want to use the COUNTIF function: =COUNTIF(range, criteria).
COUNTIF Example:
Using =COUNTIF(B:B, "_.apelabs.net")
would return 3 in your sample data (assuming your image includes the only instances of "_.apelabs.net").
This example of the COUNTIF function is the same as saying, "count the total number of times a cell in Column B (i.e. B:B) equals "_.apelabs.net"."
However, if you're wanting to sum together all the values in Column A where the corresponding url in Column B matches the given criteria, you'll want the SUMIF function: =SUMIF(range, criteria, [sum_range]).
SUMIF Example:
Using =SUMIF(B:B, "_.apelabs.net", A:A)
would return 5 in your sample data (again assuming your image includes the only instances of "_.apelabs.net").
This example of the SUMIF function is the same as saying, "each time a cell in Column B (i.e. B:B) equals "_.apelabs.net", sum together the values in Column A (i.e. A:A) that are located in the same row as each "_.apelabs.net" found in Column B."
Additionally, you can also use a pivot table, as #ScottCraner suggested. It's all a matter in how you want to present your findings.
I am using the following formula:
=VLOOKUP(E9, 'Raw data'!$A$1:$I$45857, 9, FALSE)
I have two tabs and I want one column in my first sheet to lookup the # value found in 'raw data' associated with the ID number found in column E (data begins on cell E9). my second tab, 'raw data', includes that same field as found starting on E9 in sheet 1 within the data range A1:I45857. The column I want returned from 'raw data' is the 9th column. I want to be exact matches only.
What I think excel is thinking - look for e9 in the array 'raw data' and when I see it, return the value that I find in the 9th column of that row within array 'raw data'.
What excel is saying - A value is not available to the formula or function
I am confused because the value is in fact available within that array. when I filter and search for just one of the IDs, I find it in both sheets. The data type is number for both columns and there are no rogue spaces or anything...
My goal is ultimately to take a subset of ids and look at the difference between the # found on sheet1 and the number found on 'raw data'. I am Vlookup-ing so that i can grab the # value on 'raw data, set it right next to the # i am comparing it to on sheet1 and then I can pivot the data to aggregate both of those numbers based on ID and create a calculated field showing the % difference between the two.
Any input on how to fix my vlookup or a workaround to join my # from 'raw data' to sheet1 based on a common ID is MUCH appreciated.
I recommend that you look into the combination of INDEX & MATCH, rather than VLOOKUP, for situations like this. VLOOKUP has 2 main flaws: (1) you have to order your data so that your search term is the left-most column of a continuous data block [as you have just seen]; and (2) it is volatile, meaning that when a column is inserted within your data block, it will no longer properly 'count' the number of columns to move to retrieve your data.
MATCH is like half of VLOOKUP. You give MATCH a specific column or row, and a value to search for, and it will simply return the number of cells in it had to move to find that value.
=MATCH(A1,B:B,0)
This says 'look at B:B, and tell me what row the value of A1 appears on'.
INDEX is like the other half of VLOOKUP. You give INDEX a group of cells (either a row, column, or a 2D range), and a specific row number (plus potentially a column number), and it will return the value for that cell.
=INDEX(C:C,5)
This gives you the value of cell C5, which is the 5th row found in the column given to INDEX. Combine these two formulas and it will return the value of column C, where column B matches A1:
=INDEX(C:C,MATCH(A1,B:B,0))
This formula gives an identical result to
=VLOOKUP(A1,B:C,0)
VLOOKUP looks simpler here, but INDEX & MATCH is much more versatile - in your case, you wouldn't have needed to reorder your data to get it to work, you could have used the formula:
=INDEX('Raw Data'!I:I,MATCH(E9,'Raw Data'!E:E,0))
Once you get into the habit of using INDEX / MATCH over vlookup, you will find that your data is a lot more flexible to manage.
Got it to work by making my ID field in 'raw data' the leftmost column.
You don't need to start the Vlookup in column A. If the ID column is not in column A, Vlookup can still work, as long as the ID column is to the left of the column you want to return. So, if you want to return the value from column I, and the ID column is in column F, you can leave the table as it is and change the Vlookup to
=VLOOKUP(E9, 'Raw data'!$F$1:$I$45857, 4, FALSE)
This will look for the match in column F and returns the value from the fourth column, which is column I.
I need to be able to find the row number of the row where matching criteria from A1 is equal or greater than values in column C and lesser or equal than values in column D
I can use INDEX and MATCH combo but not sure if this is something I should use for multiple criteria matching.
Any help or suggestions are highly appreciated.
I would not use MATCH to get the row number since you have multiple criteria. I would still use INDEX however to get the value of the row in E once the proper row number was discovered.
So instead of MATCH I would use an array formula using an IF statement that contained multiple criteria. Now note that array formulas need to be entered using ctrl + shift + enter. The IF statement would look like this:
=IF((A1>=C:C)*(A1<=D:D),ROW(A:A),"")
Note: I did not use the AND formula here because that cannot take in arrays. But since booleans are just 1's or 0's in Excel, multiplying the criteria works just fine.
This now gives us an array containing only blanks and valid row numbers. Such that if rows 5 and 7 were both valid the array would look like:
{"","","","",5,"",7,"",...}
Now if we encapsulate that IF statement with a SMALL we can get whatever valid row we want. In this case since we just want the first valid row we can use:
=SMALL(IF((A1>=C:C)*(A1<=D:D),ROW(A:A),""),1)
Which if the first valid row is 5 then that will return 5. Incrementing the K value of the SMALL formula will allow you to grab the 2nd, 3rd, etc valid row.
Now of course since we have the row number a simple INDEX will get us the value in column E:
=INDEX(E:E,SMALL(IF((A1>=C:C)*(A1<=D:D),ROW(A:A),""),1))
If you need to match more than one column value to retrieve a row number, that is, if two or more columns together create a unique ID you can use an array formula with MATCH as below:
MATCH(1,(A:A=J1)*(B:B=K1)*(C:C=L1),0)
where A, B, C contain the column array to be matched to retrieve the unique row number corresponding to the value in J1, K1, L1 respectively.
For a step-by-step guide, Christian Pedersen's Explainer