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?
Attribution to: George
Possible Suggestion/Solution #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.
Attribution to: Amtera
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32479