I sold my holdings today of X stock and again bought same X stock with lesser than sold quantity numbers. Can you please let me know how is the average price of the stock is calculated by giving me example for the same.

It will not affect the buy avg price.

Ex : You had purchased abc comapny - 100 shares @ Rs 10.

Now, on T+2 day, you first sold 100 shares @ Rs 20. Then, you bought 50 shares @ Rs 15. So, the 50 shares sold and bought will be considered as an intraday transaction for which you would have earned a profit of Rs 5/share. Then, the remaining 50 shares would be sold @ Rs 20 from your holdings.

Hence, at the end of the day your holdings would display :

ABC company - 50 shares @ Rs 10