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
AdenJones
New Member

count rows in a table based upon another table and field

I am from a programming background and mostly familiar with SQL for developing reports. I am very keen to learn PowerBI but have come across something I haven't found a clear answer to.

 

Basically I have the following:

Table1

Participant IDParticipant Name
12Bob
24Gretel

Table2

Participant IDFamily ID
122
242

 

Based upon the Participant ID in Table1 I want to count all the Family IDs that are the same. So if bob has participant ID 12 in table1 then I want to count all rows in Table2 with the family id of Bob;s 12 Participant ID therefore it would count both rows in Table2 because both rows have the same participant id. Any help would be greatly appreciated.

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

Hi @AdenJones,

 

You can try to use below formula if it works for your scenario.

 

Calculate column to Table1:

Count From Another Table =
VAR familyList =
    CALCULATE (
        VALUES ( Table2[Family ID] ),
        FILTER (
            ALL ( Table2 ),
            Table2[Participant ID] = EARLIER ( Table1[Participant ID] )
        )
    )
RETURN
    COUNTROWS ( FILTER ( ALL ( Table2 ), [Family ID] IN familyList ) )


Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @AdenJones,

 

You can try to use below formula if it works for your scenario.

 

Calculate column to Table1:

Count From Another Table =
VAR familyList =
    CALCULATE (
        VALUES ( Table2[Family ID] ),
        FILTER (
            ALL ( Table2 ),
            Table2[Participant ID] = EARLIER ( Table1[Participant ID] )
        )
    )
RETURN
    COUNTROWS ( FILTER ( ALL ( Table2 ), [Family ID] IN familyList ) )


Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.