I believe the issue arise from the fact that
is not looking at partner specific data, neither FirstOrderYear, nor date_invoice filtered by Min qty,while I assume you expect exactely this.
But to help you more, you would need to describe your model much more detailed, best by uploading a sample QVF.
Try creating a field with that year in your script, maybe something like
min(dateinyears) as FirstOrderYear,
max(dateinyears) as LastOrderYear,
Min( If(qty>20, dateinyears)) as FirstWhateverYear
group by partner_id;
Then use this field in your comparison, like
count(DISTINCT If(FirstOrderYear=FirstWhateverYear, partner_id))
Thanks swuehl for your response.
That was my first approach but then the users want to define the value of No of units which here is hard-coded to 20. They want it to be flexible so that they define the conversion figure. That's the reason I am using a extension to get the user input into a variable "vUnits". But this variable which includes the user input can only be used at the chart level. I cant use it in the script for the calculation.
Any other suggestion would be helpful.