Forum Discussion

RAdams's avatar
RAdams
Helper III
5 years ago
Solved

Flag Multiple Entries on Multiple Columns

I've got some Product Data that contains Product Code, UMseq and UM.    I'm only allowed to have one UM per ProductCode and UMSeq. In the example below, CRA286 and UMseq has two UM's. This is incor...
  • amitchandak's avatar
    5 years ago

    RAdams ,

    as column - this will flag all more than one rows
    flag = if(countx(filter(Table,[product] = earlier([product]) && [UMSeq] = earlier([UMSeq])),[um]) >1, True(), False())

    Measure

    use this with product or UMSeq or UM


    False = countx(filter(summarize(Table,[product],[UMSeq], "_1", calculate(count([UMSeq]),allexcept(Table,[product],[UMSeq]))),[_1]>1),[product])

  • v-jingzhang's avatar
    v-jingzhang
    5 years ago

    Hi RAdams 

     

    Count() and Countx() count the number of cells in a column that contain non-blank values. They will count the duplicate values. It seems your data has duplicate um values per productcode and umseq, so Distinctcount() is more suitable. Please try below column codes, this should work.

    flag = 
    IF (
        CALCULATE (
            DISTINCTCOUNT ( Table1[um] ),
            FILTER (
                Table1,
                Table1[productcode] = EARLIER ( Table1[productcode] )
                    && Table1[umseq] = EARLIER ( Table1[umseq] )
            )
        ) > 1,
        1,
        0
    )

     

     

    Please take note that DISTINCTCOUNT() will include the Blank value. If you have blank um value in your table and you want to count it as a distinct value, you could use DISTINCTCOUNT() as above. Otherwise if you don't want to count a blank value, you could use DISTINCTCOUNTNOBLANK() to replace DISTINCTCOUNT() in the codes.

     

    Best Regards,
    Community Support Team _ Jing Zhang
    If this post helps, please consider Accept it as the solution to help other members find it.