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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
tt211595
Frequent Visitor

Sum of measure with bidirectional relationship

Hello! I have two example tables: A and B.

 

Table A:

personIDName
1Jane
2John
3Will
4Sam
5Laura

 

Table A:

personIDCar Color
1Blue
1Green
3Blue
4Blue

 

I'd like to have a bi-directional relationship between the two tables based on the column personID. I'd like to create a bar graph like below, showing that 60% of people (3/5 people) have a blue car and 20% of people (1/5) have a green car.

tt211595_0-1683938504832.png

 

I've created a measure (so that it's responsive to my slicers) calculated as below:

Measure = DISTINCTCOUNT(b[personID])/COUNT(a[ID])

where the numerator is the number of people that appear in table B (three in this example) and the denominator is the total number of people (five in this example, but this could be affected by slicers). My issue is with the denominator; when I create this bar graph with a bi-directional relationship between the tables, the bars show 100% because the COUNT(a[ID]), or the count of total number of people, gets broken down by car color (i.e., I want the calculation for "Blue" to be 3/5, but it's getting calculated as 3/3).

 

I don't have this issue if I use a single-direction relationship between the two tables, but I would prefer a bi-directional relationship so that I can cross-highlight when clicking on the bars. I'd appreciate any advice on how to do this; my first thought was to sum up the measure, but that doesn't seem possible without breaking down the counts by color.


Thanks in advance!

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @tt211595 

 

You can try the following methods.

vzhangti_0-1684135816680.png

Measure = 
var _a = COUNTROWS(FILTER(ALL('Table B'),[Car Color]=SELECTEDVALUE('Table B'[Car Color])))
var _b = CALCULATE(DISTINCTCOUNT('Table A'[personID]),CROSSFILTER('Table A'[personID],'Table B'[personID],OneWay_LeftFiltersRight))
return DIVIDE(_a,_b)

vzhangti_2-1684135910210.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @tt211595 

 

You can try the following methods.

vzhangti_0-1684135816680.png

Measure = 
var _a = COUNTROWS(FILTER(ALL('Table B'),[Car Color]=SELECTEDVALUE('Table B'[Car Color])))
var _b = CALCULATE(DISTINCTCOUNT('Table A'[personID]),CROSSFILTER('Table A'[personID],'Table B'[personID],OneWay_LeftFiltersRight))
return DIVIDE(_a,_b)

vzhangti_2-1684135910210.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Yes, exactly. Thank you so much!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.