As other retailers get creamed, Macy’s bucked the trend Thursday by posting quarterly results that topped analysts’ expectations.

What can we learn from that?

“While macroeconomic pressures on consumer spending increased during the quarter, our customers continued to shop,” the company’s chief executive, Jeff Gennette, said in a statement.

That was due in part the economy gradually reopening and people returning to the workplace. But this rising tide hasn’t lifted all boats.

Walmart and Target got punished by investors after reporting worse-than-expected quarterly results. Most other retailers have been struggling to attract business amid soaring prices.

But Macy’s, which also owns Bloomingdale’s, somehow figured out the secret sauce for appealing to both well-heeled and working-class consumers, as well as giving Amazon a run for online shoppers.

Macy’s digital sales comprised about a third of the company’s revenue. Sales at stores open at least a year were up 12.4% from a year ago.

Overall, Macy’s quarterly profit nearly tripled from a year before to $286 million.

“We operate across the value spectrum from off-price to luxury,” Gennette told investors. “This, coupled with our wide assortment of categories, products and brands, gives us the ability to flex with consumer demand.”

There it is.

Macy’s seems to have threaded the retail needle by being all things to all shoppers.

Which is to say, it’s running Amazon’s online playbook in the brick-and-mortar world.

Will the gravy train keep chugging? Too soon to say.

For the time being, Macy’s is trying to manage expectations by forecasting only modest sales growth for the remainder of the year.

Investors are more enthusiastic. Macy’s stock soared by 19% after the earnings were announced.