Return distinct values in a for loop


In a print format, I’m trying to return distinct/unique values only from a loop. For example, for each item row in a purchase order item table I would like to return the corresponding material request number but only as a set.

So if there are 5 items with MREQ values PO-00001, PO-00001, PO-00001, PO-00002 and PO-00003, I would like to return PO-00001, PO-00002 and PO-00003 only. I tried using the set() function but couldn’t figure it out.