This solution blew my mind. Never knew we can loop and union all without creating multiple datasets and this reduced my query time a great deal.