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
ScottR-MT
Helper I
Helper I

How to Count Based on String from a Column in Related Table

Hi,

 

Been trying to find a solution for this.  I have two tables (A & B below) that are related and want to create a DAX measure that counts the number of records for "Alternate Name" separately from "Customer Name".  Currently, "Customer Name" is under the Rows section, and the other columns would be under the Values section.  Seems like a fairly simple task, but I just have not been able to solve it.  Each formula I have tried comes back with one error or another. Anyone have any ideas?

 

In the tables below, Table A is the transactions, Table B is the Customer Names, and The Data Visual Table at the bottom gives an example of what I am trying to measure.  The column in Red is what I am having trouble with.

 

Table A  Table B 
CustomerRecord # Customer NameAlternate Name
Customer 1Record 10 Customer 1Name A
Customer 1Record 11 Customer 2Name B
Customer 2Record 14 Customer 3Name C
Customer 2Record 25 Customer 4Name D
Customer 3Record 16   
Customer 3Record 17   
Customer 3Record 21   
Customer 4Record 13   
Name ARecord 22   
Name ARecord 24   
Name ARecord 19   
Name BRecord 23   
Name CRecord 20   
Name DRecord 12   
Name DRecord 15   
Name DRecord 18   
     
     
Data Table Visual    
Customer# Customer Name Records# Alternate Name Records  
Customer 123  
Customer 221  
Customer 331  
Customer 413  
1 ACCEPTED SOLUTION

5 REPLIES 5
Zubair_Muhammad
Community Champion
Community Champion

HI @ScottR-MT

 

Try this MEASURE in table B

 

# Alternate Name Records =
CALCULATE (
    COUNT ( TableA[Record #] ),
    FILTER (
        ALL ( TableA ),
        TableA[Customer] = SELECTEDVALUE ( TableB[Alternate Name] )
    )
)

Regards
Zubair

Please try my custom visuals

Thank you for the reply.  This did not work for me, but didn't give me an error this time, but rather no data.  If this helps, I am trying to get the number of transactions for a substituted customer name on the same row in my visual as the original customer name.  Is there perhaps another formula that can utilize the RELATED command to simplify the calculation?

@ScottR-MT

 

In the Tbale Visual ...are you using Customers from TAble A?


Regards
Zubair

Please try my custom visuals

@ScottR-MT

 

Please check this file with your sample data


Regards
Zubair

Please try my custom visuals

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.