with max (and other aggregation) you need to group by (as in SQL)
I also added a Max to MonthStart
Max(createdon) as createdon, //Error when this code is active...
Max(Num(MonthStart(addmonths(today(),-18)))) as Month
FROM [..............Filteredlog.qvd] (qvd)
Where createdon < MonthStart(Addmonths(today(),-17))
group by log_opportunityid;
It seems to be very close to working. But I run this in a loop where I go from 24 months back in time and up til today. And it seems like the code errors after six months in the loop, i wonder if it has to do with the createdon date not matching the criterias in the loop, but i'm not sure.