0

I have created a DE with a date_submit field added so when a contact gets added the time stamp is automatically in there mm/dd/yy/sec.

I have a ampscript lookup where it is working fine in showing all the records.

%%[
var @rows, @row, @rowCount, @i

set @rows = LookupRows('DE-test','List_name','segment_1')
set @rowCount = rowcount(@rows)

if @rowCount > 0 then

  for @i = 1 to @rowCount do

                    var @emailAddress, @subscriber_key
                    set @row = row(@rows, @i) /* get row based on counter */
                    set @name = field(@row,"Name")
                    set @emailAddress = field(@row,"Email")
                    set @phone = field(@row,"Phone")
                    set @pdate = field(@row,"Available Date")
                    set @date_submitted = field(@row,"date_submitted")

]%%

I was wondering is it possible to show only the latest entry instead of all the records?

I know I have added in the date_submitted field to the code below but now sure how to add in the filter logic where it will only pull the recent contact.

set @rows = LookupRows('DE-test','date_submitted','')
3

You will have to use the function LookupOrderedRows that returns a set of ordered rows from a Data Extension.

set @rows = LookupOrderedRows("DE-test", 0, "date_submitted desc", "List_name","segment_1")
0
1

You would need to use the lookuporderrows() function.

Set @rows2 = LookupOrderedRows("Cars",4,"Horsepower Desc","MPG",Field(@cardata,"MPG"))

Returns a specified number of rows. You can specify multiple additional field and value pairs as part of an AND clause. The function returns an empty set when no values match.

1

I think LookupOrderedRows can solve your request to descending your row and bring from latest entries first.

You can also try this way to get your entries from last to the beginning;

set @rows = LookupRows('DE-test','List_name','segment_1 DESC')

Or you need to transform your LookUpRows with LookupOrderedRows: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/lookuporderedrows.htm

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.