Forum Discussion
Create new Table and eliminate duplicate based on more values/columns with Unique row ID
Hi everyone,
as usual, i am sorry this question has been asked already.
I have a table (Table1) with a column of unique values per row (ServiceID), and then columns such as Date, Timestamp, Username and Brand.
The goal is to create a table (Table2) which eliminated the duplicate of Username and Brand, based on the latest Time. I need to keep at least one row per Username and Brand, associated, and the ServiceID is my commune value to setup relationships with other tables. I hope you can help
Table1:
| ServiceID | Date | Time | Username | Brand |
| 456 | 14-3-2020 | 3:54:21 | User2 | Opel |
| 432 | 14-3-2020 | 3:54:34 | User2 | Fiat |
| 547 | 14-3-2020 | 3:55:05 | User3 | Toyota |
| 965 | 14-3-2020 | 3:55:23 | User3 | Fiat |
| 232 | 14-3-2020 | 6:23:11 | User4 | Toyota |
| 455 | 14-3-2020 | 6:23:32 | User4 | Kia |
| 233 | 14-3-2020 | 6:23:56 | User4 | Toyota |
| 111 | 14-3-2020 | 2:45:45 | User5 | Suzuki |
| 675 | 14-3-2020 | 2:45:52 | User5 | Suzuki |
| 827 | 14-3-2020 | 2:46:01 | User5 | Ford |
| 956 | 15-3-2020 | 15:03:10 | User6 | Volvo |
| 342 | 15-3-2020 | 15:03:25 | User6 | Volvo |
| 650 | 15-3-2020 | 15:03:41 | User6 | Volvo |
| 403 | 15-3-2020 | 13:02:32 | User7 | BMW |
| 421 | 15-3-2020 | 13:02:48 | User7 | Ford |
| 721 | 16-3-2020 | 9:00:17 | User8 | Renault |
| 531 | 16-3-2020 | 11:08:22 | User9 | Fiat |
| 211 | 16-3-2020 | 11:08:35 | User9 | AlfaRomeo |
| 116 | 16-3-2020 | 11:08:50 | User9 | AlfaRomeo |
| 320 | 16-3-2020 | 11:09:03 | User9 | Fiat |
Expected Table or Table2:
| ServiceID | Date | Time | Username | Brand |
| 456 | 14-3-2020 | 3:54:21 | User2 | Opel |
| 432 | 14-3-2020 | 3:54:34 | User2 | Fiat |
| 547 | 14-3-2020 | 3:55:05 | User3 | Toyota |
| 965 | 14-3-2020 | 3:55:23 | User3 | Fiat |
| 455 | 14-3-2020 | 6:23:32 | User4 | Kia |
| 233 | 14-3-2020 | 6:23:56 | User4 | Toyota |
| 675 | 14-3-2020 | 2:45:52 | User5 | Suzuki |
| 827 | 14-3-2020 | 2:46:01 | User5 | Ford |
| 650 | 15-3-2020 | 15:03:41 | User6 | Volvo |
| 403 | 15-3-2020 | 13:02:32 | User7 | BMW |
| 421 | 15-3-2020 | 13:02:48 | User7 | Ford |
| 721 | 16-3-2020 | 9:00:17 | User8 | Renault |
| 116 | 16-3-2020 | 11:08:50 | User9 | AlfaRomeo |
| 320 | 16-3-2020 | 11:09:03 | User9 | Fiat |
Thanks, Andrea
Just use this formula to create a new table
New Table = FILTER('Table',CALCULATE(MAX('Table'[Time]),FILTER('Table','Table'[Username]=EARLIER('Table'[Username])&&'Table'[Brand]=EARLIER('Table'[Brand])))=[Time])Result:
and here is sample pbix file, please try it.
Regards,
Lin
2 Replies
- AnonymousNot applicable
Hey AndreaPiscitell
First, create a reference of the original query in Query Editor.
Next, create a calculated column with the follow dax:
Username/Brand = CONCATENATE(Table2[Username],Table2[Brand])
https://docs.microsoft.com/en-us/dax/concatenate-function-dax
Then you can remove duplicates in this column. If you have it sorted by date oldest to newest it should keep the old (first instance in table) and remove the older ones. Doing it this way will allow the table to update and keep the new oldest date whenever you refresh. Also, since you still have the Service ID you can just use the MAX function to find the max date for the Service ID in table 1 if necessary.
If this helps please kudo.
If this solves your problem please accept it as a solution.
- v-lili6-msft
Community Support
Just use this formula to create a new table
New Table = FILTER('Table',CALCULATE(MAX('Table'[Time]),FILTER('Table','Table'[Username]=EARLIER('Table'[Username])&&'Table'[Brand]=EARLIER('Table'[Brand])))=[Time])Result:
and here is sample pbix file, please try it.
Regards,
Lin