You can use Exchange powershell and filter on a large amount of variables:
https://learn.microsoft.com/en-us/powershell/exchange/recipientfilter-properties?view=exchange-ps&WT.mc_id=M365-MVP-9501
https://office365itpros.com/2021/01/18/dynamic-distribution-lists-filters/