Excel Grouping and Logic

83dons

New Member
Joined
Apr 1, 2019
Messages
6
I have some data in Excel. This is already sorted into the correct order. I require to set the value in a new column to true if it is either a solo record (ie only one distinct ID#) or if there are several entries for that same ID# then set the last one listed to True and the other ones above for that ID# to False. For example:

ID# New Column

001 True
002 True
003 False
003 True
004 False
004 False
004 True
005 True

I need to be able to apply a cell formula to the Excel sheet to auto generate this new column or to run a macro to populate the column. Any help appreciated as this is beyond my skills with Excel!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi & welcome to MrExcel
How about
=COUNTIF(A$1:A1,A1)=COUNTIF(A:A,A1)
 
Upvote 0
Say your first value is in cell A2. Place this formula in B2 and copy down:
Code:
=IF(A2=A3,"False","True")
 
Upvote 0
Hi & welcome to MrExcel
How about
=COUNTIF(A$1:A1,A1)=COUNTIF(A:A,A1)

Hi this works if you use A2 instead of A1 as there is the heading row first. Can you explain the logic of what this formula is doing just so I understand it better?
 
Upvote 0
This part counts how many times A1 occurs anywhere in col A
COUNTIF(A:A,A1)
This part counts how many times the cell value occurs between row 1 & the current row
COUNTIF(A$1:A1,A1)
If one equals the other the formula returns TRUE, otherwise it returns FALSE
 
Upvote 0
Note that if your values in column A are sorted first (like you say that they are), it isn't necessary to count them all and compare to the count so far.
What you simply want is the last instance of each value to be True and the rest to be False. So all you really need to do is check to see if the current value is the same as the value just below it.
If it is, then it is NOT the last value, and should return FALSE.
If is not the same as the value below it, then it is the last of those values and should be TRUE.

That is the very simple logic of the formula I posted.
 
Last edited:
Upvote 0
Note that if your values in column A are sorted first (like you say that they are), it isn't necessary to count them all and compare to the count so far.
What you simply want is the last instance of each value to be True and the rest to be False. So all you really need to do is check to see if the current value is the same as the value just below it.
If it is, then it is NOT the last value, and should return FALSE.
If is not the same as the value below it, then it is the last of those values and should be TRUE.

That is the very simple logic of the formula I posted.

Hi yes you are right I just tried it your way and compared it to the previous way it returns the same results. Your way is also much quicker as it is less of a drain on resources I would think. Thanks for replying.
 
Upvote 0
Your way is also much quicker as it is less of a drain on resources I would think. Thanks for replying.
Yes, I would think it would use less resources too.

However, if your data was NOT sorted, that way would work, where mine would not (just something to keep in mind, should that situation ever arise).
 
Upvote 0
Ok thanks we have to apply a sort to the spreadsheet first as it is this that places it in the correct order so your option is best for us.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top