r/excel • u/HiddenComments • 14h ago
unsolved If a table contains duplicate rows, return a value for the oldest instances only
Not sure if anyone can help with this but I have a table similar to the image:
(sorry I can't put a photo in the post body as on mobile but here's a link to it)
Every month new data gets loaded in via Power Query.
I want to set up a formula where it will check if data from columns b to d are duplicates (shown in the image in yellow), if yes, it then checks column e to see if this data is unique to that row (ie. row 2 and 6 contain the same B-D data, but column E is different). If it is unique, it changes a revision/status in column a to "Yes" for any old instances.
Is this possible?
Thank you.
2
u/SchoolOk950 1 14h 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 14h ago
Via excel formulas sorry
1
u/Gringobandito 8 13h ago
Why not do it in PQ since you're already transforming the data there already?
1
u/HiddenComments 13h 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?
2
u/Gringobandito 8 12h 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 1265 14h ago edited 14h ago
1
u/HiddenComments 14h 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 14h ago
2nd formula doesn't work.
Not sure why I'm getting #VALUE however
3
u/MayukhBhattacharya 1265 13h 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 13h 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 5h 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 13h ago
Excel version you’re using?
Did you convert your range to a table after posting?1
u/HiddenComments 13h 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 13h ago
31/02/2027 really?
1
u/HiddenComments 13h 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 14h ago edited 4h 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 13h ago
2
u/Way2trivial 472 12h ago
1
u/Way2trivial 472 12h ago edited 12h 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 7h 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 14h 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.