Pooping during sex

For a while now there have been many times when my husband and I are having sex. Right when I feel that I am about to come I poop. It is something that bothered me so much because I have no idea what is happening. Thankfully I have the best husband ever which is very loving and supportive and just wants me to be comfortable and feel good. I have tried pooping before having sex but when I least expect it it happens. Has this ever happened to anyone or does anyone have an idea of what causes it? I did make an appointment a the doctors but its still weeks away.