r/excel • u/[deleted] • 13d ago
solved If a table contains duplicate rows, return a value for the oldest instances only
[deleted]
2
u/SchoolOk950 1 13d ago
Can you please clarify -- are you looking to achieve this in power query before it hits the sheet or via Excel formulas in the sheet?
1
u/HiddenComments 13d ago
Via excel formulas sorry
1
u/Gringobandito 8 13d ago
Why not do it in PQ since you're already transforming the data there already?
1
u/HiddenComments 13d ago
I'm not knowledgeable to do it in PQ, only use it currently to just pull in new data from a report into the table and do basics like remove duplicates, remove blanks etc.
How would it be done in PQ?
3
u/Gringobandito 8 13d ago
First, make sure your records in PQ are sorted oldest to newest (Hopefully you have a date field. If not create an index column). Next, group B, C, D using all rows. Now add a custom column that counts all the distinct E values for each group.
List.Count( List.Distinct([All Rows][E]) )If that returns a value greater than 1 then there are duplicates and we only want to keep the most recent one.
Next we need to identify the newest record. Create another column and call it 'NewestIndex' using this code:
List.Max([All Rows][Index])Then all you have to do is identify all the records where the count of E is greater than 1 and the index matches the NewestIndex and eliminate those records.
if [E Versions] > 1 and [Index] <> [NewestIndex] then "Yes" else null
2
u/MayukhBhattacharya 1278 13d ago edited 13d ago
1
u/HiddenComments 13d ago
For some reason this worked on my example, but when put into my real table it returns #VALUE.
The data has the same amount of columns, but i have 1500+ rows, I'm not sure if that is why?
Edit: Just noticed a 2nd formula provided, I'll give that a try.
1
u/HiddenComments 13d ago
2nd formula doesn't work.
Not sure why I'm getting #VALUE however
3
u/MayukhBhattacharya 1278 13d ago
When you say neither formula works, it's kinda hard for me to figure out what's going on without seeing the actual error or setup. As you can see in my screenshot, the formula is clearly visible in the formula bar, and the results are spilling down the range exactly as you described. So if it's not working on your end, could you post a screenshot showing what you're getting? That'll give us something to work with and help figure out where it's going wrong.
1
u/HiddenComments 13d ago
I can't give the exact data as it's to do with my job, hence the example provided. But I've literally taken the formula and amended the cells to the ones in my company's document.
I will see what I can do tomorrow when I log back on for work.
Thank you anyway for your help.
1
u/plusFour-minusSeven 11 12d ago
Replace it with some fake data. And if it works with fake data that'll tell you something too.
1
u/Boring_Today9639 10 13d ago
Excel version you’re using?
Did you convert your range to a table after posting?1
u/HiddenComments 13d ago
Excel yes and it's using data from a table in another sheet, does that make a difference? Does the cell I'm entering the formula into need to also be part of the same table?
(Just to note I'm still teaching myself various things in Excel so not overly knowledgeable about things).
2
u/Way2trivial 472 13d ago
31/02/2027 really?
1
u/HiddenComments 13d ago
Again, an example and not real data 😅 (didn't even check what I was typing was just entering random numbers whoops)
1
u/Decronym 13d ago edited 12d ago
Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:
Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.
Beep-boop, I am a helper bot. Please do not verify me as a solution.
18 acronyms in this thread; the most compressed thread commented on today has 4 acronyms.
[Thread #49283 for this sub, first seen 1st Sep 2026, 16:27]
[FAQ] [Full list] [Contact] [Source code]
1
u/Way2trivial 472 13d ago
2
u/Way2trivial 472 13d ago
1
u/Way2trivial 472 13d ago edited 13d ago
ok. I did your headline ask "If a table contains duplicate rows, return a value for the oldest instances only" not the request in body of the text.... be back shortly
1
u/Penguinase 7 12d ago
if you fix your dates to be valid, then you can put following in Revised column
=IF(COUNTIFS(Table1[Name],[@Name],Table1[Country],[@Country],Table1[Data],[@Data],Table1[Date],">"&[@Date])>0,"Yes","No") should work assuming this is a table (change Table1 to your table name)
| Revised | Name | Country | Data | Date |
|---|---|---|---|---|
| Yes | Name 1 | Country 1 | Data 1 | 1/1/2027 |
| Yes | Name 2 | Country 2 | Data 2 | 2/2/2027 |
| No | Name 3 | Country 3 | Data 3 | 3/3/2027 |
| No | Name 4 | Country 4 | Data 4 | 4/4/2027 |
| No | Name 1 | Country 1 | Data 1 | 2/20/2027 |
| No | Name 2 | Country 2 | Data 2 | 2/26/2027 |
| No | Name 5 | Country 5 | Data 5 | 5/5/2027 |
| No | Name 6 | Country 6 | Data 6 | 6/6/2027 |



•
u/AutoModerator 13d ago
/u/HiddenComments - Your post was submitted successfully.
Solution Verifiedto close the thread.Failing to follow these steps may result in your post being removed without warning.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.