Index/Match- Lookup 2nd Value if 1st Value is Blank - excel

I was hoping to get some assistance in writing a formula in excel.
I have a table that contains a list of employees and their cell phone number. However, the table is structured in such a way that there is a number of blank and duplicate rows.
Essentially, I am hoping to create a new table without any duplicates and blanks by performing a lookup on the respective cell phone numbers.
The problem is, when I do a standard Index/Match formula, the formula will grab just the first lookup value, which more often than not, is a blank row.
How would I modify this formula to say something like, "Look this value up. If the value is blank, lookup the second value"?
Here is a sample of what the table looks like:
Table 1 (Original)
+---------------+--------------+
| Employee Name | Cell Phone |
+---------------+--------------+
| Doe, John | |
| Doe, John | 111-111-1111 |
| Smith, Eric | 222-222-2222 |
| Jones, Dave | |
| Jones, Dave | 333-333-3333 |
+---------------+--------------+
Table 2 (What I want the table to look like)
+---------------+--------------+
| Employee Name | Cell Phone |
+---------------+--------------+
| Doe, John | 111-111-1111 |
| Smith, Eric | 222-222-2222 |
| Jones, Dave | 333-333-3333 |
+---------------+--------------+
=Index(Table1[Cell Phone], Match([Employee Name], Table1[Employee Name],0))

How about the first non-blank match?
=INDEX(B:B, AGGREGATE(15, 6, ROW($2:$999)/((A$2:A$999=F2)*(B$2:B$999<>"")), 1))
'listobject table alternative
=INDEX(Table1[Cell Phone], AGGREGATE(15, 6, (ROW(Table1[Cell Phone])-ROW(Table1[#Headers]))/((Table1[Employee Name]=F7)*(Table1[Cell Phone]<>"")), 1))

Related

Excel formul to count Table Range using month from date text

I have an excel workbook where I am trying to count the number of apples in a named table. The workbook has multle sheets each named Jan, Feb, Mar, etc. with a corresponding table range of the same name.
My main worksheet has a list of months as columns and fruit as rows, I want to use a countif or suitable function to count the number of each fruit per month using the column heading as the worksheet portion of the formula.
This is what I have tried, this works, but has to be manually coded for each month, i would prefer it be more dynamic.
=COUNTIF(JAN[Labels],$A2)
Note: A2 contains the word apple
I have tried to get the month from the column date but it doesnt work
=COUNTIF(TEXT(E25,"mmm")[Labels],$A2)
This is roughly what the "master" table should look like (for clarity)
| | Jan-20 | Feb-20 | Mar-20 | .... |
| Apple | 4 | 3 | 5 | ... |
| Pear | 5 | 4 | 9 | ... |
EDIT:
Just to assist with anyone trying to help, this is roughly what a table on another sheet will look like:
| invoice | labels|
| 12535 | Apple |
| 12536 | Pear |
| 12537 | Apple |
This table would be a named table of Jan or Feb, etc.
Please try this:-
=COUNTIF(INDIRECT(TEXT(G2,"mmm")),"A")
G2 contains a proper date.
Here is a variation of the above where column 2 of the table is specified as the range to count in.
=COUNTIF(INDEX(INDIRECT(TEXT(G2,"mmm")),0,2),"B")
If you must use column captions to identify the column I would suggest MATCH to find it.
OK, so I found an answer, combining the above answer by Variatus with an additional new row.
| A | B | C | D |
1| | Jan-20 | Feb-20 | Mar-20 |
2| |JAN[Labels]|FEB[Labels]|MAR[Labels]| <- =UPPER(TEXT(B1,"MMM"))&"[Labels]"
3|Apple | 5 | 7 | 3 | <- =COUNTIF(INDIRECT(B$2),$A3)
4|Pear | 7 | 2 | 9 |
5|Orange| 1 | 3 | 3 |
So formula in B2 makes an uppercase text value of the month from B1 plus the column name Labels.
The formula in B3 (and down) counts the number of instances of the fruit from the named table & column shown in B2.

Vlookup for row to column

My table is something like below, currently I have a column as category with few types of cat names but now we what to have the categories as column header and the name's attached to it.
Table now;
ID | category | Name |
856| Car | Ford |
432| Motorcycle | Honda|
Desired;
ID| Car | Motorcycle |
856| Ford | (blank) |
432 | (blank) |Honda |
How can I do this?
Say your "Table now" table is named TableNow, and your "Desired" table is named TableDesired. Put this formula into your Car column, and fill over.
=IF(VLOOKUP([#ID],TableNow,2,FALSE)=TableDesired[#Headers],VLOOKUP([#ID],TableNow,3,FALSE),"")

Fill down excel values between dates

I have an excel sheet (called Sheet1) with rows of data that look like this:
Unit | Names | Begin_Date | End_Date
-----------------------------------
A | Jones | 1/1/2016 | 1/4/2018
A | Frank | 2/11/2018 |
B | Adam | 3/5/2011 |
C | Jane | 6/9/2012 | 7/14/2016
C | John | 7/28/2016 | 9/22/2017
C | Joe | 12/31/2017 | 1/1/2019
C | Joe | 1/2/2019 |
I am trying to get it into a format that has the units as column headers and dates as rows. The idea is that for every day between the begin and end dates, the name of the person should be in the appropriate cell. If there is a gap between the end date of one person and the begin date of the next within the same unit, the formula will list "vacant". It is assumed each unit was vacant before the first "begin date" for that unit, and blanks for end dates mean that the person still occupies that unit. Ideally the completed data set would look like this, on Sheet2:
Date | A | B | C |
-------------------------------------
3/5/2011 | Vacant | Adam | Vacant
3/6/2011 | Vacant | Adam | Vacant
...
6/9/2012 | Vacant | Adam | Jane
...
1/1/2016 | Jones | Adam | Jane
...
7/14/2016 | Jones | Adam | Jane
7/15/2016 | Jones | Adam | Vacant
7/16/2016 | Jones | Adam | Vacant
...
7/28/2016 | Jones | Adam | John
...
1/4/2018 | Jones | Adam | Joe
1/5/2018 | Vacant | Adam | Joe
etc.
The formula I have thus far populates the first values, i.e. the first person to live in the unit or, if no one, then it lists "vacant" on Sheet2. However, I am not sure how to extend it to look for the next person. I've listed all the dates in column A and all of the unique Unit names in row 1. Any help or advice would be appreciated!
=iferror(if(index(Sheet1!Names,match(1,(Sheet2!A$2=Sheet1!Begin_Date)*(Sheet2!$A3=Sheet1!End_Date),0))=Index(Sheet1!Names,match($A2,ArrayFormula(min(Sheet1!Unit=B$2,Sheet1!Begin_Date)),"Vacant",Index(Sheet1!Names,match($A2,ArrayFormula(min(Sheet1!Unit=B$2,Sheet1!Begin_Date))),Index(Sheet1!Names,match($A2,ArrayFormula(min(Sheet1!Unit=B$2,Sheet1!Begin_Date)))
This uses aggregate and is basically an array formula but without having to be entered with
CtrlShiftEnter
=IF($F2="","",IFERROR(INDEX($B:$B,AGGREGATE(15,6,ROW($A$2:$A$10)/
(($A$2:$A$10=G$1)*($F2>=$C$2:$C$10)*(($F2<=$D$2:$D$10)+($D$2:$D$10=""))),1)),"Vacant"))
Aggregate(15,6...1) woks out the minimum value of the array inside it, ignoring any error values. This array consists of the rows 2-10 divided by the conditions on the rows. The conditions are set up (as you did) using * for AND and + for OR. Where the conditions are false, this leads to a division by zero which gives an error, so only the rows which satisfy the condition are taken into account.
You can also use this
=IF($F2="","",IFERROR(INDEX($B$2:$B$10,MATCH(1,
($A$2:$A$10=G$1)*($F2>=$C$2:$C$10)*(($F2<=$D$2:$D$10)+($D$2:$D$10="")),0)),"Vacant"))
entered as an array formula.

How to do VLOOKUP with a list of values

I have two sheet in excel.
In sheet2 I have a table with these fields:
NAME, SURNAME, CITY, AGE
In sheet1 I have to set field CITY and I want that table under this field will be with all the rows from sheet2 with selected CITY.
If I do a VLOOKUP I obioubsly get only first row of table.
Example:
A | B | C | D
NAME | SURNAME | CITY | AGE
Alex | Green | Rome | 18
Max | Brown | Rome | 21
Mary | White | Milan | 33
George | Violet | Rome | 27
In sheet 1 I have
A | B | C | D
CITY | Rome
NAME | SURNAME | CITY | AGE
VLOOKUP| VLOOKUP | VLOOKUP | VLOOKUP
VLOOKUP| VLOOKUP | VLOOKUP | VLOOKUP
VLOOKUP = VLOOKUP($B$2;Sheet2!A:D;1;0) -->
I wanted ALEX, MAX, GEORGE; I have ALEX, ALEX, ALEX
How can I do this without macros?
Thank you
For a simple data configuration like your sample pu this in Sheet1!A3 and fill both right and down,
=INDEX(Sheet2!A:A,AGGREGATE(15,6,ROW($2:$9)/(Sheet2!$C$2:$C$9=$B$1),ROW(1:1)))
For more complicated data configurations and retrievals put this in Sheet1!A3 and fill right and down,
=INDEX(Sheet2!$A:$D, AGGREGATE(15, 7, ROW($2:$9)/(Sheet2!$C$2:$C$9=$B$1), ROW(1:1)), MATCH(A$2, Sheet2!$1:$1, 0))
Use an IFERROR function 'wrapper' to avoid displaying worksheet errors when you run out of data to retrieve.

Excel - compare and replace cell value based on a value in another table or column

I have one column with countries acronymns
SHEET 1
+------------------+
| Country_Acronym |
+------------------+
| EG |
| AE |
| PK |
| IN |
| LK |
+------------------+
I have another sheet with corresponding titles
SHEET 2
+------------------+----------------------+
| Country_Acronym | Country_Name |
+------------------+----------------------+
| EG | Egypt |
| AE | United Arab Emirates |
| PK | Pakistan |
| IN | India |
| LK | Sri Lanka |
+------------------+----------------------+
I need a formula to read the value on the first column of the first sheet and replace the value with the country_name on the 2nd sheet.
So, when you find EG replace with Egypt, when you find PK replace with Pakistan etc
You cannot change the value of cell itself depending on the value within that very self cell - without using VBA.
Instead you may use the below formula on the B2 of Sheet1 & copy down, then copy that column, paste onto Col:A as Values Only.
=VLOOKUP(A2,Sheet2!A:B,2,0)

Resources