Yes it can be done. We do it in one of our projects.
Yes it can get a bit messy.
You will need to iterate over the top level items to create the second level formset. For each instance of the second level formset, you will need to create the third level formset, using the second level object as the parent instance. You’ll also need to ensure you’re creating unique prefixes for both the individual second and third level formsets.
My post at Multiples of one formset - #12 by KenWhitesell goes into a little bit more detail about how we do this.