2

I'd like to insert content based on a user's last entry within a Data Extension; that is, if a user looked at five products over five days, I want to use the most recent product to insert content. The Data Extension is a transactional DB in that all the records are present - so how do I write the AMPscript to review all the rows but only action on the most recent one?

1

I'm going with the assumption you have a field in your Data Extension that has a date data type. I'll call it ViewDate

You'll need to use the LookupOrderedRows AMPscript Function and do something like this:

%%[

SET @rowset = LookupOrderedRows("MYDENAME, 1,"ViewDate Desc","SubscriberKey", SubscriberKey)

IF RowCount(@rowset) > 0 THEN

SET @productName = FIELD(ROW(@rowset, 1), "ProductName")

ENDIF

]%%

I'm looking up the Data Extension and retrieving only 1 row, where the SubscriberKey matches and the latest ViewDate. I'm then creating a variable that will be populated with the Product's name.

| 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.