Investors were worried about Amazon (AMZN -0.51%) when sales growth dipped in 2022 and the company posted its first annual loss in almost a decade. But if you followed Warren Buffett's advice to be greedy when others are fearful, your investment would be up almost 125% since the stock price bottomed out in early 2023.

Amazon is back in the market's favor now that sales growth is heating up and profitability is soaring. Even more, it has massive opportunities as it develops robust artificial intelligence (AI) services. With sales rising, Amazon could hit an important milestone this year.

Amazon is not the largest company in the world

Amazon is the second-largest company in the U.S. by sales, trailing only Walmart (WMT -0.83%).

AMZN Revenue (TTM) Chart

AMZN Revenue (TTM) data by YCharts.

It's the fourth-largest in the world, also behind Saudi Aramco and China's State Grid. But as you can see from the chart above, it's gaining on Walmart, and the gap is getting smaller all the time. Amazon typically reports higher sales growth than Walmart. Now that this growth is accelerating again, the e-tailer could overcome Walmart and become the biggest company in the world by sales very soon.

Let's consider some scenarios and see if it's going to happen this year.

Scenario No. 1: Management's guidance

Management is guiding for Amazon's sales to increase about 10% in the 2024 second quarter. It hasn't provided full-year guidance, so let's use that ballpark figure for the full year for this exercise.

Adding 10% to Amazon's 2023 full-year sales of $575 billion would bring the total to $632.5 billion, still less than Walmart's fiscal-year figure (for 2024, ended Jan. 31) of $648 billion. Walmart is expecting sales to increase about 3.5% in fiscal 2025. If that happens, it ends the year at $671 billion. That narrows the gap from $57 billion to $38 billion, but Walmart stays on top.

All other scenarios

Let's say Amazon's sales increased 13% in 2024, slightly more than the top of second-year guidance of 11%. That's $650 billion, just above Walmart's fiscal 2024 total. If Walmart's sales stay flat or decline, Amazon will slide into first place.

That's an unlikely event, but as Amazon Web Services (AWS) begins to accelerate again, it's a significant possibility that Amazon's full-year sales will exceed 10%. If Walmart exceeds expectations as well, it's likely to keep its top spot in 2024.

If Amazon reports anything below guidance, it's also unlikely to become the largest company in the world by sales in 2024. But Amazon generally meets or beats guidance, so this is another unlikely scenario.

Can Amazon overtake Walmart?

Amazon has several growth drivers right now. E-commerce is picking up speed, AWS is picking up clients, and advertising is its highest-growing segment, with tons of new opportunities as Amazon moves to ad-supported video streaming.

And the company's investments in AI are compelling. CEO Andy Jassy put it this way: "I don't know if any of us have seen a possibility like this in technology in a really long time, for sure, since the cloud, perhaps since the internet."

What Walmart has going for it is its base size, which is so large that despite Amazon's sales growth outdoing Walmart's, the e-tailer has yet to overtake the big-box store. And Walmart is still growing. It owns a strong brand and growth drivers in new stores and products. For example, it recently launched a new brand called Better Goods aimed at attracting higher-income shoppers. It hasn't been easy to knock Walmart off its perch in the past, and it's not going to be easy this year either.

There is a small chance that Amazon overtakes Walmart in 2024. And otherwise, it will probably get there in the next few years.