Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Count all shared values with condition

Hi everyone,

 

I cannot seem to figure out how to do the below.

I have a table like this:

UserEntity
A1
A2
A3
B2
C1
C2
C4
D2
D4

 

Essentially what I'd like to do is count how many times one entity appears with another entity based on users.

So I'd like to get all possible unique combination of entities (in two separate columns) and the count of times they appear with the same user (as a third column)- see the below table:

 

Entity 1Entity 2User Count
122
131
141
231
242
340

 

So for example the combination '1-2' has a user count of 2 because both A and C appear with entity 1 and 2.

On the other hand, the combination of '1-3' has a user count of 1 because A is the only person who appears with both entity 1 and entity 3.

I hope that makes sense and if someone could help me figure out how to get that second table I would be super grateful!

 

Many thanks,

Ginny

 

4 Replies