1 Reply Latest reply on Mar 26, 2020 8:02 AM by Joshua Milligan

    Tableau Prep - identify the first duplicate item

    Kenny Wong

      Hi Community


      I have some items as shown above which is duplicate and I would like to count the first occurrence of those duplicate item only. Is it possible to label the first item with 1 and the remaining item with 0 in Tableau Prep?


      Any help will be appreciated.


      Thank you.



        • 1. Re: Tableau Prep - identify the first duplicate item
          Joshua Milligan

          Hi Kenny,


          If you are using 2020.1 or later, you can use the Row_Number() function.  In your case, you'll want to specify the calculation as something like:


          { PARTITION [Target Location],[Ref #] : {  ORDERBY [Target Location] : ROW_NUMBER()}}


          That will cause the rows numbers to restart for every new Locaiton and Ref #, with results like this:



          If you want to replace anything > 1 with 0, that's another easy calculation:


          IF [Row Number] > 1 THEN 0 ELSE 1 END



          Hope that helps!