Forum Discussion

mb0307's avatar
mb0307
Responsive Resident
5 years ago
Solved

Identify canceled items

Hi,   Table below shows order detials and in column Canceled Order value 2 represents the canceled order:   If Canceled Type is 2 then I want to find 1 value with the same Order Number, Ite...
  • v-alq-msft's avatar
    5 years ago

    Hi, mb0307 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

    Table:

     

    You may create an index column in Power Query and then create a calculated column as below.

    Result = 
    var tab = 
        CALCULATETABLE( 
                'Table',
                FILTER(
                    'Table',
                    [Canceled Order] = 2&&
                    [Order]=EARLIER('Table'[Order])&&
                    [Date]=EARLIER('Table'[Date])&&
                    [Item]=EARLIER('Table'[Item])&&
                    [Quantity]=EARLIER('Table'[Quantity])&&
                    [Batch]=EARLIER('Table'[Batch])
                )
        )
    var minindex = 
    CALCULATE(
        MIN('Table'[Index]),
        FILTER(
                    'Table',
                    [Order]=EARLIER('Table'[Order])&&
                    [Date]=EARLIER('Table'[Date])&&
                    [Item]=EARLIER('Table'[Item])&&
                    [Quantity]=EARLIER('Table'[Quantity])&&
                    [Batch]=EARLIER('Table'[Batch])&&
                    [Canceled Order]=EARLIER('Table'[Canceled Order])
        )
    )
    return
    IF(
        COUNTROWS(tab)>0&&[Index]=minindex,
        "REMOVE","KEEP"
    )

     

    Result:

     

    Best Regards

    Allan

     

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