Target had its largest increase in sales in 15 years as millions of Americans turned to the Minneapolis-based retailer to buy essential items — often online — as COVID-19 took hold in the U.S.

However, profits were down as customers’ buying habits changed during the pandemic, dramatically shifting several times in the past few months.

CEO Brian Cornell expects the unpredictability to continue as states loosen rules and economic conditions change, leaving Target to adjust week by week to the rapidly changing environment.

“There’s just so much uncertainty as I think about the balance of the year,” he said. “We’re still trying to figure out if children are going back to school, what’s going to happen with colleges and universities, how the guest is going to celebrate different holidays.”

Target’s comparable sales in the February-to-April quarter rose 10.8%, most of it being driven by an eye-popping 141% jump in online sales. But its profits took a hit as consumers shifted spending to groceries and household supplies.

The pandemic spurred 5 million consumers to order items online from Target for the first time. Two-fifths of DriveUp customers in the quarter were first-time users of the service.

On many days in April, Cornell said Target was fulfilling more online orders than it did on last year’s Cyber Monday. The digital spike took executives by surprise, resulting in volumes they had not planned to reach online for another three years.

Traffic in stores surged in mid-March as consumers stockpiled, plummeted as stay-at-home orders went into effect, and then bounced back as more people have started getting out of the house.

Sales of groceries skyrocketed 50% at one point, then settled down but to higher-than-normal levels. Conversely, apparel sales plummeted by as much as 50% but rebounded in mid-April as consumers received stimulus checks. Sales of electronics such as video games and home office products increased 45% and kitchen items by 25%.

“Unprecedented volatility within the quarter presented the most extreme test of our business and operations that I could have imagined,” said Cornell. “In that environment, we drove industry-leading growth.”

However, with more lower-margin items in the cart, Target’s profits fell 20% in the February-to-April quarter. The retailer also had to write down mountains of unsold clothing as consumers pivoted to buying essential items.

Target also said it is spending about $500 million on pandemic-related benefits such as a temporary $2-an-hour pay increase for its front-line workers — which have been extended until July 4 — as well as increased safety measures such as more rigorous cleanings of stores and face masks for employees.

The retailer’s net earnings dropped 64.3% in the quarter to $284 million. Its shares declined 3% on Wednesday.

“This is the reality of retailing during the crisis: Those retailers that remained open got a spike in trade, but the cost of servicing that business was punishingly high,” Neil Saunders, managing director of GlobalData Retail, wrote in a note.

While the growth in digital sales also weighed on Target’s bottom line, Cornell said the retailer has been growing its affinity and loyalty among shoppers during the pandemic because of its DriveUp service and same-day delivery through Shipt.

Target executed well and managed to keep up with the pandemic-fueled surge in demand seemingly better than Amazon did, said Brian Yarbrough, an analyst with Edward Jones.

But it remains to be seen how much spending trails off as the bump from stimulus checks wears off and whether consumers will go back to their previous shopping habits as other retailers reopen.

“The million-dollar question is how many of these customers stay with Target,” said Yarbrough. “A lot of them had no other options. As other retailers open up, does that change the game?”

Cornell acknowledged that some of Target’s market-share gains were because other retailers were closed. He said he looks forward to them reopening because retail is critical to the health of the U.S. economy, and employees of other retailers often shop at Target.

At the same time, he and other executives nodded to the fact that they will likely benefit from expected dislocations in the retail space. They said they will be looking at opportunities to buy up real estate and brands as other retailers permanently close stores or shut down.

Target’s results come on the heels of strong sales reported by other companies such as Walmart and Amazon. It also magnified the chasm between these “essential” retailers that remained open during the pandemic and the department stores and clothing stores that saw massive sales declines as they had to shutter stores as consumers put discretionary purchases on hold. On Tuesday, Kohl’s, for example, said that its first-quarter sales had plunged 43.5%.

The pandemic has pushed several struggling retailers into bankruptcy, including J.C. Penney, Neiman Marcus, J. Crew and Stage Stores. Analysts expect more to follow. Overall U.S. retail sales in April plunged 16.4%, the largest drop ever recorded.

On Wednesday, Target executives said they are resuming plans to add fresh groceries to the chain’s DriveUp and order pickup service this year, having recently begun testing it in the Twin Cities and Kansas City.

In March, Target had put that initiative, as well as plans for store remodels and openings, on hold because of the pandemic.