Compare and print out the rows which meet the conditions - excel

I would like to compare the latest date for each Name, and only print out the result without duplication of Name, one Name only with latest PurchaseDate and Type. Any method can be used?
Example:
Name PurchaseDate Type
Alex 10-3-2011 A
Alex 3-7-2014 B
Alex 25-12-2013 C
Jim 27-2-2014 C
Jim 1-10-2012 D
Jim 2-3-2013 A
.
.
.
Expected Result:
Name PurchaseDate Type
Alex 3-7-2014 B
Jim 27-2-2014 C
.
.
.

Sort by Name and Purchase Date Oldest to Newest, add this formula:
=IF(A2<>A3,"keep","")
(say in D2 and copied down), filter and for column D in the example, check "keep" then print.

Related

formula to find value from two separate tables and based on values in three tables

I'm looking for a formula for the Party column in Table 3 that will produce its values based on the data contained in Table 1 and Table 2.
NumSelect value in Table 3 determines Party value in Table 3.
Where NumSelect has "p", it refers to data in Table 1. If no "p" in NumSelect, then it refers to Table 2.
Number in NumSelect refers to row number.
If the corresponding ShortName has a value, that value should be returned.
If the corresponding ShortName is blank, then the corresponding Name should be returned.
Uppercase "P" and lowercase "p" in the NumSelect should both point to Table 1.
Each table is an Excel Table and its rows may expand or contract.
Certain rows in Table 1 and Table 2 may be empty.
Formula should not be volatile, not require control+shift+enter to enter the formula, and not require VBA.
Thanks!
Sorry for the bad formatting. I had this question formatted perfectly, but Stack Overflow kept preventing me from posting it because it claimed, "Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon."
Table 1
Name
Gender
ShortName
Occupation
Grace Turner
F
Singer
Cadie Crawford
F
Tiger
Fine Artist
Paige Johnston
F
Archeologist
Dexter Payne
M
Klondike
Veterinarian
Valeria Barnes
F
Chef
Florrie Reed
F
Lawer
Emily Ferguson
F
Scientist
Sam Hawkins
M
Alpha
Biochemist
Savana Ellis
F
Cook
Table 2
Name
Gender
ShortName
Occupation
Vanessa Cooper
F
Producer
Jasmine Morris
F
Beta
Baker
Evelyn Taylor
F
Economist
Adelaide Roberts
F
Historian
Blake Cunningham
M
Lion
Chef
Adelaide Harrison
F
Chemist
Frederick Watson
M
Journalist
Table 3
NumSelect
Party
p2
Tiger
3
Evelyn Taylor
P8
Alpha
2
Beta
7
Frederick Watson
p7
Emily Ferguson
Long Formula
Your formula has 717 characters, this one has 347.
=IF(ISNUMBER(SEARCH("P",[#NumSelect])),
IF(INDEX(Table1[ShortName],VALUE(RIGHT([#NumSelect],1)))="",
INDEX(Table1[Name],VALUE(RIGHT([#NumSelect],1))),
INDEX(Table1[ShortName],VALUE(RIGHT([#NumSelect],1)))),
IF(INDEX(Table2[ShortName],[#NumSelect])="",
INDEX(Table2[Name],[#NumSelect]),
INDEX(Table2[ShortName],[#NumSelect])))
A pseudo-code could look like this:
=IF(ISNUMBER(A),IF(B="",C,B),IF(D="",E,D))
The issue is that B (lines 2 & 4) and D (lines 5 & 7) are repeated expressions.
Hopefully, this will help someone to make a major improvement.
Microsoft 365
Using the LET function, you could use the following:
=LET(iIndex,[#NumSelect],sIndex,VALUE(SUBSTITUTE(LOWER(iIndex),"p","")),
IF(LEN(iIndex)>LEN(sIndex),
LET(nShort,INDEX(Table1[ShortName],sIndex),nLong,INDEX(Table1[Name],sIndex),
IF(nShort="",nLong,nShort)),
LET(nShort,INDEX(Table2[ShortName],sIndex),nLong,INDEX(Table2[Name],sIndex),
IF(nShort="",nLong,nShort))))
Welp, I figured out the formula. But it's very inefficient. I'm sure someone here could make it a lot shorter and more efficient.
Here it is:
=IF(
INDEX(FILTER(CHOOSE(IF(LOWER(LEFT([#NumSelect],1))="p",1,2),Table1[[Name]:[ShortName]],Table2[[Name]:[ShortName]]),CHOOSE(IF(LOWER(LEFT([#NumSelect],1))="p",1,2),Table1[Name],Table2[Name])<>""),SUBSTITUTE(LOWER([#NumSelect]),"p",""),3)
=0,
INDEX(FILTER(CHOOSE(IF(LOWER(LEFT([#NumSelect],1))="p",1,2),Table1[[Name]:[ShortName]],Table2[[Name]:[ShortName]]),CHOOSE(IF(LOWER(LEFT([#NumSelect],1))="p",1,2),Table1[Name],Table2[Name])<>""),SUBSTITUTE(LOWER([#NumSelect]),"p",""),1),
INDEX(FILTER(CHOOSE(IF(LOWER(LEFT([#NumSelect],1))="p",1,2),Table1[[Name]:[ShortName]],Table2[[Name]:[ShortName]]),CHOOSE(IF(LOWER(LEFT([#NumSelect],1))="p",1,2),Table1[Name],Table2[Name])<>""),SUBSTITUTE(LOWER([#NumSelect]),"p",""),3)
)

How can I concatenate multiple fields in Excel?

What is the actual function to generate a single line output (Column I, #QR) from below fields?
+
A
B
C
D
E
F
G
H
I
1
f_name
l_name
designation
email
landline
mobile
country
web
#QR
2
John 
DOE
Senior Manager 
john.doe#gmail.com
4422688
444221
Sweden
google.com
BEGIN:VCARD\nVERSION:2.1\nFN:John Doe\nORG:Senior Manager - Google\nADR:Sweden\nTEL;WORK:4422688\nTEL;CELL:444221\nEMAIL:john.doe#gmail.com\nURL:google.lk\nEND:VCARD
There is a function "Textjoin" if you're using Excel 2019 or up:
=TEXTJOIN(" ",TRUE,A1:A2)
This would result into the string "f_nameJohn". You can look up more about this function here: https://support.microsoft.com/en-us/office/textjoin-function-357b449a-ec91-49d0-80c3-0e8fc845691c
You can also use:
=A2&B2
giving JohnDOE
Then you can do:
=A2&" "&B2
which will put a space between: John DOE
if you don't have Excel 2019 or up you can use:
=A2&" "&B2&" "&C2&" "&D2&" "&E2&" "&F2&" "&G2&" "&H2&" "&I2
or
=CONCATENATE(A2," ",B2," ",C2," ",D2," ",E2," ",F2," ",G2," ",H2," ",I2)

Use awk to replace one column value with another column value if the first letter is not a alphabet letter

I have the following csv file:
ID Name Gender NID
Y12 Jim M C12
Y23 David M C23
234 Bob M C22
2b1 Lucy F C24
2bb Lily F C25
What I want to do is to replace ID colunm's value with NID value if the first letter in ID is not a alphabet letter.
So the output is expected to be
ID Name Gender NID
Y12 Jim M C12
Y23 David M C23
C22 Bob M C22
C24 Lucy F C24
C25 Lily F C25
This is just a sample. My original data size is much bigger so I have to use awk. The key issue is how to specify the condition. I am not clear how to deal with.
The code I was thinking of is like awk -F, 'if $1 != ..., $1=$4'. I also googled but failed to find an appropriate solution.
Here is a link which I think may be helpful.
Filter lines that have only alphabets in first column. Thank you.
Use a regular expression.
awk '$1 ~ /^[^A-Z]/ { $1 = $4 }1' filename
DEMO
If you can count on the ID column always being 3 characters, this will preserve the table formatting:
awk '{ sub("^[^[:alpha:]]..", $4) } 1' file

Formula to determine latest ordered entry of unique table values

I'm looking for some help in creating a column populated with 1's for the (in this example) 'latest' revision of each unique entry (in another column).
Project # Rev Flag
=========================
FCA1 A
FCA1 D 1
FCA1 B
FCA1 B
FCA1 C
FCA1 C
BRS1 A
BRS1 B 1
BRS2 A 1
FCA2 A
FCA2 A
FCA2 B
FCA2 B
FCA2 C 1
FCA2 C 1
BRS3 A 1
FCA1 D 1
FCA1 D 1
FCA1 A
My desired output is in the 'Flag' column in the above example. For example, all Rev D's for project number FCA1 and all Rev C's for FCA2. Same thing for the other values under Project #. Note that I'd like this done independent of the order or sorting of the entries. The example just happens to show them in some sort of order for clarity.
I'm working with Excel 2010.
Thank you!
The formula you want is:
=IF(MAX(INDEX(($A$2:$A$20=$A2)*CODE($B$2:$B$20),0))=CODE($B2),1,"")
E.g.:
EDIT
Re the question how can I error handle when there is a blank entry in the Rev column? It's not possible if you are using A, B, C and D as revision codes because the CODE function won't handle an empty string in the formula I presented. If you switch to number-based revisions then it will work with this formula:
=IF(MAX(INDEX(($A$2:$A$20=$A2)*$B$2:$B$20,0))=$B2,1,"")
Noting that this is the same formula as above but without the CODE function usage. E.g. if A=1, B=2, C=3 and D=4 then:

Excel - Transposing unsorted items

So lets say that I have a table like this..
TID Person Type Name
1 Andy F Orange
2 Andy M Beef
3 Andy V Carrot
4 Andy V Spinach
5 Bobby M Ham
6 Bobby F Apple
7 Bobby V Carrot
I want to transpose it so that it will be sorted according to the Type, I want it to look like so
Person F M V
Andy Orange Beef Carrot
Bobby Apple Ham Carrot
How can I manage to do this? Oh, and I'll also point some stuff in case you guys missed it:
The Types have no particular order, if you notice Andy's, the order is F M V V, but Bobby's is M F V.
Multiple instances of Type may occur, just like in Andy's case, notice the double V. But even so, I want it so that the only V that counts is the first one, thats why in the transposed table, the V is Carrot, because the Carrot occurred first (the Spinach is ignored).
I dont know if I ask too much, but even just the gist of the solution would be very helpful for me. The main point of my question is to ask how can I transpose such unsorted items, whilst paying attention to the 1st point. The 2nd point is important too, but I can wait or ask later if you guys dont feel like answering.
Thanks for reading, please share me your knowledge.
The easisest/quickest way is to create a new column before the TID column which has this formula in it.
=[Person]&"_"&[Type]
For instance say your data started in column B, see screen shots (TID), then the first formula would be:
=C2&"_"&D2 and will result in Andy_F being created. Copy this down for all the names you have.
You should have something like this:
NEW TID Person Type Name
Andy_F 1 Andy F Orange
Andy_M 2 Andy M Beef
Andy_V 3 Andy V Carrot
Andy_V 4 Andy V Spinach
Bobby_M 5 Bobby M Ham
Bobby_F 6 Bobby F Apple
Bobby_V 7 Bobby V Carrot
Next, set up a table like this (using copy unique items, if necessary), with unique names on the vertical and Types along the horizontal:
F M V
Andy [form]
Bobby
Where [form] is a vlookup formula as in the screen shots below:
Resulting in the correct table for you, once the formula is copied to all cells in the new table:
Vlookup will grab the first item that matches its search critera, so multiple matches will be ignored.
The formula for Andy F in the table is VLOOKUP($G2&"_"&H$1,$A$2:$E$8,5,0), with the data as in the screen shots.
A better way might be to use VBA, but this should do the trick.

Resources