It is very difficult to understand your logic.
Could you create sufficient number of sample data in excel with expected answer examples.
I've attached an Excel Sheet with sample data. Basically, the expected result is: There is a filter in the workbook, this filter is applied for two dimensions simultaneously. Hence, if you choose in this filter "31" measure 1 and measure 2 will be calculated independently.
There are different ways to get this done even though there is no direct solution for this. Please find the attached workbook. This solution will work fine but bit tedious to maintain when the dataset becomes large. Hope it helps.
Please mark the answer as helpful if it resolves the issue.
If you can prepare your data like this then it will be very easy for your to get the output without any calculation.
Find my approach below, normalize your data set into two sets like this then union both the data sets. Follow the screenshot
Connect the final data in tableau then drag the fields in canvas and check.
Workbook and excel attached for your reference. Let us know if this help.