I think you will have to use maybe a combination of case/if switches. Maybe combined with a group by and count to check for the number of rows. As it happens I collected some links about import and switches maybe that would help.
Then the best thing would be to create a minimal viable example that represents all your challenges so the community could have a look.