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.
Hi Anonymous, thank you so much for the reply and for taking the time to help me out. I think this gets me closer but it's not quite what I need. I may not have explained it very clearly, but I only want to suppress rows when the following conditions are met:
- There are duplicate Item IDs within a Master Order # AND those duplicate Item IDs contain a blank/NULL invoice date.
So consider the screenshot below. The ones highlighted in green should be removed, and the white ones left alone, which your script did perfectly.
But the yellow ones I highlighted, which are part of a different Master Order #, should not be removed because they do not have duplicate Item IDs nor do they have a blank Invoice Date. So I don't want to remove the yellow rows. Does this help clarify what I am asking for?
Hi Anonymous
Add a filter in calculated table code.
Remove Duplicate =
SUMMARIZE (
FILTER ( 'Table', OR ( 'Table'[RANK] <> 1, 'Table'[Invoice Date] <> BLANK () ) ),
'Table'[Order Number],
'Table'[Master Order Number],
'Table'[Order Date],
'Table'[Invoice Date],
'Table'[Item ID]
)
Result is as below.
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.
- Anonymous4 years agoNot applicable
Anonymous -- even closer but one thing is still missing. I still want to count orders that were placed but not yet invoiced. Only when there were duplicate Item IDs within a Master Order # that had blank Invoice Dates did I want to discard them from the total.
Consider the Master Order # below, #10007106. It does not have an invoice date (yet) but does not have any duplicate Item IDs. In other words, it has not yet been invoiced but has not been double counted. It should still be counted in total sales (I created a separate metric for invoiced sales).
So how could I modify either the deduplication table or the rank column to account for this? Again, thanks for all your help and for sticking with me on this one.
- Anonymous4 years agoNot applicable
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.
- Anonymous4 years agoNot applicable
Thank you very much Anonymous this has done the trick. Appreciate your expertise and assistance.