Forum Discussion
Conditional deduplication based on multiple columns
- Anonymous4 years ago
Hi Anonymous
Try this code.
Remove Duplicate = SUMMARIZE ( FILTER ( 'Table', IF ( VAR _COUNTROW = CALCULATE ( COUNTROWS ( 'Table' ), FILTER ( ALL ( 'Table' ), 'Table'[Master Order Number] = EARLIER ( 'Table'[Master Order Number] ) && 'Table'[Item ID] = EARLIER ( 'Table'[Item ID] ) ) ) RETURN _COUNTROW > 1, 'Table'[RANK] <> 1 || 'Table'[Invoice Date] <> BLANK (), 'Table'[RANK] = 1 ) ), 'Table'[Order Number], 'Table'[Master Order Number], 'Table'[Order Date], 'Table'[Invoice Date], 'Table'[Item ID] )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
lbendlin thanks for the reply.
Table 1: Sample of data before filter showing all the order IDs within Master Order # 10034858.
| Order Number | Master Order Number | Order Date | Invoice Date | Item ID |
| 10034858 | 10034858 | 7/12/2021 | CA-ST-EA | |
| 10034858 | 10034858 | 7/12/2021 | CA-BB-CS | |
| 10034858 | 10034858 | 7/12/2021 | CC-USR-04 | |
| 10034858 | 10034858 | 7/12/2021 | CC-UPTP-04 | |
| 20405998 | 10034858 | 7/12/2021 | FP-20EHH-CS | |
| 20405999 | 10034858 | 7/12/2021 | 3M-SGCUP-01 | |
| 10034858 | 10034858 | 7/12/2021 | 7/13/2021 | CC-USR-04 |
| 10034858 | 10034858 | 7/12/2021 | 7/13/2021 | CC-UPTP-04 |
| 10034858 | 10034858 | 7/12/2021 | 7/13/2021 | CA-ST-EA |
| 10034858 | 10034858 | 7/12/2021 | 7/13/2021 | CA-BB-CS |
| 20405998 | 10034858 | 7/12/2021 | 7/13/2021 | FP-20EHH-CS |
| 20405999 | 10034858 | 7/12/2021 | 7/13/2021 | 3M-SGCUP-01 |
Table 2: Data after filter applied; duplicate order IDs within Master Order # 10034858 WHERE Invoice Date = NULL have been removed.
(Remember I want this logic to look within all Master Order #s. I have just filtered down to one Master Order # to simplify the example output.)
| Order Number | Master Order Number | Order Date | Invoice Date | Item ID |
| 10034858 | 10034858 | 7/12/2021 | 7/13/2021 | CC-USR-04 |
| 10034858 | 10034858 | 7/12/2021 | 7/13/2021 | CC-UPTP-04 |
| 10034858 | 10034858 | 7/12/2021 | 7/13/2021 | CA-ST-EA |
| 10034858 | 10034858 | 7/12/2021 | 7/13/2021 | CA-BB-CS |
| 20405998 | 10034858 | 7/12/2021 | 7/13/2021 | FP-20EHH-CS |
| 20405999 | 10034858 | 7/12/2021 | 7/13/2021 | 3M-SGCUP-01 |
Thanks again.
Hi Anonymous
Try this rank code.
RANK =
RANKX (
FILTER (
'Table',
'Table'[Order Number] = EARLIER ( 'Table'[Order Number] )
&& 'Table'[Master Order Number] = EARLIER ( 'Table'[Master Order Number] )
&& 'Table'[Item ID] = EARLIER ( 'Table'[Item ID] )
&& 'Table'[Order Date] = EARLIER ( 'Table'[Order Date] )
),
'Table'[Invoice Date],
,
ASC
)
This code will create a rank based on each [Order Number],[Master Order Number],[Order Date] and [Item ID] group.
Then create a new dax table to remove rank =1.
Remove Duplicate =
SUMMARIZE(FILTER('Table','Table'[RANK]<>1),'Table'[Order Number],'Table'[Master Order Number],'Table'[Order Date],'Table'[Invoice Date],'Table'[Item ID])
Result is as below.
Or you can calcualte sum directly by add rank<>1 in your table filter. You don't need to create a new table.
Such as:
Measure = CALCULATE(SUM([Sales],Filter('Table',[Rank]<>1))
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.