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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Sab
Helper V
Helper V

Measure to count Reciprocal User Relationship

Hello all,

 

I have a dataset similar to the one shown below.

 

I need to create a measure that counts how many reciprocal relationships we have, so if a particular user sends a message to the receiver, and then the receiver sends back the message, that's 1 reciprocal relationship.

 

In the screenshot you can see there are a total of three.

 

Thank you!

 

New Message - Microsoft Power BI Community and 1 more page - Work - Microsoft Edge.jpg

2 ACCEPTED SOLUTIONS

Hi @Sab ,

 

That likely means your sender id is not unique and that it matches many purchase id.  Try this instead to return only the first value:

 

TransmitEcho = 
VAR _Receivers = VALUES('Table'[Receiver])
RETURN
IF(
    [Sender] in _Receivers, 
    VAR _ID = CALCULATE(MIN('Table'[ID]), FILTER('Table', 'Table'[Sender] = EARLIER('Table'[Receiver])), ALL('Table'[Receiver]))
    VAR _Key = 
        SWITCH( TRUE(), 
            ISBLANK(_ID), BLANK(),
            [ID] > _ID, COMBINEVALUES("^",_ID, [ID]),              
            COMBINEVALUES("^", [ID], _ID))
    RETURN
    _Key
)

 

If this doesn't work, if you can send some larger sample data for me to work with and I can test.



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

Create this calculated column formula

Is this combination available elsewhere?=CALCULATE(COUNTROWS(Data),FILTER(data,Data[SenderID]=EARLIER(Data[ReceiverID])&&Data[ReceiverID]=EARLIER(Data[SenderID])))

Write this measure and drag it to a card visual

Measure = calculate(countrows(Data),Data[Is this combination available elsewhere?]=1)/2

This will work only as long as a Send and Receiver ID pair appears twice only.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Sab
Helper V
Helper V

Thanks for all your help!

 

 

Ashish_Mathur
Super User
Super User

Hi,

Create this calculated column formula

Is this combination available elsewhere?=CALCULATE(COUNTROWS(Data),FILTER(data,Data[SenderID]=EARLIER(Data[ReceiverID])&&Data[ReceiverID]=EARLIER(Data[SenderID])))

Write this measure and drag it to a card visual

Measure = calculate(countrows(Data),Data[Is this combination available elsewhere?]=1)/2

This will work only as long as a Send and Receiver ID pair appears twice only.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Sab
Helper V
Helper V

Hello and thank you for your reply @hnguy71 .

Strangely I am getting the error, 'A table of multiple values was supplied where a single value was expected.'

 

Sab_0-1651883504150.png

 

Hi @Sab ,

 

That likely means your sender id is not unique and that it matches many purchase id.  Try this instead to return only the first value:

 

TransmitEcho = 
VAR _Receivers = VALUES('Table'[Receiver])
RETURN
IF(
    [Sender] in _Receivers, 
    VAR _ID = CALCULATE(MIN('Table'[ID]), FILTER('Table', 'Table'[Sender] = EARLIER('Table'[Receiver])), ALL('Table'[Receiver]))
    VAR _Key = 
        SWITCH( TRUE(), 
            ISBLANK(_ID), BLANK(),
            [ID] > _ID, COMBINEVALUES("^",_ID, [ID]),              
            COMBINEVALUES("^", [ID], _ID))
    RETURN
    _Key
)

 

If this doesn't work, if you can send some larger sample data for me to work with and I can test.



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
hnguy71
Super User
Super User

Hi @Sab ,

 

How about we create a calculated column first, and then count the total number of distinct relationships?

 

TransmitEcho = 

VAR _Receivers = VALUES('Table'[Receiver])
RETURN
IF(
    [Sender] in _Receivers, 
    VAR _ID = LOOKUPVALUE('Table'[ID], [Sender], [Receiver])
    VAR _Key = IF([ID] > _ID, COMBINEVALUES("^",_ID, [ID]),  COMBINEVALUES("^", [ID], _ID))
    RETURN
    _Key
)

 

A screenshot of the output is provided below:

hnguy71_0-1651882292510.png

 

And then, you'd create a basic distinctcount measure to find number of relationships:

CountTotalRelationship = DISTINCTCOUNTNOBLANK('Table'[TransmitEcho])

 

hnguy71_2-1651882394629.png

In this way, you can eventually evaluate and analyze your pairs.

 

Let me know if this helped you!

 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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