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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
wsspglobal
Helper I
Helper I

Count Loop for mapping relationship

Hi,

 

I'm trying to do the below count exercise:

I have a mapping of ID-A to ID-B, and I want to define a universal mapping relationship either "One to Many", "Many to One" or "Many to Many". The purpose of the universal mapping is to make sure if I had to use one ID's revenue to calculate that of the other, I know how to split or combine the revenues. For example, if A11 has a revenue of $3,000 then B22, B23,B24 each gets $1,000. My idea is to count how many of each of the count of ID-A and ID-B is bigger than 1 and if that count is bigger than 0, then there is a "Many relationship". I wonder if there is a more efficient way to write it in Power BI without creating too many columns. Here's the result I did in Excel. This is what I wrote in the last column "= IF( E2>0, "Many B", "One B" ) & " to " & IF(F2>0, "many A ", "one A " )"

 

I'd like to create a column in table view not a measure. Thank you!

ABCDEFG
ID-AID-BCountIDACountIDBCount of CountIDA > 1Count of CountIDB > 1Mapping Relationship
A11B223232Many B to many A 
A11B233130Many B to one A 
A11B243130Many B to one A 
A21B131100One B to one A 
A32B341404One B to many A 
A33B341404One B to many A 
A34B341404One B to many A 
A35B341404One B to many A 
A45B222222Many B to many A 
A45B412120Many B to one A 
1 ACCEPTED SOLUTION

Hi , @wsspglobal 

Writing all to a calculated column will become more cumbersome.

It is recommended to calculate with multiple columns。

Please check the new file attached.

pbix attached

BTY ,you can try to hide the calculated column you don't need  in PowerBI report view.

51.png

 

Best Regards,
Community Support Team _ Eason

 

View solution in original post

4 REPLIES 4
v-easonf-msft
Community Support
Community Support

Hi , @wsspglobal 

Could you please tell me whether your problem has been solved?
If it is,  please mark the helpful replies or add your reply as Answered to close this thread.
It will help other community members easily find the solution when they get the similar issue.

Best Regards,
Community Support Team _ Eason

v-easonf-msft
Community Support
Community Support

Hi , @wsspglobal 

It seems that there is no need to create two auxiliary  columns,“CountIDA”,“Count of CountIDA > 1”.

It is enough to create a  column "CountID A >1 " , because the value of  "CountIDA" is eauql to the value of "Count of CountIDA".

 

Please try formula as below:

Mapping relationship =
VAR a =
    CALCULATE ( COUNT ( 'Table'[ID-A] ), ALLEXCEPT ( 'Table', 'Table'[ID-A] ) )
VAR b =
    CALCULATE ( COUNT ( 'Table'[ID-B] ), ALLEXCEPT ( 'Table', 'Table'[ID-B] ) )
VAR text1 =
    IF ( a > 1, "Many B", "One B" )
VAR text2 =
    IF ( b > 1, "many A", "one A" )
RETURN
    text1 & " to " & text2

The result will show as below:

27.png

Pbix attached 

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-easonf-msft 

 

Thanks for responding. I realized I made a mistake in my Excel table. Please the updated one below:

 

Column E and F has changed, so Column G changed as a result. Column E should be - for every ID-B, count where CountIDA is >1. Column F should be - for every ID-A, count where CountIDB is >1. This way, there should be a difference between your approach and my approach. Please help again. Thank you and sorry for the mistake. 

 

ABCDEFG
ID-AID-BCountIDACountIDBCount of CountIDA > 1Count of CountIDB > 1Mapping Relationship
A11B223221Many B to many A 
A11B233111Many B to many A 
A11B243111Many B to many A 
A21B131100One B to one A 
A32B341401One B to many A 
A33B341401One B to many A 
A34B341401One B to many A 
A35B341401One B to many A 
A45B222221Many B to many A 
A45B412111Many B to many A 

Hi , @wsspglobal 

Writing all to a calculated column will become more cumbersome.

It is recommended to calculate with multiple columns。

Please check the new file attached.

pbix attached

BTY ,you can try to hide the calculated column you don't need  in PowerBI report view.

51.png

 

Best Regards,
Community Support Team _ Eason

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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