Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Conditional deduplication based on multiple columns

Hi everyone,   I need to write a very specific deduplication query and I am wondering if you can help me out. We have an ecommerce site and I am getting a daily CSV file that has transactional info...
  • Anonymous's avatar
    Anonymous
    4 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 Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.