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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jimmyfromus
Helper III
Helper III

Creating a measure for tables with no relationship

Hi, 

 

I've 2 tables with no relationship between them, I would like to create a measure to add one column, Membership from table 2 to table 1. Table 1 is on the left and Table 2 is on the right. 

01.JPG

I created this measure in table 1: 

Committee Measure =
VAR __selectedcontact = SELECTEDVALUE ( 'First Table' [contactid] )
VAR __selectedcompany = SELECTEDVALUE ( 'First Table' [companyid] )
VAR __Committee = CALCULATE(MAX('Second Table'[Committee]),'Second Table'[companyid]=__selectedcompany,'Second Table'[contactid]=__selectedcontact)
RETURN __Committee
 
It doesn't seem to pick up all the values, as for example I would expect the 4th last line for company a in table 1 to have a committee value of dancing.
 
I've included the pbix file: pbix file 

 

1 ACCEPTED SOLUTION

@jimmyfromus 

Calculated table exactly as you have created it, not in PQ.

PQ is another option I recommended but not the solution provided

Try GENERATEALL instead if you want the rows with no committee as well:

First Table B V2 = 
GENERATEALL (
    'First Table',
    VAR contactCompany_ = 'First Table'[contact/company]
    VAR resT_ =
        CALCULATETABLE (
            DISTINCT ( 'Second Table'[Committee] ),
            FILTER (
                ALL ( 'Second Table'[company], 'Second Table'[contact] ),
                LEN ( contactCompany_ ) > 0
                    && ( 'Second Table'[contact] = contactCompany_ || 'Second Table'[company] = contactCompany_ )
            )
        )
 RETURN     
    resT_)

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

8 REPLIES 8
PaulDBrown
Community Champion
Community Champion

@jimmyfromus 

If you are happy to do this in a visual (as opposed to adding a new column to a table) you can use the TREATAS function





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






AlB
Super User
Super User

@jimmyfromus 

You should do this in Power Query.

It will not work on  a visual without modifying the underlying First table, since you seem to be adding rows. You can create a new calculated table:

First Table B =
GENERATE (
    'First Table',
    VAR contactCompany_ = 'First Table'[contact/company]
    RETURN
        CALCULATETABLE (
            DISTINCT ( 'Second Table'[Committee] ),
            FILTER (
                ALL ( 'Second Table'[company], 'Second Table'[contact] ),
                LEN ( contactCompany_ ) > 0
                    && ( 'Second Table'[contact] = contactCompany_
                    || 'Second Table'[company] = contactCompany_ )
            )
        )
)

 I reiterate that this should be done in PQ.

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

@AlB Thank you. I'm not sure how to create a calculated table with DAX in power query? Could you please advise? When I create the table via modeling and new table, I get the following but a few rows are missing from membership number 29 to 36. Thanks again. 

 

03.JPG

@jimmyfromus 

Calculated table exactly as you have created it, not in PQ.

PQ is another option I recommended but not the solution provided

Try GENERATEALL instead if you want the rows with no committee as well:

First Table B V2 = 
GENERATEALL (
    'First Table',
    VAR contactCompany_ = 'First Table'[contact/company]
    VAR resT_ =
        CALCULATETABLE (
            DISTINCT ( 'Second Table'[Committee] ),
            FILTER (
                ALL ( 'Second Table'[company], 'Second Table'[contact] ),
                LEN ( contactCompany_ ) > 0
                    && ( 'Second Table'[contact] = contactCompany_ || 'Second Table'[company] = contactCompany_ )
            )
        )
 RETURN     
    resT_)

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

@AlB Thank you, that works well. One last question. Can I add more columns besides committee? If I wanted to add Membership for example?

@AlB I used Summarize instead of Distinct and it seems to do the job fine. Thanks again. 

AlB
Super User
Super User

Hi @jimmyfromus 

Please explain the logic behind it. How do you get the committee from Table2? Why should it be "dancing" for that last 4th row??

Show the full expected result

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Table 1 has a company/contact column, whereas table 2 has these columns seperated. So in table 2, company a and contact a have dancing as a committee value. I would like to show this in table 1 where company a has a committee value of dancing and the same for contact a. 

The expected result would be like so. 

 

02.JPG

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors