Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I have a table with structure similar to this:
project-contact
project | contact |
1 | Steve Smith |
1 | Sally V. |
1 | Sammy Davis |
2 | Steve Smith |
2 | Sally V. |
3 | Tom Rosen |
3 | Sammy Davis |
4 | Tom Rosen |
I am looking to ideally get to something that is like this:
person 1 | person 2 | partnerships |
Steve Smith | Sally V | 2 |
Steve Smith | Sammy Davis | 1 |
Sally V | Steve Smith | 2 |
Sally V | Sammy Davis | 1 |
Sammy Davis | Steve Smith | 1 |
Sammy Davis | Sally V | 1 |
Tom Rosen | Sammy Davis | 1 |
Essentially I am trying to count the number of times a person is partnered with another on projects.
Solved! Go to Solution.
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:
Then you can create measures like this.
# 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 )
)
Hopefully that's of some use.
Regards,
Owen
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:
Then you can create measures like this.
# 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 )
)
Hopefully that's of some use.
Regards,
Owen
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
11 |
User | Count |
---|---|
19 | |
14 | |
14 | |
11 | |
9 |