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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
powerbiuser12
Frequent Visitor

Count rows with multiple conditions

I would love to get some help in counting how many of the 'courses that count for credit' a 'person' has taken, i.e.; if you take a 'courses that counts for credit' twice you only recieve credit for one.  Right now all I have is the Person/Course Table.  My expected results are shown in the last table below.  e.g.; Eventhough Squares is a course that counts for credit, Bill only gets one credit when he actually took Squares twice. 

PersonCourse
BillSquares
BillSquares
BillTriangles
BobCircles
BobRectangles
LisaSquares
LisaTriangles
LisaRectangles
LisaRectangles
JenniferOvals
TomPolygons
DavidOvals
DavidSquares
DanielSquares

 

Courses that count for credit
Squares
Rectangles
Ovals

 

 Expected Output
Bill1
Bob1
Lisa2
Jennifer1
Tom0
David2
Daniel1
1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @powerbiuser12 

You can use something like this.

Counted Courses = 
VAR Countedcourses = {"Squares", "Rectangles", "Ovals"}
VAR TheCount = 
    CALCULATE (
        DISTINCTCOUNT ( YourTable[Course] ),
        YourTable[Course] IN ( Countedcourses )
    )
RETURN
    IF ( ISBLANK ( TheCount ), 0, TheCount )

View solution in original post

3 REPLIES 3
powerbiuser12
Frequent Visitor

Thanks for the super fast response @jdbuchanan71 !  It worked.  Hopefully I put this issue in generic enough terms others will gain value from it too.

I was trying to think of a way to do it using IF, Countrows, Distinct, and Filter but couldn't put all the pieces together.  Your solution is simple and elegant but seemingly a little more advanced to a new user like myself by creating variables.  Is there a "messier" version using more off-the-shelf functions in DAX perhaps that I should have been able to piece together?

 

Again thanks for the help.

One other solution I tried was to display the data in a Matrix with the Courses in the Rows and the Names in the Columns then apply a Visual level filter and select only the "Courses that counted for credit".  The downside is I have about 500+ names and the Matrix stops at about letter C in my alphabetical names list so I applied a data slicer to let the report user hone in on a name or set of names but the solved solution does what I was after better.

jdbuchanan71
Super User
Super User

Hello @powerbiuser12 

You can use something like this.

Counted Courses = 
VAR Countedcourses = {"Squares", "Rectangles", "Ovals"}
VAR TheCount = 
    CALCULATE (
        DISTINCTCOUNT ( YourTable[Course] ),
        YourTable[Course] IN ( Countedcourses )
    )
RETURN
    IF ( ISBLANK ( TheCount ), 0, TheCount )

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors