HI,
Is your time is of KF type ? If not then you need to make a KF of type time at modeling level and map it with the field which gives time related data.
At Query level you need to make a new selection ---time kf---drag and drop--0calyear---restrict with user input variable.
Now create a formula as you described above.
Hope this helps.
Regards,
AL