Respuesta :

How long had you owned the flat before you sold it?

“Had owned” is correct; “had been owning” doesn’t sound natural.