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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Anonymous
Not applicable

countrows ignoring filter

hello,

 

trying to compare a count of multiple transaction vs single transactions.

i have a table with 2 columns, first one is GATEVISITNUMBER, second column is NBR

 

GATEVISITNUMBER is the primary key, and NBR is a unique number that represent different transaction associated with GATEVISITNUMBERS

for example:

 

GATEVISITNUMBER     NBR

1                                   1

1                                   2

2                                   3

3                                   4

4                                   5

4                                   6

5                                   7

 

my measures:

count nbr measure = count(N4_TruckTransactions[NBR])
single transaction = CALCULATE(count(N4_TruckTransactions[GATEVISITNUMBER]),filter(N4_TruckTransactions,[count nbr measure]=1))
double transaction = CALCULATE(count(N4_TruckTransactions[GATEVISITNUMBER]),filter(N4_TruckTransactions,[count nbr measure]=2))
 
but however the Single measure is returning all rows
and Double measure returning blanks.
 
what am i doing wrong? or if there is a better way to do this?
 
thank you

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this small change instead.  There is something called context transition that happens with you use a measure in your FILTER evaluation.  It is a good thing but, since you are filtering the whole table, a filter is created on both columns and every row returns 1.  That is what your first one gets all rows and your second one gets none.  To get your desired result, you just want to filter the one column.

 

single transaction =
COUNTROWS(
    FILTER (
        DISTINCT ( N4_TruckTransactions[GATEVISITNUMBER] ),
        [count nbr measure] = 1
    )
)

 

And then use same but with = 2 for second measure

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this small change instead.  There is something called context transition that happens with you use a measure in your FILTER evaluation.  It is a good thing but, since you are filtering the whole table, a filter is created on both columns and every row returns 1.  That is what your first one gets all rows and your second one gets none.  To get your desired result, you just want to filter the one column.

 

single transaction =
COUNTROWS(
    FILTER (
        DISTINCT ( N4_TruckTransactions[GATEVISITNUMBER] ),
        [count nbr measure] = 1
    )
)

 

And then use same but with = 2 for second measure

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

thanks Pat ,

 it works!

😀👍

but can you explain a little more on 
"a filter is created on both columns and every row returns"

still don't understand why first measure returns all rows and second returns blanks.

 

i first thought calculate() and filter() always goes together, but apperently not.

and when do I need to use the calculate() ?

Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors