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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Mumin192
Helper I
Helper I

count rows with many search conditions

Hello
I want to count rows that has the words "Basal" and "Rapid" but doens't contain "Premix" and "GLP"
The measure equation that I'm using is not giving the right solution
Any suggestions?
 
Basal +Rapid = CALCULATE(COUNT(PRF[INTNR]),SEARCH("Basal",PRF[Q15],,0)<>0,SEARCH("Rapid",PRF[Q15],,0)<>0,SEARCH("Premix",PRF[Q15],,0)=0,SEARCH("GLP",PRF[Q15],,0)=0)/CALCULATE(COUNT(PRF[INTNR]))
1 ACCEPTED SOLUTION
TomasAndersson
Solution Sage
Solution Sage

Hi!
CONTAINSSTRING() is probably a better function for this. I'm unsure if you want to use AND or OR as your operators for the required and forbidden words, so you would have to adjust accordingly, but something like this (also adjust table and columns names to your model):

AND in both cases:

Basal + Rapid = 
CALCULATE(COUNT('Table'[Words]),
    AND(CONTAINSSTRING('Table'[Words],"Basal"),CONTAINSSTRING('Table'[Words],"Rapid")) && 
    NOT AND(CONTAINSSTRING('Table'[Words],"Premix"),CONTAINSSTRING('Table'[Words],"GLP"))
    )

 
OR in both cases:

Basal + Rapid = 
CALCULATE(COUNT('Table'[Words]),
    OR(CONTAINSSTRING('Table'[Words],"Basal"),CONTAINSSTRING('Table'[Words],"Rapid")) && 
    NOT OR(CONTAINSSTRING('Table'[Words],"Premix"),CONTAINSSTRING('Table'[Words],"GLP"))
    )

 

Hope this helps!

View solution in original post

2 REPLIES 2
themistoklis
Community Champion
Community Champion

@Mumin192 

 

I used your formula and changed it a bit using the OR and AND statements.

So my twicked formula count the rows that contain 'Basal' or 'Rapid' texts AND do not contain the text 'Premix' or 'GLP'

 

  

Basal +Rapid =
CALCULATE (
    COUNT ( PRF[INTNR] ),
    FILTER (
        ALL ( PRF ),
        (
            SEARCH ( "Basal", PRF[Q15],, BLANK () ) > 0
                || SEARCH ( "Rapid", PRF[Q15],, BLANK () ) > 0
        )
            && (
                SEARCH ( "Premix", PRF[Q15],, BLANK () ) = 0
                    || SEARCH ( "GLP", PRF[Q15],, BLANK () ) = 0
            )
    )
)
    / CALCULATE ( COUNT ( PRF[INTNR] ) )
TomasAndersson
Solution Sage
Solution Sage

Hi!
CONTAINSSTRING() is probably a better function for this. I'm unsure if you want to use AND or OR as your operators for the required and forbidden words, so you would have to adjust accordingly, but something like this (also adjust table and columns names to your model):

AND in both cases:

Basal + Rapid = 
CALCULATE(COUNT('Table'[Words]),
    AND(CONTAINSSTRING('Table'[Words],"Basal"),CONTAINSSTRING('Table'[Words],"Rapid")) && 
    NOT AND(CONTAINSSTRING('Table'[Words],"Premix"),CONTAINSSTRING('Table'[Words],"GLP"))
    )

 
OR in both cases:

Basal + Rapid = 
CALCULATE(COUNT('Table'[Words]),
    OR(CONTAINSSTRING('Table'[Words],"Basal"),CONTAINSSTRING('Table'[Words],"Rapid")) && 
    NOT OR(CONTAINSSTRING('Table'[Words],"Premix"),CONTAINSSTRING('Table'[Words],"GLP"))
    )

 

Hope this helps!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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