How can I add a count that needs to count number of rows for the main reference and then sub count the number of rows for the sub reference, I plan to join this to the main