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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

CountRows with ALL & FILTER

Hi community,

I am having difficulty trying to create a COUNTROWS measure that has both ALL & FILTER. This is my data structure,

ActivityNew/ContinuationRole
ANewTeacher
ANewTeacher
BNewStudent
BContinuationStudent
CNewStudent

 

I would like to COUNT only "New" rows, and also ignore the Roles when putting it in a Matrix that has Roles in Columns. Something like this,

ActivityTeacherStudent
A20
B01
C01

 

This is my current measure, but it does not ignore Roles when I place it in my matrix:

Measure = CALCULATE(COUNTROWS(Activity),
FILTER(Activity,Activity[New/Continuation]="New"),
ALL(Activity[Role]))
 
Could you let me know what has gone wrong? Thank you.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Your problem stems from the fact that you do something you should never do: putting a whole table as a filter in CALCULATE. Do not ever do it if you want to create correct formulas and stay sane. The golden rule of DAX is this: You must never filter a table if you can filter a column.

 

[Measure] =
CALCULATE(
    COUNTROWS( Activity ),
    KEEPFILTERS( Activity[New/Continuation] = "New" ),
    ALL( Activity[Role] )
)

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Your problem stems from the fact that you do something you should never do: putting a whole table as a filter in CALCULATE. Do not ever do it if you want to create correct formulas and stay sane. The golden rule of DAX is this: You must never filter a table if you can filter a column.

 

[Measure] =
CALCULATE(
    COUNTROWS( Activity ),
    KEEPFILTERS( Activity[New/Continuation] = "New" ),
    ALL( Activity[Role] )
)

 

Anonymous
Not applicable

Hi @Anonymous 

 

Thanks for pointing out my mistake Also really appreciate you explaining the approach I should take to avoid similar mistakes in the future!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.