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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
DHB
Helper V
Helper V

Filtered Count Between 2 Tables

I have two tables that look a little like this;

 

'Courses'

[Course_ID]

A

B

C

D

E

 

'Course Assignments'

[Course_ID]    

A

C

D

B

B

E

A

 

I'm trying to calculate the number of assignments for each course in the 'Course' table so that I'd get 

[Course_ID]         [Assignment_Count]

A                                           2

B                                           2

C                                           1

D                                           1

E                                            1

 

My DAX for this won't work.  It reads;

 

Assignment_Count =

COUNTA('Course Assignments'[ASSIGNMENT_ID]),FILTER('Course Assignments'[COURSE_ID]='Courses'[COURSE_ID])

 

Can anyone see what I'm doing wrong?

 

Thank you in advance.

 

Daniel.

1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee

You can create proper relationship between those two tables, then no measure is needed.

Capture.PNG

 

Alternatively, if no relationship, a measure as below works as well.

Assignment_Count =
CALCULATE (
    COUNTA ( 'Course Assignments'[ASSIGNMENT_ID] ),
    FILTER (
        'Course Assignments',
        'Course Assignments'[ASSIGNMENT_ID] = LASTNONBLANK ( Courses[Course_ID], "" )
    )
)

Capture.PNG

 

See the attached pbix file.

View solution in original post

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee

You can create proper relationship between those two tables, then no measure is needed.

Capture.PNG

 

Alternatively, if no relationship, a measure as below works as well.

Assignment_Count =
CALCULATE (
    COUNTA ( 'Course Assignments'[ASSIGNMENT_ID] ),
    FILTER (
        'Course Assignments',
        'Course Assignments'[ASSIGNMENT_ID] = LASTNONBLANK ( Courses[Course_ID], "" )
    )
)

Capture.PNG

 

See the attached pbix file.

Thank you, that's just what I need.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.