The equivalent SQL pseudocode is something like this:
SELECT COUNT DISTINCT P_Key
FROM FactQ INNER JOIN DimP ON FactQ.P_Key = DimP.P_Key WHERE Date1Key IN @SelectedMonths OR Date2Key IN OR AFTER @SelectedMonths and Date1Key BEFORE @SelectedMonths AND MAX(P_Number) IN (1,3) GROUP BY P_Key
P_Number is defined to aggregate using the Max function in the measure group.
But to simplify things, I basically need to:
1. Get a set of P_Keys where the aggregated P_Number is 1 or 3 and [Date1] is in [Date Set One]
2. Get a set of P_Keys where the aggregate P_Number is 1 or 3 and [Date1] is in [Date Set One A] and [Date2] is in [Date Set Two]
3. Combine the sets and count distinct.
I know how to get the date sets and filter by P_Number, but I am stuck on how to go back and get the P_Keys.
Sorry for the long post. I wanted to start from the beginning in case this is an XY problem.