Using Custom formula to create a bar chart

Below mention formula is calculating three consecutive visits.
Naming it xyz to store the value.

ifelse((distinct_countIf({Rank Appt},{Rank Appt}=1))<>1,ifelse(lag({Rank Appt}, [{Rank Appt} ASC],2)=1,3, NULL),NULL).

When i am dropping this in bar chart , it is giving me an Error
Table calculation attribute reference are missing infield wells.

Hi @Abhishek_24 Can you please include a sample of your dataset (synthetic data. Plz do not share production data) and then provide a description of what you are trying to achieve?

HI @Abhishek_24
could you solve your problem?
I guees you need to bring the fields of your rank calculation into the visual.
BR