Excel, using match index, and if statement - excel

My issue is that I have an excel file. The file requires me to analyze 4 columns.
This is the data:
F is the column for the in-active and active
B is for the name being compared
G is the column with a bunch of names
H is the column with the dates
Given the status as in-active, or active, beside the city name, i am required to match it with the other city column if it is Active. If it is active, then display the date.
I tried to implement this formula:
=IF(INDEX(F:F, MATCH(B2,$G:$G))="Active",INDEX(H2:H1683, MATCH(B2,G2:G1683,0)),"n/a")
but it seems to display for active and inactive.

This was the solution
=IF(INDEX($F3:$F1684,MATCH($B3,$G3:$G1684,0))="Actual",INDEX($H2:$H1684,MATCH(B3,G2:G1683,0)))

You can use xlookup to search for multiple criteria.
=XLOOKUP("active"&B2,$F$2:$F$14&$G$2:$G$14,$H$2:$H$14,"na",0)
Or, you can use an alternative form using boolean logic:
=XLOOKUP(1,($F$2:$F$14="active")*($G$2:$G$14=B2),$H$2:$H$14)
See https://exceljet.net/formula/xlookup-with-multiple-criteria for a tutorial on searching with multiple criteria.

Use SUMIFS:
=IFERROR(1/(1/SUMIFS(H:H,F:F,"Active",G:G,C2)),"n/a")
This assumes that only one date per Name/Status combo exists.
With the new Dynamic Array formulas:
=#FILTER($H$2:$H$7,($F$2:$F$7="Active")*($G$2:$G$7=C2),"n/a")

Related

Highlight/extract rows that consist of a specific value

Im not sure if this can be done in excel but here goes.
Im looking for a way to either extract/highlight a list of OrderID & with its related products only if the OrderID has Product "A" while ignoring the other orderID's that does not have A.
I have tried using IF statements to detect Product "A" but it could not check the subsequent OrderID rows. I also thought of using Concatenate/Textjoin but couldn't make it work.
Screenshot of sample data:
Result im trying to achieve
It should only highlights/extract the OrderID's 6613,7557 and 3396 (along with the other products values) as these OrderID's has product "A". While it ignore other OrderIDs that does not have Product "A" (eg. 4519,7601,2113,9880)
Edited: attached 2 pictures to differentiate sample and results
To highlight use below formula in conditional formatting.
=AND(ISNUMBER(MATCH($A2,$E$2:$E$10,0)),$B2="A")
If you want to filter data with Product A then use below formula.
=IFERROR(INDEX($A$1:$B$17,AGGREGATE(15,6,ROW($A$1:$A$17)/($B$1:$B$17="A"),ROW(1:1)),COLUMN(A$1)),"")
If you have Office365 then use Filter() formula.
=FILTER(A1:B17,B1:B17="A")
If you have O365:
F2: =FILTER($B$2:$C$17,COUNTIFS($B$2:$B$17,$B$2:$B$17,$C$2:$C$17,"A"))
If you have an earlier version of Excel:
=INDEX(B2:C17,
-1+AGGREGATE(
15,6,
1/COUNTIFS($B$2:$B$17,$B$2:$B$17,$C$2:$C$17,"A")*ROW(B2:B17),
ROW(INDEX($A:$A,1):INDEX($A:$A,SUM(COUNTIFS($B$2:$B$17,$B$2:$B$17,$C$2:$C$17,"A"))))),
{1,2})
Highlighting the A's can be done with simple conditional formatting (eg cell equals A)

Using VLOOKUP and not only match on first value

I'm trying to use VLOOKUP to match activities with product codes, but run into an issue since VLOOKUP always returns the first match. I did a mockup below to describe my issue. To the left, I have a table with activity names and product codes.
To the right, in column G, I want to, based on matching activity names in column F with activity names in column A, assign the activities product codes from column B.
When I use VLOOKUP, it only matches with the first activity name and give all the activities with the same name the same product codes. I need them to get different product codes even if they have the same name. I want my function to "take the next one" on the list, when the first one is taken.
Should I try to use another function to solve this? Is it impossible with VLOOKUP? My 'real' document has like 2000 rows, and the solutions I found on Youtube was not good to scale.
Thanks in advance. I'm new to here so if I should clarify my question in any way, feel free to tell me.
If the raw is around 2,000 rows, you can use a nested index match with helper columns.
Add a rank in column C with the formula =COUNTIF(A2:$A$2,A2)
Then apply the same ranking in your output part as well (Ensure Activity Name is sorted so that the formula works), Output rank formula =IF(J2=J1,I1+1,1)
Formula that lists out the Product Code {=INDEX($B$2:$B$3190,MATCH(I2,IF($A$2:$A$3190=J2,$C$2:$C$3190),0))}
This is an array formula, you get the curly brackets by hitting control+shift+Enter instead of just Enter upon keying in the formula
If you are using excel 365, you can use UNIQUE formula.
=UNIQUE(A2:B18)

Excel VLOOKUP with multiple possible options in table array

I have two lists, the first is a set of users. The second list contains different encounter dates for these users.
I need to identify the date that is within 10 days of the "Renew Date" [Column C], but not before. With Member 1 this would be row 3 1/8/2017. With Member 2 this would be row 6, 1/21/2017.
Now using a VLOOKUP which the user before me who managed this spreadsheet obviously isn't viable as it's simply going to pickup the first date that has a matching Member ID. Is there a way to do this in Excel at all?
I have included a link to a sample file and a screenshoit of the sample data.
https://drive.google.com/file/d/0B5kjsJZFrUgFcUFTNFBzQzN4cm8/view?usp=sharing
To avoid the slowness and complexities of array formulas, you can try with SUMIFS but the problem is that if you have more than one match, it will add them, not return the first match. The sum will look like an aberration. Will work however if you are guaranateed that you have only one match in the data.
An alternative is also to use AVERAGEIFS, which, in case of multiple matches, will give you their average and it will look like a valid date and a good result. Enter this formula in D2 and fill down the column:
D2:
=AVERAGEIFS(G:G,F:F,A2,G:G,">="&C2,G:G,"<="&C2+10)
and don't forget to format column D as Date.
Try this
=SUMPRODUCT($G$2:$G$7,--($F$2:$F$7=A2),--($G$2:$G$7<=C2+10),--($G$2:$G$7>C2))
Format the result as date. See screenshot (my system uses DMY order)
Don't use whole column references with this formula. It will slow down the workbook.

Manipulate data base on Criteria

I am trying to create code that will help me achieve the correct format. All I want is to pull employee (EE) entire row and paste into a new sheet, and then second part (ER) value to match the same employee.
In other words, if employee pay pension contributions for 100 (Pen EE (Tal)) and employer pay for 200 (Pen ERS (Tal)) on behalf of the same employee. Then, the worksheet should look like Column A= Pers No, Column B=Employee Name, Column C= ID Number, Column D=PenPay, Column E=Pens EE(Tal) and Column F=Pens ER(Tal) and G= Total (Pen EE +Pen ER values), as exactly in example tab.
I hope this makes sense. I have tried several methods but no luck so far. Thank you all for your help.
From your problem description, I think I can decipher that you are using Excel.
I see three basic approaches to solving your problem:
The simplest approach is not to use VBA at all and instead use the workbook functions INDEX and MATCH. The latter returns the row or column where an exact match is found in the search range, which has to be one dimensional. (The exact match actually requires the search option 0.) The function INDEX returns the value at the given row and column in a range. Combining both, you get a more flexible verision of VLOOKUP and HLOOKUP, which you can use to find the values in the second table for a given employee. (MATCH returns an N/A error if no match is found.)
The second approach is to use the Excel object model in VBA. You can search a range for a value using the Find method of the range. This returns the cell where the match is found and Nothing in case there is no match. If the search result is not Nothing, you can use the EntireRow property to get the entire row and the Cells property to select cells in the row.
Finally, you can use the support of SQL for Excel via ADODB. For a description how to do this, you can look at this Microsoft page and this old question on SO. Provided you know how to write SQL queries, this should enable you to solve your problem via SQL.

Searching multiple Postcodes in Excel

I have an excel sheet with 8000 records that i would like to search by postcode.
This is my client list and i would like to say search for all clients living in the "EH1","EH2","KY1","SW9" postcodes.
I would like the search to return all the values related to that postcode.
The excel document is laid out like this.
(ID,Name,Surname,Address,Postcode,Telephone Number)
Im a novice at excel spreadsheets so any help on this would be greatly appreciated.
ID Name Surname Address Postcode Telephone number
26584 John Smith 69 Bedford road Eh12 5db 0131225689
Thanks
Edited with quick and dirty method:
If you only need to use this table a few times, then there is a quick and dirty method:
Make a helper column that only includes the first 3 characters of the postcode. You do this via the left function, specifying the postcode column in the first argument, then "3" in the next, to return the first 3 characters. This effectively hides the values you haven't ticked.
You then use the filter section at the top of the column once you have made it a table as stated earlier. In the drop down menu untick "Select all", then tick the values you want to see, i.e. the postcodes you are interested in).
You can then copy the visible cells only via Copy visible cells only if you want to use just that list.
A longer, but more robust method would involve three tables. The first is your data set as it is, with the helper column as discused above included. The second would be a simple single column of all the first three letter codes you are interested in. The third would be an array function modified from this formula:
=index($a$1:$b$7,small(if($a$1:$a$7=$a$10,ROW($a$1:$a$7)),ROW(1:1)),2)
which returns multiple items based on preset criteria, ignoring those that are not specified. I would link to a site explaining this better but I am such a new user I can hardly do anything it seems :(
I suggest you simply use an autofilter on the respective column.
Here is a short tutorial for Excel 2010: AUTOFILTER TUTORIAL
I think an easy way to do this is first make Postcode column first; from Column E to Column A.
Insert a new column in Column A, then use the left function to get the first 3 characters of the postcode: =LEFT(B1,3)
With this, you can use VLOOKUP to search for the postcodes "EH1","EH2","KY1","SW9", and use multiple VLOOKUP formulas to return a column index of everything.
You'll end up with a list of everything for that specific postcode.

Resources