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
Buatti
Frequent Visitor

Grouping a Measure by a field in a related table

Hi all, first time post!

I'm trying to create a visual that shows the results of a measure of a field in Table A, grouped by a field in a related table (Table B). 

Capture.PNG

 

The Measure I have is:

# Premium Customers =
CALCULATE (
COUNT ( 'Table A'[Customer ID] ),
'Table A'[Customer Class] = "Premium"
)

 

I want to create a visual that shows the number of Premium Customers (in Table A) by Magazine Subscription (in Table B) but come up with this:

Buatti_0-1655730803809.png

 

I have discovered that if I change the relationship between the tables so that Cross filter direction is Both, I can get the desired result (below). However I have read that this is not best practice - is there a reasonable alternative?

Buatti_1-1655730920445.png

 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Buatti ;

Try it.

# Premium Customers = 
IF (
    ISINSCOPE ( TableB[Magazine Sub] ),
    CALCULATE (
        COUNT ( 'TableB'[Customer ID] ),
        'Table A'[Customer Class] = "Premium"
    ),
    CALCULATE (
        COUNT ( 'Table A'[Customer ID] ),
        'Table A'[Customer Class] = "Premium"
    )
)

The final show:

vyalanwumsft_0-1655967905752.png

You need to use 'TableB'[Customer ID] , You can use my measure and establish a two-way relationship to see if the result is the same.
Best Regards,
Community Support Team _ Yalan Wu
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

7 REPLIES 7
v-yalanwu-msft
Community Support
Community Support

Hi, @Buatti ;

Try it.

# Premium Customers = 
IF (
    ISINSCOPE ( TableB[Magazine Sub] ),
    CALCULATE (
        COUNT ( 'TableB'[Customer ID] ),
        'Table A'[Customer Class] = "Premium"
    ),
    CALCULATE (
        COUNT ( 'Table A'[Customer ID] ),
        'Table A'[Customer Class] = "Premium"
    )
)

The final show:

vyalanwumsft_0-1655967905752.png

You need to use 'TableB'[Customer ID] , You can use my measure and establish a two-way relationship to see if the result is the same.
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thanks for your suggestion however this doesn't address my original problem. I want to count the number of records in Table A and group by the Magazine Subscription in Table B. That way I can also see the number of customers who don't have a magazine subscription. I am unsure why this has been marked as a solution.

Ashish_Mathur
Super User
Super User

Hi,

Let the relationship remain as Many to One and Single.  In Table B, write a calculated column formula to bring over the Customer Class from Table A.  The calculated column formula should be C_Class = related('TableA'[Customer Class]).  To your visual, drag the Magazine subscription from Table B and write this measure

Measure = calculate(distinctcount('Table B'[Customer ID]),'Table B'[C_Class] ="Premium")

Hope this helps.


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

Thanks Ashish, however this counts the Customer IDs in Table B (Magazine Subscriptions). I want to count the number of Customers (Table A) regardless if they have a subscription or not. Is it possible to count the records in Table A and group by a field in Table B?

Hi,

Share the link from where i can download your PBI file.


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

Thanks for the suggestion, however the output is the same. Is there another way to replicate the cross filtering without changing the relationship?

 

Buatti_0-1655768465100.png

 

amitchandak
Super User
Super User

@Buatti , Try like

 

# Premium Customers =
CALCULATE (
COUNT ( 'Table A'[Customer ID] ),
filter('Table A', 'Table A'[Customer Class] = "Premium")
)

 

refer

http://dataap.org/blog/2019/04/22/difference-between-calculate-with-and-without-filter-expression/

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.