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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
evan_hoefling
Frequent Visitor

Counting Number of Partnerships

I have a table with structure similar to this:

 

project-contact

projectcontact
1Steve Smith
1Sally V.
1Sammy Davis
2Steve Smith
2Sally V.
3Tom Rosen
3Sammy Davis
4Tom Rosen

 

I am looking to ideally get to something that is like this:

person 1person 2partnerships
Steve SmithSally V2
Steve SmithSammy Davis1
Sally VSteve Smith2
Sally VSammy Davis1
Sammy DavisSteve Smith1
Sammy DavisSally V1
Tom RosenSammy Davis1

 

Essentially I am trying to count the number of times a person is partnered with another on projects.

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @evan_hoefling 

I recommend something similar to the Basket Analysis pattern described on DAX Patterns.

 

I have attached a sample PBIX, using a tweaked version of the above pattern.

 

Firstly, your data model can be set up like this, where Person 2 is a copy of Person 1, which contains a list of distinct people:

OwenAuger_0-1645484177549.png

 

Then you can create measures like this.

  • The Partnerships measures are designed to be placed in a visual grouped by Person 1 and Person 2.
  • Partnerships will include both partnerships (A,B) & (B,A).
  • Partnerships without duplicates will avoid double-counting and just include (A,B).
# Projects = 
DISTINCTCOUNT ( Projects[project] )
Partnerships = 
VAR ProjectsWithBothPeople =
    CALCULATETABLE (
        SUMMARIZE ( Projects, Projects[project] ),
        REMOVEFILTERS ( 'Person 1' ),
        -- Exclude Person 1 = Person 2
        EXCEPT (
            VALUES ( 'Person 2'[Person 2] ),
            VALUES ('Person 1'[Person 1] )
        ),
        -- Activate relationship with Person 2 
        USERELATIONSHIP (
            'Person 1'[Person 1],
            'Person 2'[Person 2]
        ) 
    )
RETURN
    CALCULATE (
        [# Projects],
        KEEPFILTERS ( ProjectsWithBothPeople )
    )
Partnerships without duplicates = 
-- Assume single value of Person 1
VAR CurrentPerson1 =
    SELECTEDVALUE ( 'Person 1'[Person 1] )
VAR ProjectsWithBothPeople =
    CALCULATETABLE (
        SUMMARIZE ( Projects, Projects[project] ),
        REMOVEFILTERS ( 'Person 1' ),
        -- Ensure each pair appears only once
        KEEPFILTERS ( 'Person 2'[Person 2] > CurrentPerson1 ), -- Person 2 > Person 1
        -- Activate relationship with Person 2
        USERELATIONSHIP (
            'Person 1'[Person 1],
            'Person 2'[Person 2]
        ) 
    )
RETURN
    CALCULATE (
        [# Projects],
        KEEPFILTERS ( ProjectsWithBothPeople )
    )

 

OwenAuger_1-1645484473701.png

 

Hopefully that's of some use.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

1 REPLY 1
OwenAuger
Super User
Super User

Hi @evan_hoefling 

I recommend something similar to the Basket Analysis pattern described on DAX Patterns.

 

I have attached a sample PBIX, using a tweaked version of the above pattern.

 

Firstly, your data model can be set up like this, where Person 2 is a copy of Person 1, which contains a list of distinct people:

OwenAuger_0-1645484177549.png

 

Then you can create measures like this.

  • The Partnerships measures are designed to be placed in a visual grouped by Person 1 and Person 2.
  • Partnerships will include both partnerships (A,B) & (B,A).
  • Partnerships without duplicates will avoid double-counting and just include (A,B).
# Projects = 
DISTINCTCOUNT ( Projects[project] )
Partnerships = 
VAR ProjectsWithBothPeople =
    CALCULATETABLE (
        SUMMARIZE ( Projects, Projects[project] ),
        REMOVEFILTERS ( 'Person 1' ),
        -- Exclude Person 1 = Person 2
        EXCEPT (
            VALUES ( 'Person 2'[Person 2] ),
            VALUES ('Person 1'[Person 1] )
        ),
        -- Activate relationship with Person 2 
        USERELATIONSHIP (
            'Person 1'[Person 1],
            'Person 2'[Person 2]
        ) 
    )
RETURN
    CALCULATE (
        [# Projects],
        KEEPFILTERS ( ProjectsWithBothPeople )
    )
Partnerships without duplicates = 
-- Assume single value of Person 1
VAR CurrentPerson1 =
    SELECTEDVALUE ( 'Person 1'[Person 1] )
VAR ProjectsWithBothPeople =
    CALCULATETABLE (
        SUMMARIZE ( Projects, Projects[project] ),
        REMOVEFILTERS ( 'Person 1' ),
        -- Ensure each pair appears only once
        KEEPFILTERS ( 'Person 2'[Person 2] > CurrentPerson1 ), -- Person 2 > Person 1
        -- Activate relationship with Person 2
        USERELATIONSHIP (
            'Person 1'[Person 1],
            'Person 2'[Person 2]
        ) 
    )
RETURN
    CALCULATE (
        [# Projects],
        KEEPFILTERS ( ProjectsWithBothPeople )
    )

 

OwenAuger_1-1645484473701.png

 

Hopefully that's of some use.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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