Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello,
I have come across a CALCULATE behaviour that I cannot quite understand, but I believe it is a basic think about how it works:
I have this dummy table:
Now I want to calculate the percentage of Female:
This works fine when no filter is applied:
But when I filter by Gender, it is giving me some unexcpected results:
But when I filter by GenderCopy (exact copy of Gender Column), I get the expected results:
Could someone please give me an easy to understand explanation why the value is different when filtering by the duplicate column? And why am I getting 43%?
Warm regards,
Jakub
Solved! Go to Solution.
Hi @jdusek92
The short explanation is that filter arguments in CALCULATE overwrite existing filters by default.
Just restating your measure here for reference:
Female% =
CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Gender] = "F" )
/ COUNTROWS ( 'Table' )
In your example, the "numerator "of your Female% measure overwrites any existing filter on 'Table'[Gender] and replaces it with 'Table'[Gender] = "F".
This default behaviour can be changed so that filter arugments instead intersect with existing filters, by wrapping them in KEEPFILTERS. I suspect that you may want to rewrite your measure as follows, rather than using GenderCopy:
Female% =
CALCULATE ( COUNTROWS ( 'Table' ), KEEPFILTERS ( 'Table'[Gender] = "F" ) )
/ COUNTROWS ( 'Table' )
To explain the results you were getting originally:
There are numerous articles on this topic out there, and these may be good ones to start with:
https://www.sqlbi.com/articles/using-keepfilters-in-dax/
https://www.sqlbi.com/articles/filter-arguments-in-calculate/
Regards,
Owen
Hi @jdusek92
The short explanation is that filter arguments in CALCULATE overwrite existing filters by default.
Just restating your measure here for reference:
Female% =
CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Gender] = "F" )
/ COUNTROWS ( 'Table' )
In your example, the "numerator "of your Female% measure overwrites any existing filter on 'Table'[Gender] and replaces it with 'Table'[Gender] = "F".
This default behaviour can be changed so that filter arugments instead intersect with existing filters, by wrapping them in KEEPFILTERS. I suspect that you may want to rewrite your measure as follows, rather than using GenderCopy:
Female% =
CALCULATE ( COUNTROWS ( 'Table' ), KEEPFILTERS ( 'Table'[Gender] = "F" ) )
/ COUNTROWS ( 'Table' )
To explain the results you were getting originally:
There are numerous articles on this topic out there, and these may be good ones to start with:
https://www.sqlbi.com/articles/using-keepfilters-in-dax/
https://www.sqlbi.com/articles/filter-arguments-in-calculate/
Regards,
Owen
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
20 | |
7 | |
6 | |
5 | |
5 |
User | Count |
---|---|
26 | |
10 | |
10 | |
9 | |
6 |