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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Jessica_17
Helper III
Helper III

Issue with Relationship between 2 tables to get the desired results

Hello All,

I have 2 tables,

Table A

CatSub CatActconcatmetric
abckjlyuff- ggthm
cbadfyukk - llthm
abcadyuyy - jjthm
cbadfyukk - llthm
drfsdfyuyy - jjthm
kjhuiqwyy - jjthm
drfadfgqwyy - jjthm
drfsdfqwyy - jjthm
drfadfgqwff- ggthm
kjhuiqwkk - llthm
kjhuiqwyy - jjthm
kjhuiqwff- ggthm
kjhuiqwkk - llthm

 

Table B

CatSub CatActconcatcustmetrictrad
abckjlyuff- gggfthmdgdf
cbadfyukk - llgfthmdgdf
abcadyuyy - jjgfthmdgdf
cbadfyukk - llgfthmrty
drfsdfyuyy - jjgfthmefewr
kjhuiqwyy - jjgfthmefewr
drfadfgqwyy - jjgfthmefewr
drfsdfqwyy - jjsethmefewr
drfadfgqwff- ggsethmtrh
kjhuiqwkk - llsethmwerg
kjhuiqwyy - jjsethmwerg
kjhuiqwff- ggsethmwerg
kjhuiqwkk - llsethmyujy
abckjlyuff- gggfthmwefsdf
cbadfyukk - llgfthmwefsdf
abcadyuyy - jjgfthmwefsdf
cbadfyukk - llgfthmkmkl
drfsdfyuyy - jjgfthmkmkl
kjhuiqwyy - jjgfthmkmkl
drfadfgqwyy - jjgfthmkmkl
drfsdfqwyy - jjsethmtyjyjht
drfadfgqwff- ggsethmtyjyjht
kjhuiqwkk - llsethmtyjyjht
kjhuiqwyy - jjsethmtyjyjht

 

 

Both tables are have a relationship of many to many and bidirectional. Output required (row part of matrix table):-

output      
CatSub CatActconcatcustmetrictrad
abckjlyuff- gggfthmdgdf
adyuyy - jjgfthmdgdf
kjlyuff- gggfthmwefsdf
adyuyy - jjgfthmwefsdf
cbadfyukk - llgfthmdgdf
dfyukk - llgfthmrty
dfyukk - llgfthmwefsdf
dfyukk - llgfthmkmkl
drfsdfyuyy - jjgfthmefewr
adfgqwyy - jjgfthmefewr
sdfqwyy - jjsethmefewr
adfgqwff- ggsethmtrh
sdfyuyy - jjgfthmkmkl
adfgqwyy - jjgfthmkmkl
sdfqwyy - jjsethmtyjyjht
adfgqwff- ggsethmtyjyjht
kjhuiqwyy - jjgfthmefewr
uiqwkk - llsethmwerg
uiqwyy - jjsethmwerg
uiqwff- ggsethmwerg
uiqwkk - llsethmyujy
uiqwyy - jjgfthmkmkl
uiqwkk - llsethmtyjyjht
uiqwyy - jjsethmtyjyjht
       

 

I am not able to achieve this using dax or modelling also, and it has some numeric columns too which I have not shown in an example.

8 REPLIES 8
lbendlin
Super User
Super User

Please provide a more detailed explanation of what you are aiming to achieve. What have you tried and where are you stuck?

HI @lbendlin ,

Basically I have created a bidirectional relationship between each table, now the client want is that from table A all values should be shown irrespective of values being there in table B or not, then I changed it to unidirection relationship where Table A filters Table B, then the 1st column is from table B then next columns are from table A which do not shows the correct values, then again at last we are adding column from Table B which given an error of values cannot be shown.

 

I am not able to show both tables values together in unidirection relationship, and using bidirection, not all values are being shown.

Can you please confirm on what columns you are trying to create relationship between two tables?

HI @vigneshba ,

There is one common column between each table which is combination of 2 columns, which is causing many to many relationship.

 

and In above sample scenario it is conact column.

Thanks for the reply from@vigneshba and@lbendlin,please allow me to provide another insight:
Hi,@Jessica_17 

Regarding the issue you raised, my solution is as follows:

1.Next create relationships between tables:

vlinyulumsft_0-1719819235438.png

2.The visualization object is then modified to the following result:

vlinyulumsft_1-1719819249554.png

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_2-1719819264449.png

This is the more relevant approach to your needs as far as I'm concerned.

 

4.Of course, we still recommend using the following three options if allowed:

First, use the merge query in powerquery:

vlinyulumsft_3-1719819287638.png

Merge queries overview - Power Query | Microsoft Learn

 

Second, using custom columns in powerquery:

vlinyulumsft_5-1719819322573.png

Add a custom column in Power BI Desktop - Power BI | Microsoft Learn

 

Third using the lookupvalues() function in dax:

LOOKUPVALUE function (DAX) - DAX | Microsoft Learn

RELATED function (DAX) - DAX | Microsoft Learn

 

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

HI @v-linyulu-msft ,

Thanks for providing this solution, I think I was not able to deliver in my questions was that according to your data also, that Need to so same in Matrix table, but when I convert your data also into matrix table, it is showing values according to cross join, such as Cat "abc" do not have concat value as "kk-ll" but it is showing that value in front of "abc" Cat, even I checked the data , it does not have that data in front of Cat, so basically it should filter as what ever the associated values are in Concat column, (so only 2 values in Concat should have been shown in front of Cat "abc").

Jessica_17_0-1719837360990.png

 

Hi,@Jessica_17 

Thank you for your reply.

First of all, for your needs, I recommend using table visualizations for more convenience and intuitiveness, and matrices for aggregate hierarchical values.

Second, if you still need to display that value in the matrix, here's my solution:

1.First, you need to insert the serial number in PowerQuery to ensure that the values are not aggregated:

vlinyulumsft_0-1721308445005.png

2.Next, copy the table and name it "head":

vlinyulumsft_1-1721308445006.png

3.Then unpviot it:

vlinyulumsft_2-1721308462543.png

4.Finally, get rid of duplicates and unnecessary rows:

vlinyulumsft_3-1721308462544.png

vlinyulumsft_4-1721308473263.png

5. Below are the measure I've created for your needs:

Measure = 
SWITCH(TRUE(),
MAX('head'[Attribute])="Cat",CALCULATE(MAX('Table'[Cat]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index]))),
MAX('head'[Attribute])="Act",CALCULATE(MAX('Table'[Act]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index]))),
MAX('head'[Attribute])="concat",CALCULATE(MAX('Table'[concat]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index]))),
MAX('head'[Attribute])="cust",CALCULATE(MAX('Table'[cust]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index]))),
MAX('head'[Attribute])="metric",CALCULATE(MAX('Table'[metric]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index]))),
MAX('head'[Attribute])="Sub Cat",CALCULATE(MAX('Table'[Sub Cat]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index]))),
MAX('head'[Attribute])="trad",CALCULATE(MAX('Table'[trad]),FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])))
,FALSE())

6. Then modify the visualization settings:

vlinyulumsft_5-1721308529525.png

7.Here's my final result, which I hope meets your requirements.

vlinyulumsft_6-1721308529527.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Hello @v-linyulu-msft 

Thanks for the solution, but I think I made it a little complex, I do require matrix only and only the concat part needs to be filtered according to previous column values as you had done in previous steps, rest are solvable as you have already completed those part.

Jessica_17_0-1721333047696.png

 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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