You can do something like below..
First load your original table...
Load Count(Distinct Year) as TotalYear;
Load FieldValue('Calendar year',RecNo()) as Year
AutoGenerate FieldValueCount('Calendar year');
Let vTotalYear = Peek('TotalYear',0,'Temp');
Drop Table Temp;
IF vTotalYear = 0 THEN
Drop Table Data;
Load your data.....
Thanks for your code. I think it's working when vTotalYear = 0 is tested true. However, it's possible that there's the field 'Calendar year' doesn't exist. and under that condition, it should go to else statement.. But the code is giving a field not found error. Any idea how to adjust the code?