Dear All ,
We Have 3 Tables, MainTable , ContactBill and Contractpayment.
The Fields Inside Main Table as the following:
ID: Integer Primary Key
Amount: Double, Amount in US$
Code: Text Represents the name of the related table either (ContactBill or Contractpayment)
Related Tables:
ContactBill
The Fields Inside ContactBill (Payment Installments By Bills) Table as the following:
ID: Foreign Key Reference (MainTable)
Amount: Double, Amount in US$, this represents the Installments of payments based on (Bills).
For example: In the main table the amount is (10) then In ContactBill it might be in a form of Installments (5,5) in two rows of the table For particular ID.
Date: Installment Date where the amount paid.
Contractpayment
The Fields Inside Contractpayment (Payment Installments By Cash) Table as the following:
ID: Foreign Key Reference (MainTable)
Amount: Double, Amount in US$, this represents the Installments of payments based on (Cash).
For example: In the main table the amount is (12) then In ContactBill it might be in a form of Installments (8,4) in two rows of the table For particular ID.
Date: Installment Date where the amount paid.
How can I implement DAX to do the following 2 Tasks:
1-Based On the code from MainTable Lists all the Installments for this particular code with the ID.
Example:
Code(ContactBill) and ID (1), will list all the Installment amounts In the table (ContactBill) with ID (1) including its dates. In this list table, we must take into account to display the column name for each table( Cash Amount (ContactPayment), Bill Amount (ContactBill)).
2-If there is a difference between the Total Amount in (Main Table) and the sum of Installments of their Related Tables (Codes) it should calculate this difference, Example: In Main Table ID=4 has amount=26 for Code (ContactPayment) , In Table ContactPayment ID=4 have two rows (13,4) = 17 , But the amount in main table = 26 , means the Difference Should be: 26-17= 9.
Thank You
Note: In spite that the 2 related tables looked as the same structure, but for some reason, we must deal with them separately Because In the near future any or both of them might have different fields column , In Addition it should be without physical relationship with (Main Table).