
Alex F. answered 11/05/21
A lifetime of experience
I realize this might be old, but for anyone coming across this who might be interested in a solution using cell functions, this is something you can do only if your table is sorted by column B (session ID) as you have it in your example. There are other solutions if the table is unsorted, but they start to complicated real fast.
Anyways, here are two solutions for a sorted table where session ID is in column B:
=IF(AND(B2=B1,B2=B3),"FALSE",IF(AND(B2=B1,B2<>B3),"Last",IF(AND(B2<>B1,B2=B3),"First","First and Last")))
=IF(COUNTIF(B$1:B1,B2)=0,"First",IF(COUNTIF(B3:B$1000,B2)=0,"Last",FALSE))
Combining IFs with ANDs and ORs allows you to build what is often called a case statement where you can set a value based on your logic. In the first example, the formula simply compares the session ID to the ID above and below it, and chooses which value to have. The second example uses COUNTIF() but is essentially doing the same thing -- checking if the given session ID is in the column above or below it and assigning a value appropriately.
Patrick B.
Chiranjit notice his answer is using VBA , which is a PROGRAMMING LAGUAGE. Although EXCEL is rich with various built-in functions, the problem you are asking requires TWO different logical tests per row, one to check the next row and one to check the previous row. You CANNOT have two formulas in the same cell. THerefore, the problem requires a programming language like VBA or Java, which I have provided awhile back. You are going to have to decide which programming language you want to use in your solution. If you want VBA, the Derrick has expressed his interest in helping you. If you want the Java, please reach out to me via email by clicking on my profile picture and then the email link that appears on my page. Thanks and good luck.08/15/21