Set variable to 0 if changes were made

In my form, i need to calculate a respondent rating. Every time they upload a photo of a different certificate they get +1. It works. The issue: when a user has uploaded a wrong photo and then delete it, or changing the previous answer, the variable still has value +1.
The question is how to setup or create a formula that will set this var equals zero if a photo was deleted? Thanx!

Welcome to the community, @maznytskano! Maybe try sharing your XLSForm (only the selected part) so that the community should be able to help you out.

@Kal_Lam It is a common code, if/then cycle, but if i will change the answer after uploading a picture, the variable doesn’t change.
Let me explain.
calculate A1=0
user uploaded a file
note ${A1}

next question

and then user decided to change their mind and delete that uploaded file
but A1=1, it does not recount again…