0

I've got a (simplified) with 3 columns: Offer_name / Product_Name/ Offer_rating

I want to display, thanks to AMPScript, the best rated offered in my newsletter. However, I do not want to display a Product_Name twice.

I used the "de-duplicate row" code by https://sprignaturemoves.com/de-duplicate-rows-ampscript/
But instead of ordering my rows by Product_Name, I have to do it by Offer_rating
The results is that I can have the same Product_Name displayed several times in my email.
This is because only the prevproductname is stored and I would need to store prevproductname1, prevproductname2, etc.
Having a

@prevproduct@i

doesn't seem to work so I am a little stuck there.

Does any body had had the same issue?

Here are a sample of data ordered by offer_rating :


data sample and wanted output


  • Please provide a sample of the data your are retrieving and how you'd like it to show in the email. – Adam Spriggs Aug 3 '17 at 13:31
  • The solution on my blog only de-duplicates by the column you're sorting by in the lookup. – Adam Spriggs Aug 3 '17 at 13:32
  • Hi, I just added data sample and wanted output in my post – Emilie Aug 3 '17 at 14:53
1

Without your code, below is the best I can do to help solve your issue:

%%[
var @i, @rows, @row, @OfferRating, @prevOfferRating, @productName, @prevProductName, @rowsToReturn

var @rowsToReturn = 0 /* up to 2000 */

SET @rows = LookupOrderedRows("SubscriberProducts" ,@rowsToReturn, "OrderRating asc", "EmailAddress",emailaddr)

set @prevOfferRating = ""

FOR @i = 1 TO RowCount(@rows) DO

  set @row = Row(@rows,@i)
  set @OfferRating = Field(@row, "OfferRating")


  if empty(@prevOfferRating) or @OfferRating != @prevOfferRating then

     set @prevOfferRating = @OfferRating

     set @rows2 = LookupOrderedRows("SubscriberProducts" ,1, "productName asc", "EmailAddress",emailaddr)

        set @row2 = Row(@rows2,1)
        set @productName = Field(@row2, "productName")

        if empty(@prevProductName) or @productName != @prevProductName then

            set @prevProductName = @ProductName

        ]%%

            <h1>%%=v(@ProductName)=%%: %%=v(@OfferRating)=%%</h1>

        %%[ endif ]%%

    %%[ next @i ]%%

%%[ next @i ]%%

What this does is runs through two FOR statements with 2 IF statements to ensure both the Rate and Product are Unique. I have not tested it, but in theory it should handle this.

As the initial lookup is Order Rate asc meaning all dups should be in a row and as the productName (put to single item return based on Offer Rate and reduce render time) combined with an IF statement, it should limit the product name to a single instance as well.

This might need some tweaking to make it exactly fit into your needs, but it should at least lead you into the right direction.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.