It's usually a good idea to purchase a property when you know you'll remain in a location for 10 years or more. In addition, consider buying if you think you can get the property at a below-market price. In that case, the invested equity, debt service and tax benefits to the owner can make owning more advantageous than leasing.
A good broker should be able to perform a lease vs. purchase cost analysis that will help inform your decision. But always double check with a tax consultant to make sure your decision is beneficial from a tax perspective.
Aside from general office space, specialized industries such as manufacturing or life sciences that have heavy and unique infrastructure requirements are generally better off buying their space. If you have to spend a lot of money to outfit a building to meet your needs, you want to own those improvements. Warehouse and distribution facilities, on the other hand, are interchangeable and can usually be leased cost-effectively.