Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
bourne2000
Helper V
Helper V

How to sum related to Many to Many relationship

Hi

 

I have two tables,

 

Table 1:

 

ProductIDPaid Amount
A10
B20
C30
D40
E50
F60
G70
H80

 

 

Table 2:

 

ProductIDTotalDue
A30
B40
C50
D60
K70
L80
M30
N40
I50
O60
  

 

Both Table 1 & Table 2 has connected with Product ID and it is Many to Many Relationships

 

What I need?

 

1) Wanted to calculate Remaining Amount for the productID presented in Table 1

 

I used below dax

 

Remaining Amount = sum(Table2[Total Due]) - sum(Table1[Paid Amount]) 

 

However it is not working

 

Expected Output

 

ProductIDPaid AmountTotal DueRemaning Amount
A103020
B204020
C305020
D406020

 

2) Wanted to print the Table 1 records which is not presented in the Table 2

 

Expected Output

 

ProductIDPaid Amount
E50
F60
G70
H80

 

I don't want to use any bridge table, possible to solve through DAX?

 

Kindly advise

 

1 ACCEPTED SOLUTION
SamInogic
Super User
Super User

Hi,

 

As per our understandings you are looking for DAX formulae to get required data and have Many many to relationship in your tables, so have created sample data as per your requirement as follows:

 

Table 1

 Table1.png
Table 2
Table2.png

Relationship Between table will be as Following 

Relationship.png
You can create a new column [Total Due] by using below DAX Expression 

 

Total Due = LOOKUPVALUE('Table 2'[TotalDue],'Table 2'[ProductID],'Table

 1'[ProductID])

 

Then create a new column for Remaining Amount using below DAX expression,

Remaining Amount = IF('Table 1'[Total Due]-'Table 1'[Paid Amount]>=0,'Table

 1'[Total Due]-'Table 1'[Paid Amount],0)

Output.png

Regarding second question to find non-matching records from table 2 you can create new column in Table 1 with below DAX expressions:

ExistInTable2 = IF(ISBLANK(LOOKUPVALUE('Table 2'[ProductID],'Table 2'[ProductID], 'Table 1'[ProductID])), "No","Yes")

 

And to display only records which are not present in Table 2 you can apply filter on the table visual as ExistInTable as “No”.

Please refer to the below screenshot for the same,

second output.png

If this answer helps, please mark it as Accepted Solution so it would help others to find the solution.


Thanks!

Inogic Professional Service Division

An expert technical extension for your techno-functional business needs

Power Platform/Dynamics 365 CRM

Drop an email at crm@inogic.com

Service:  http://www.inogic.com/services/ 

Power Platform/Dynamics 365 CRM Tips and Tricks:  http://www.inogic.com/blog/

Inogic Professional Services: Power Platform/Dynamics 365 CRM
An expert technical extension for your techno-functional business needs
Drop an email at crm@inogic.com
Service: https://www.inogic.com/services/
Tips and Tricks: https://www.inogic.com/blog/

View solution in original post

1 REPLY 1
SamInogic
Super User
Super User

Hi,

 

As per our understandings you are looking for DAX formulae to get required data and have Many many to relationship in your tables, so have created sample data as per your requirement as follows:

 

Table 1

 Table1.png
Table 2
Table2.png

Relationship Between table will be as Following 

Relationship.png
You can create a new column [Total Due] by using below DAX Expression 

 

Total Due = LOOKUPVALUE('Table 2'[TotalDue],'Table 2'[ProductID],'Table

 1'[ProductID])

 

Then create a new column for Remaining Amount using below DAX expression,

Remaining Amount = IF('Table 1'[Total Due]-'Table 1'[Paid Amount]>=0,'Table

 1'[Total Due]-'Table 1'[Paid Amount],0)

Output.png

Regarding second question to find non-matching records from table 2 you can create new column in Table 1 with below DAX expressions:

ExistInTable2 = IF(ISBLANK(LOOKUPVALUE('Table 2'[ProductID],'Table 2'[ProductID], 'Table 1'[ProductID])), "No","Yes")

 

And to display only records which are not present in Table 2 you can apply filter on the table visual as ExistInTable as “No”.

Please refer to the below screenshot for the same,

second output.png

If this answer helps, please mark it as Accepted Solution so it would help others to find the solution.


Thanks!

Inogic Professional Service Division

An expert technical extension for your techno-functional business needs

Power Platform/Dynamics 365 CRM

Drop an email at crm@inogic.com

Service:  http://www.inogic.com/services/ 

Power Platform/Dynamics 365 CRM Tips and Tricks:  http://www.inogic.com/blog/

Inogic Professional Services: Power Platform/Dynamics 365 CRM
An expert technical extension for your techno-functional business needs
Drop an email at crm@inogic.com
Service: https://www.inogic.com/services/
Tips and Tricks: https://www.inogic.com/blog/

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.