Chiranjit M.

asked • 08/14/21

Assign value to First and Last row of each group.

This is My Table


+------------------------+

| id | session ID | bal |

+------------------------+

| 0 | 00000002 | 100 |

| 1 | 00000002 | 120 |

| 2 | 00000002 | 140 |

| 3 | 00000001 | 900 |

| 4 | 00000001 | 800 |

| 5 | 00000001 | 500 |

+------------------------+

result Want

+------------------------+

| id | session ID | bal | Assign

+------------------------+

| 0 | 00000002 | 100 | First |

| 1 | 00000002 | 120 | False |

| 2 | 00000002 | 140 | Last |

| 3 | 00000001 | 900 | First |

| 4 | 00000001 | 800 | False |

| 5 | 00000001 | 500 | Last |

+------------------------+

2 Answers By Expert Tutors

By:

Alex F. answered • 11/05/21

Tutor
5 (33)

A lifetime of experience

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.
Report

08/15/21

Alex F.

Respectfully disagree with the statement that excel cannot handle two different logic tests per row -- you can stack many tests together using things like nested IF() statements, AND(), OR(), and many other functions. VBA or another programming language can give robust solutions to this problem, but there are plenty of quick excel function-based workarounds for this.
Report

11/05/21

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.