Select only values that are present in comun a and column b

To simulate your situation I have create two free-hand SQL queries with data similar to yours…

–Longer than 2 years ago
SELECT ‘000000000’ AS [ID], ‘05-01-2017’ [SomeDate]
UNION
SELECT ‘000000000’, ‘05-03-2017’
UNION
SELECT ‘123456789’, ‘02-04-2018’
UNION
SELECT ‘111222333’, ‘05-03-2018’
UNION
SELECT ‘444555666’, ‘06-27-2018’
UNION
SELECT ‘987654321’, ‘12-04-2018’
UNION
SELECT ‘999888777’, ‘12-15-2018’;

–2021 Q1
SELECT ‘000000000’ AS [ID], ‘01-16-2021’ [SomeDate]
UNION
SELECT ‘000000000’, ‘02-07-2021’
UNION
SELECT ‘000000000’, ‘02-13-2021’
UNION
SELECT ‘123456789’, ‘02-24-2021’
UNION
SELECT ‘111222444’, ‘03-03-2021’
UNION
SELECT ‘987654321’, ‘03-19-2021’;

Those queries yield these tables…

Next I merged on the ID objects from each query. Here is where things get a little more difficult.

I created two variables; one for the SomeDate object from each query. I called them Var SomeDate 2021 Q1 and Var SomeDate Two Years Ago. The key is that the Qualification must be “Detail” and the Associated dimension must be the merged ID dimension. Not the ID from either query, but the merged ID dimension that looks like a parent to the ID dimension from each of the queries.

Now we can build a table with the merged ID dimension and the two variables we just created.

The final step is to add filters where both the variables are not null.

And there you have it…

I do not know how to deal with the #MULTIVALUE (#MEERWAARDEN) in this situation, but that is not essential to this particular question.

A couple of other notes. You do not need the variables in the table in order to filter on them. Or you could leave them in the table, but hide them if you do not want to see them.

Also, with this foundation you can show the IDs that are in one query an not the other by adjusting the filters giving these results…

Hope this helps