I want to find the difference between the sum of all the common elements between 2 tables.
We have one large table (Table A)
You can observe that neither the id, nor the date can be used individually as a unique identifier.
Based on certain filters(one of it is date), we have to create 2 tables:
We then have to find the difference between the sum of all the common elements.
Table 1 and 2 may not be real tables and could be simply virtual tables (defined using VAR) declared in order to create the measure.
I have tried the following code:
Difference = VAR Table1= ADDCOLUMNS('TableA', "id", CALCULATE(VALUES('TableA'[Id]), ALL('Date'),ALL('TableA'), USERELATIONSHIP('Date'[As of Date], Previous_Date[Previous_Date]),USERELATIONSHIP('Date'[As of Date], 'TableA'[Date])), "Value", 'TableA'[Value] )
VAR Table2= ADDCOLUMNS('TableA', "id", CALCULATE(VALUES('TableA'[Id]),ALL('TableA'), USERELATIONSHIP('Date'[As of Date], 'TableA'[Date])),"Value", 'TableA'[Value] )
VAR abc = CALCULATE(SUMX(Table1,IF(VALUES('TableA'[Id]) IN Table1 && VALUES('TableA'[Id]) in Table2,Table1[Value])) )
VAR pqr = CALCULATE(SUMX(Table2,IF(VALUES('TableA'[Id]) IN Table1 && VALUES('TableA'[Id]) in Table2,Table2[Value])) )
RETURN abc-pqr