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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
MBEL
Regular Visitor

Calculating number of nodes in relationship data

Hi all,

I have relationship data to plot in a network map. An example of this is:

Origin

Target

1

2

1

3

1

4

1

5

2

1

To use the network graph, I need to create a copy of the table, make the targets origins, and the origins target, like this:

Origin

Target

1

2

1

3

1

4

1

5

2

1

2

1

3

1

4

1

5

1

1

2

Now, I want to calculate the occurrences of each node, that is:

MBEL_0-1683198640762.png

 

 

However this table is static and when I filter the origin node, I cannot make the count target update:

MBEL_1-1683198640762.png

 

 

 

The right quantities should be:

Origin

Target

Count_Origin

Count_target

2

1

2

2

2

3

2

1

3

1

2

2

3

2

2

1

 

I have tried many things (countx / countrows and earlier functions, created separate tables and tried to join them, etc.

The formula I am using for the Count_Origin is :

Count_origin = COUNTX(filter(Countpairs, EARLIER(Countpairs[Origin]) = Countpairs[Origin]),Countpairs[Origin])

Any ideas, Please!!!

1 ACCEPTED SOLUTION

Hi @MBEL ,

 

Sorry, due to my negligence there was an error in the fields in the previous measure.

Now it has been corrected, please check if the result is what you want now:

Count_origin = 
var _a = ALLSELECTED('Table'[Origin])
var _b = ALLSELECTED('Table'[Target])
return COUNTX(FILTER(ALL('Table'),[Origin] in _a&&[Target] in _b&&[Origin]=SELECTEDVALUE('Table'[Origin])),[Origin])

Count_target = 
var _a = ALLSELECTED('Table'[Origin])
var _b = ALLSELECTED('Table'[Target])
return COUNTX(FILTER(ALL('Table'),[Origin] in _a&&[Target] in _b&&[Target]=SELECTEDVALUE('Table'[Target])),[Target])

Final output:

vjianbolimsft_0-1683770337951.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-jianboli-msft
Community Support
Community Support

Hi @MBEL ,

 

Please try:

Count_origin = 
var _a = ALLSELECTED('Table'[Origin])
var _b = ALLSELECTED('Table'[Target])
return COUNTX(FILTER(ALL('Table'),[Origin] in _a&&[Target] in _b&&[Origin]=SELECTEDVALUE('Table'[Origin])),[Origin])

Count_target = 
var _a = ALLSELECTED('Table'[Origin])
var _b = ALLSELECTED('Table'[Target])
return COUNTX(FILTER(ALL('Table'),[Origin] in _a&&[Target] in _b&&[Origin]=SELECTEDVALUE('Table'[Target])),[Target])

Final output:

vjianbolimsft_0-1683598802968.png

vjianbolimsft_1-1683598812443.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for your message, but hat I am trying to calculate is the ocurrances of target nodes. In your filtered table what I am after is the following:

OriginTargetCount_originCount_target 
2122number of 1's in taget column
2321number of 3's in target column
3132number of 1's in taget column
3231nuber of 2's in target column 

Hi @MBEL ,

 

Sorry, due to my negligence there was an error in the fields in the previous measure.

Now it has been corrected, please check if the result is what you want now:

Count_origin = 
var _a = ALLSELECTED('Table'[Origin])
var _b = ALLSELECTED('Table'[Target])
return COUNTX(FILTER(ALL('Table'),[Origin] in _a&&[Target] in _b&&[Origin]=SELECTEDVALUE('Table'[Origin])),[Origin])

Count_target = 
var _a = ALLSELECTED('Table'[Origin])
var _b = ALLSELECTED('Table'[Target])
return COUNTX(FILTER(ALL('Table'),[Origin] in _a&&[Target] in _b&&[Target]=SELECTEDVALUE('Table'[Target])),[Target])

Final output:

vjianbolimsft_0-1683770337951.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 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.

Top Solution Authors