One of the best-performing stocks in this millennium has been Amazon (AMZN 0.58%). An investment of $30,000 in Amazon at the start of 2000 would have made you a millionaire now, but if you started with a smaller position and consistently added to it along the way, you may have achieved this feat as well.

With Amazon worth around $1.5 trillion, it's basically impossible to repeat its performance. However, Amazon's stock still looks like an attractive investment now and may accelerate your goal of becoming a millionaire by adding it to your portfolio.

Amazon's business shift has positively affected its financials

What made Amazon rise to prominence over the past two decades is not what is driving the company now. Although its online stores segment is still the largest part of its business, it hasn't done particularly well lately. Instead, Amazon is focused more on equipping third-party sellers to use its platform. As an illustration of this switch, Amazon's online store revenue grew by only 7% in the third quarter (the best over the past four quarters), while third-party seller services increased by 20%.

Amazon's switch to equipping sellers instead of selling the products themselves is smart as it doesn't require Amazon to source and maintain the inventory. That falls onto the seller's plate, and it's a move shareholders should be applauding.

Also, Amazon is expanding into other areas, like advertising, which has grown drastically to become a significant part of the company (advertising made up 8.4% of revenue in Q3). This was also Amazon's fastest-growing segment, increasing at a 26% year-over-year clip.

But the main takeaway from Amazon's business shift is that these segments produce higher margins. While Amazon doesn't break out its margins for each segment, you can use comparisons, like Alphabet's (NASDAQ: GOOG) (NASDAQ: GOOGL) advertising and Google Cloud (to compare Amazon Web Services), to see how much more profitable these businesses are versus retail. You can also see it in Amazon's improving gross margins, which reached an all-time high in Q3.

AMZN Gross Profit Margin (Quarterly) Chart

AMZN Gross Profit Margin (Quarterly) data by YCharts.

It cannot be understated how much improving gross profit margins can help a company, especially for a business like Amazon that doesn't have a high gross margin to begin with. Higher gross margins mean better profit margins as long as operating expenses are kept in check. And with CEO Andy Jassy's focus on becoming more efficient, he has delivered. This led to strong profits for Amazon, and there looks to be more in the future as Amazon returns to growth mode but with disciplined spending.

However, the stock's valuation has not responded in part.

Amazon's stock is attractively valued

Most software stocks trade at a massive premium to their peers because of their high margins. With the ability to generate greater profits with less revenue, investors attach a higher premium to their stock.

This can be seen with many software companies gathering a 10 to 20 times sales multiple, while those in the retail industry may only demand a 1 or 2 times sales premium. But as Amazon's margins improve, the price investors are willing to pay for the stock should increase. However, that's not what has happened with Amazon through its gross margin improvement.

AMZN PS Ratio Chart

AMZN PS Ratio data by YCharts. PS Ratio = price-to-sales ratio.

Amazon's 2.7 times sales valuation is about the same as in 2016 when its gross margins hovered around 10%. Now that this figure has nearly doubled, Amazon should be getting more respect, but it's not.

As Amazon maintains its profitability over the long term, I'd expect more investors to realize that Amazon has the potential to be one of the greatest cash-generating businesses on the market. This will allow it to do things like repurchase shares or pay dividends, making the stock even more attractive.

So, while Amazon isn't going to turn $30,000 into $1 million any time soon, I think it has strong potential to beat the market over the next five years. This can help increase your portfolio's return and hasten the path to becoming a millionaire versus just investing in an index fund.