but didn't have the same powers of storytelling or whatever the x-factor in publishing is. Plenty of books get remaindered each year, and no one publishes stuff (except HMSO or whatever it is these days) they think people won't buy.
As someone who's worked in fiction publishing, let me point out there is no objective 'x-factor' when an agent chooses to represent an author, or an editor buys a novel. People buy/represent stuff that interests them and that they think will sell, but what they think is interesting and/or will sell varies hugely from person to person.
People snark about the fact that the HP series was turned down by multiple publishers before it was bought, but the fact is that this is true for an awful lot of novels. I couldn't begin to count the number of novels that crossed my desk and weren't bought, which were then bought by another editor who rated the book as more salable, sometimes rightly, sometimes wrongly. Or a big nine-way auction emerges because a lot of editors think it's saleable, but the book doesn't sell well in the end.
Timing and luck matter too. I know someone who'd been peddling the same novel around for years with no success, and then Sally Rooney happened, and an editor decided this novel could be marketed to SR readers, and bought it for a big advance, and it was optioned for a film/series. But it's exactly the same novel as it was three years earlier, when no one would touch it.