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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Pbiuserr
Post Prodigy
Post Prodigy

COUNTROW with OR/AND in filter measure

Hello,

I've got a measure which calculate in a wrong way. I believe its not hard for advanced pbi users, but the little description of how to handle that for the future would be benefitial for me 

 

Try to calculate every row which has RESOLVED collumn filled and is from Category1 + Category2.
I've break down this measure into two pieces to let it be easier to understood and here they are

 

Cat1 = CALCULATE(

Countrows(
filter(
'data', 'data'[RESOLVED] <> blank()
&& 'data'[CATEGORIES]="CAT1"
) ) ) - gives 1 (good)
 

Cat2 = CALCULATE(

Countrows(
filter(
'data', 'data'[RESOLVED] <> blank()
&& 'data'[CATEGORIES]="CAT2"
) ) ) - gives 14 (good)
 
however, when I try to combine them

CatTot = CALCULATE(

Countrows(
filter(
'data', 'data'[RESOLVED] <> blank()
&& 'data'[CATEGORIES]="CAT1" || 'data'[CATEGORIES]="CAT2"
) ) ) - gives bad result (suppose to be 15). Ignores BLANK

however:

CatTot = CALCULATE(

Countrows(
filter(
'data', 'data'[RESOLVED] <> blank()
&& 'data'[CATEGORIES]="CAT2" || 'data'[CATEGORIES]="CAT1"
) ) ) - gives good result, surprisingly - because when I reverse categories then I got bad results
 
Any ideas, tips?
Thank you in advance
1 ACCEPTED SOLUTION

@Pbiuserr,

 

You need to include all the filter expressions in the NOT clause:

 

blogunder15-30 =
CALCULATE (
    COUNTROWS ( 'data' ),
    FILTER (
        'data',
        NOT ( 'data'[CATEGORIES]
            IN { "CAT", "CAT2" }
            && 'data'[blogdays] >= 15
            && 'data'[blogdays] < 30 )
    )
)

 

Try to simplify:

 

blogunder15-30 =
CALCULATE (
    COUNTROWS ( 'data' ),
    FILTER (
        'data',
        NOT ( 'data'[CATEGORIES] IN { "CAT", "CAT2" } )
            && 'data'[blogdays] < 15
    )
)

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
DataInsights
Super User
Super User

@Pbiuserr,

 

The OR clause (||) needs to be enclosed in parentheses. Or, you can write it this way:

 

CatTot =
CALCULATE (
    COUNTROWS (
        FILTER (
            'data',
            'data'[RESOLVED] <> BLANK ()
                && 'data'[CATEGORIES] IN { "CAT1", "CAT2" }
        )
    )
)

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks. It works now. I'll later accept this as solution. Can you perhaps help me in this query

 

blogunder15-30 = CALCULATE(
COUNTROWS('data'),
    FILTER ('data',
                        NOT('data'[CATEGORIES] IN { "CAT", "CAT2" })
                         &&
'data'[blogdays] >= 15 && 'data'[blogdays] < 30
       )
)

it counts wrong. above 14 days as well. where is an issue?

@Pbiuserr,

 

You need to include all the filter expressions in the NOT clause:

 

blogunder15-30 =
CALCULATE (
    COUNTROWS ( 'data' ),
    FILTER (
        'data',
        NOT ( 'data'[CATEGORIES]
            IN { "CAT", "CAT2" }
            && 'data'[blogdays] >= 15
            && 'data'[blogdays] < 30 )
    )
)

 

Try to simplify:

 

blogunder15-30 =
CALCULATE (
    COUNTROWS ( 'data' ),
    FILTER (
        'data',
        NOT ( 'data'[CATEGORIES] IN { "CAT", "CAT2" } )
            && 'data'[blogdays] < 15
    )
)

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.