Chosen Solution

I bought my xbox one in 2015, It recently started to shut off randomly, it either takes a few hours to shut off or it takes 30 minutes. I thought that because dust could have collected in there for 2 years, I decided to use a compressed air can. It still has the same problem.

This issue could be dust buildup in the fan, as you said. Also, you may want to disassemble the power brick, as these buildup TONS of dust. Try this guide to get the power brick apart. If this does not help, try cleaning the fan as said in the second guide. Xbox One Power Brick (Day One Edition) Disassembly Xbox One Fan Replacement

You can find some additional ideas on the Xbox One Turns Itself Off page. Good luck!

I had the same issue but I noticed that it wasn’t the xbox shutting off first, it was the power brick. Try replacing the power brick/cord

I have the same thing but it gets really hot and when it just sits there it ends up over heating