Move a this cells value to this cell if it equals this [duplicate] - excel

I know this might not be the best place to ask a purely excel question, but. I have a table with the following headers: Number, Date, Name. In another file I need to link the number with the name. It is not always in the same order, hence the VLOOKUP formula. Here is the data below.
1 15-Nov Allen 15-Nov
10 15-Nov Allen 15-Nov
19 15-Nov Allen 15-Nov
6 5-Mar Avalon 5-Mar
15 5-Mar Avalon 5-Mar
24 5-Mar Avalon 5-Mar
9 15-Nov Burg 15-Nov
18 15-Nov Burg 15-Nov
27 15-Nov Burg 15-Nov
8 1-Sep Fischer 1-Sep
17 1-Sep Fischer 1-Sep
26 1-Sep Fischer 1-Sep
3 14-Oct Kiser 14-Oct
12 14-Oct Kiser 14-Oct
21 14-Oct Kiser 14-Oct
2 15-Oct Remmert 15-Oct
11 15-Oct Remmert 15-Oct
20 15-Oct Remmert 15-Oct
4 1-Sep Roos 1-Sep
13 1-Sep Roos 1-Sep
22 1-Sep Roos 1-Sep
7 6-Feb Tomo 6-Feb
16 6-Feb Tomo 6-Feb
25 6-Feb Tomo 6-Feb
5 1-Jan Wash 1-Jan
14 1-Jan Wash 1-Jan
23 1-Jan Wash 1-Jan
So Lets assume it is titled as Column A, B, C, D. So in the new file in order to grab the name from numbers I used the formula:
=VLOOKUP(A1,[Workbook1]Sheet1!$A$1:$D$27,3,FALSE)
Workbook1 and Sheet1 is where the data is. Next I need to grab the date from the file by linking it to the name. I know I can link it to the number but it is a thing for work and the way they are arranged are with Different dates from oldest to newest, not the same like this one. The Date function in excel is extremely stupid in my opinion. So I used the formula
=VLOOKUP(B1,[Workbook1]Sheet1!$A$1:$D$27,1,FALSE)
and iterations of it by replacing the 1 with 4. It keeps returning N/A. Even when I change the formatting of the Date to General it still returns nothing. I dont get what I am doing wrong here.

VLOOKUP syntax:
VLOOKUP(lookup_value , table_array, col_index_num, (optional) [range_lookup])
The VLOOKUP function will always look up the lookup_value in the first column of the table_array. It then attempts to return the value in the col_index_num of the corresponding row in the table_array. The range_lookup tells VLOOKUP whether to look for an exact or an approximate match. In your case, you will be looking for an exact match.
In no way can VLOOKUP return a value in the table_array that is to the left of the column looking to match the lookup_value. The lookup_value is always looked for in the first column and VLOOKUP returns a value in a column to the right.
Your formula to look up the name based upon the ID number in column A works well for this.
=VLOOKUP(A1, [Workbook1]Sheet1!$A$1:$D$27, 3, FALSE)
With 8 in A1, the above formula returns Fischer in B1.
      
When you are looking to return the dates, VLOOKUP will work for the one to the right of the name in Sheet1's column D but it cannot the return the date from Sheet1's column B basing the lookup_value on the name. You will need an INDEX/MATCH function pair for that. In addition, retrieving the second and third date sets that match the name is easier with INDEX/MATCH than VLOOKUP.
INDEX and MATCH syntax:
INDEX(array, row_num, column_num)
MATCH(lookup_value, lookup_array, (optional) [match_type])
If you are looking to return the date from Sheet1's column B using the name just retrieved from Sheet1's column C, you will have to use an INDEX/MATCH pair. Since we are using this for one date, it is eaay to use it for the other although strictly speaking, VLOOKUP could be used for this.
Use these two formulas in C1 and D1.
=INDEX([Workbook1]Sheet1!B:B, MATCH(B1, [Workbook1]Sheet1!C:C, 0))
=INDEX([Workbook1]Sheet1!D:D, MATCH(B1, [Workbook1]Sheet1!C:C, 0))
Format the cells for a custom number format of d-mmm. Your results should be similar to the following.
      
If you wanted to return the second and third dates from Sheet1 that match the name in column B, change the target worksheet's C1 and D1 to to these formulas that use the SMALL function togewther with the ROW function and COUNTIF function to produce the additional dates.
Make a minor tweak to the formula in B1 so it can be filled down then supply the next two formulas for C1 and D1.
=VLOOKUP(A$1, [Workbook1]Sheet1!$A$1:$D$27, 3, FALSE)
=IFERROR(INDEX([Workbook1]Sheet1!B$1:B$999, SMALL(INDEX(ROW($1:$999)+([Workbook1]Sheet1!C$1:C$999<>B$1)*1E+99, , ), COUNTIF(B$1:B1, B1))), "")
=IFERROR(INDEX([Workbook1]Sheet1!B$1:B$999, SMALL(INDEX(ROW($1:$999)+([Workbook1]Sheet1!C$1:C$999<>B$1)*1E+99, , ), COUNTIF(B$1:B1, B1))), "")
Fill B1:D1 down down to catch all of the possible dates from Sheet1 that match the name returned from your original ID lookup. Your results should look like,
      
You may notice that I sequenced the identical dates on Sheet1 in order to demonstrate the method. The IFERROR function is used to display an empty string (e.g. "") instead of an error message when you run out of values (as in C4 and D4 in the above sample image).
In summary, use the VLOOKUP function to return values to the right of the value sought; use an INDEX/MATCH function pair to retrieve values from either side of the matching column.

I assume that B1 holds the name of the person. In that case, you need to adjust the range for the lookup table, so that it starts in the column with the name, i.e.
=VLOOKUP(B1,[Workbook1]Sheet1!$C$1:$D$27,2,FALSE)
EDITTED : Change the column to 2 to get the date

You need format the date with the following format :
This is the overall that I had done to solve the problem.

Related

If function and Xlookup

I am currently trying to run an excel function that runs the logic that if the cell that has date X is greater than date 2023-01-01 then run an XLookup function. If it is not then do not run it.
Here's what I tried below:
=IF(table2!N5>DATE(2023,1,1),XLOOKUP(A2,'Table2'!A:A,'Table2'!B:B),"FALSE")
N5 has the date 2022-12-01. The rest is just a standard xlookup function that would run if cell N5 is greater than the date 2023-01-01.
Data for the Xlookup below:
Table 1 : This table provides the lookup value A1.
A B C
1 Position Classification Full Name
2 111111 IT 04 John Smith
Table 2 : This table provides the lookup array being A:A and the return array being B:B
A B C D
1 Employment Position CC Valid From Valid To
2 111111 8888888 2022-10-01 2023-03-31
As posted in comments, I will suggest you use a cell reference, so it becomes more dynamic to use, instead of hard coding within a formula,
• instead of this
=IF(N5>0+"2023-01-01",XLOOKUP(E3,H:H,J:J),"FALSE"))
• Use a cell reference, let's say cell A1 = 2023-01-01
=IF(N5>A1,XLOOKUP(E3,H:H,J:J),"FALSE"))
So the above helps you in changing the cell A1 values whenever you need instead of bothering the formula each time for a change.
I would advise you to use the DATE() function, like this:
= IF(A1>DATE(2023,1,1), ...)

Excel SUMIF column value matches

I would like to sum all values in column J when the value in column K matches. So, for example, I have the following:
COL J | COL K
25.00 | Now
45.00 | Aug 15
40.00 | Sep 10
70.00 | Now
14.00 | Aug 15
92.00 | Now
I'd like Excel to find all matching values in Column K and add up the values in corresponding rows of column J. For the example above it would sum 25.00, 70.00 and 92.00 which correspond with "Now" and then also add up 45.00 and 14.00 which correspond with Aug 15.
I know it can be done with formulas like this:
=SUMIF(K:K,"Now",J:J)
=SUMIF(K:K,"Aug 15",J:J)
However, I'd like to be more flexible and not have to have a separate formula for every different value in Column K. Is there a way to use a wildcard of some sort that can replace "Now" and "Aug 15" in the example above so that I could just have one formula that finds any matches in Column K and sums the corresponding values for those rows in Column J?
Thank you!
SUMIF accepts wildcards (e.g., this or this).
I tried adding another line to your data,
92.00 | Never
and then =SUMIF(K:K,"N*",J:J). It works great. If I understood what you were specifically aiming at, it would be =SUMIF(K:K,"*",J:J).
PS: I wouldn't know how it behaves when you have cells formatted as date, and you try to match according to what is displayed. That might involve locale issues.
You need to investigate Array Formulas also known as CSE formulas. http://www.mrexcel.com/articles/CSE-array-formulas-excel.php or http://office.microsoft.com/en-us/excel-help/guidelines-and-examples-of-array-formulas-HA010342564.aspx
=SUM(IF($K$1:$K$6=K1,$J$1:$J$6,0))
If you paste this formula into cell L1 (assuming your data is in K1:J6) and press Control-Shift-Enter to save it, it will calculate the sum of all the cells in Column J that have a matching Column K. Array Formulas are pretty powerful but they are pretty hard to debug.

PercentileIF Excel (or rangeif)

A B
1 5
2 10
2 15
3 20
I want to calculate percentile for a column of values B if A is equal say 2. That's I want to get range of B2,B3 and calculate percentile of this.
So basically the question is: how do I select range in one column with the checking with another column?
I.e. it works perfectly with SumIf and CountIf, I just need the same with PercentileIf. Thx!
This will give you the 25th percentile of A1:A6 for all cells where the value in B1:B6 equals 2:
=PERCENTILE.INC(IF(B1:B6=2,A1:A6,""),0.25)
It's an array formula and must be entered with Ctrl-Shift-Enter.

defining variables in excel formulas?

i have a simple table data like:
date | Jenna | Tom | Robin
01/01/12 2 5 8
02/01/12 3 4 7
(date columns starts from the first day of the year and goes all the way down to he next year.)
I have a formula getting the min. and max. values (for example for Jenna) for the month January.
I have to change the row numbers every month to get the right result.
Is it possible for me to define variables in two cells and use them in that formula without using VBA.
For example;
I will put two values in H1 and H2 cells, which are 28 and 58 respectively. And i will define E1 as start and E2 as end. And write down this formula:
=min(Cstart:Cend)
=max(Cstart:Cend)
=average(Cstart:Cend)
The first formula means to get the min value between the C28 and C58.
That way i will not have to change every formula manually on the page. I will just change the values of 2 cells and that will be enough.
I hope, I have explained.
Sure. You have to use the INDIRECT() function. INDIRECT transforms a string to a range reference.
=MIN(INDIRECT("C" & $H$1 &":C" & $H$2))

Return value of last match

I need a formula to return the value of Data for the last match of "Text". Row number is also acceptable. Macro is NOT acceptable. Name column is unsorted and cannot be sorted!
Only column "Name" is used as lookup value. I would rather use a/multiple helper column(s) instead of an array formula.
Row Name Data
1 Joe 10
2 Tom 20
3 Eva 30
4 Adam 40
5 Tom 21
LARGE only works with numbers, and VLOOKUP only returns the first match. LOOKUP only works sometimes, so its out too.
So if I wanted the last match for "Tom" then it should return "21".
Array formulas could be avoided with a helper column.
Suppose to have in F1 the name to match (i.e. Tom)
In the helper column row C2 enter
=IF(A2<>$F$1,0,row())
Then copy the formulas along your data.
Now the column C contains 0 for the unmatched names and the row number for the matched ones. Maxing the column yield the row of the solution.
Now the result is simple a matter of using the correct offset with the function offset:
=OFFSET(B1,max(C:C)-1,0)
PS: my copy of excel is in italian, so I can't test this english translaction of the formulas.
I think it's the easiest way to make it.
=LOOKUP("Tom";A2:B7)
Create a column with an array formula (enter it with Ctrl+Shift+Enter):
=VLOOKUP(MAX(IF($B$2:$B$6=B2, $A$2:A$6, 0)), $A$2:$C$6, 3, FALSE)
To make sure you did it right, click on the cell, and the formula should be shown encased in curly brackets ({}).
Note: This assumes that "Row" is in A1.
I have come up with a solution, but it requires that numbers in Data are concurrent, like so
Name Data
Joe 1
Tom 1
Eva 1
Adam 1
Tom 2
Tom 3
Eva 2
But thats okay, since that my data looks like that anyway. So if Name is used before then it must be the old highest +1 aka concurrent.
Name is A1 and Data is B1, and this formula goes into C2:
FLOOR(SQRT(2*SUMIF(A2:A7,A2,B2:B7)),1)

Resources