Here at the Fool, we preach the merits of long-term investing, a strategy also touted by legendary investor Warren Buffett. In fact, Buffett has said that when he finds a stock he likes for Berkshire Hathaway (NYSE:BRK-A) (NYSE:BRK-B), his favorite holding period is "forever." Therefore, it's been surprising to see Buffett sell some rather large positions over the past year, namely in IBM (NYSE:IBM), and Walmart (NYSE:WMT).

What could have compelled Buffett to exit these previous high-conviction picks? The answer in both cases is the same: Amazon (NASDAQ:AMZN). The fact that one company can throw a wrench into the investments of the world's most famous investor, and in two different sectors, shows just how disruptive Amazon has become. Here's how the Jeff Bezos-led company challenged Buffett's thinking on both companies, and what the rise of Amazon means for your investments.

a die with words Buy Sell and Hold on three different sides next to a pile of one hundred dollar bills.

Image source: Getty Images.

Walmart

"Retailing is just too tough for me," Buffett said in a CNBC interview last year. "We bought a department store in 1966, and I got my head handed to me." Of course, Buffett is being a bit modest -- he's also scored some big wins in smaller specialty retailers such as the Nebraska Furniture Mart and See's Candies, both of which Berkshire bought long ago and wholly owns.

Buffett thought that luck would continue when he bought Walmart in 2005, when Amazon was much smaller.  But in the fourth quarter 2016, the Oracle hit the "sell" button. Buffett wound up doing OK on his Walmart investment, though he didn't beat the market over that time.

WMT 10 Year Total Returns (Daily) Chart

WMT 10-Year Total Returns (Daily) data by YCharts.

Of his Walmart exit, Buffett said:

I think that Amazon in particular is an entity that's gonna have everybody in their sights ... they've got delighted customers. And it's extraordinary what they've accomplished. And a lot of people the delivery, you know, and that is a tough, tough, tough, competitive force. Now, Walmart's pushing forward online themselves and they've got all kinds of strengths. But I just decided that I'd look for a little easier game. 

Even Walmart's old CEO Mike Duke has said his big regret was not investing in e-commerce sooner, a sin for which current CEO Doug McMillon is still atoning, spending $3 billion on Jet.com in 2016, and vowing to greatly expand Walmart's fulfillment centers in the years ahead.

That will mean spending lots of money to potentially make lower margins. And while Walmart's stock actually took off after Buffett's sale last year, it recently fell back to earth after a tough fourth quarter showed increasing margin pressure.

Walmart might be able to pull off a challenge to Amazon, but success is not assured. As someone who likes to invest in near-certain winners, Buffett decided to leave for greener pastures. 

IBM

More recently, Buffett revealed he'd sold almost all of Berkshire's stake in IBM.  Buffett has always said that he had never understood technology, therefore many were surprised when Buffett announced the IBM investment back in 2011. That investment has not worked out, with the stock lagging well behind the current bull market.

SPY 5 Year Total Returns (Daily) Chart

SPY 5-Year Total Returns (Daily) data by YCharts.

Last year, Buffett said he'd rethought the investment and valued IBM "somewhat lower." The reason? Amazon Web Service's cloud computing:

[T]he cloud came along. And one of the most extraordinary things I've ever seen in business is when an unrelated type company -- a retailer, you can call Amazon of that type -- goes into another big industry and sees the future in it, gets into it, and then they gave -- and Jeff Bezos would say this, he said it on the Charlie Rose show, some time ago -- he got this amazing runway ... here are all these 200 IQ people, you know, in that business, and they gave him year, after year, after year. It wasn't a secret of what he was doing. And he was, in an important way, revolutionizing the industry, and the other people sat on their hands, basically. 

Of course, like Walmart, IBM has shown some signs of life recently. Still, Buffett sees a long battle ahead against Amazon in a field he doesn't know well and thought it a good time to exit.

Nothing to buy?

Since Amazon has been called "The Everything Store," you may be wondering if there's anything you can buy that Amazon can't touch.

Well, Amazon doesn't do everything and has had failures, most notably its Fire Phone, which it launched in 2014. For whatever reason, the Fire Phone couldn't catch on in an industry dominated by established heavyweights, and the company shuttered the Fire Phone in late 2015.

The very next year, Buffett began buying smartphone giant Apple, which has already become his second-largest public stock holding. 

John Mackey, CEO of Whole Foods Market, an Amazon subsidiary, is a member of The Motley Fool's board of directors. Billy Duberstein owns shares of Amazon, Apple, and IBM. His clients may own shares in the companies mentioned. The Motley Fool owns shares of and recommends Amazon, Apple, and Berkshire Hathaway (B shares). The Motley Fool is short shares of IBM and has the following options: long January 2020 $150 calls on Apple and short January 2020 $155 calls on Apple. The Motley Fool has a disclosure policy.