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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
sharpedogs
Advocate II
Advocate II

Calculate function for contains and does not contain at the same time.

I have a column with a variety of license that each person has been assigned, as per column below.

I need a few measures so that I can report against certian license groupings, for example

 

1) Count rows that CONTAIN "Office 365" - it should count 2

2) Count rows that ONLY HAS "Office 365" - it should count 0

3) Count rows that CONTAIN "Office 365" and "Visio" - it should count 2  

4) Count rows that CONTAIN "Office 365" Does NOT Contain "Word" - it should count 1

 

Licenses
Office 365 + Word + Visio
Visio + Project

Office 365 + Visio

Project + Visio

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@sharpedogs , 1 and 2 and are contradictory

 

You can use https://docs.microsoft.com/en-us/dax/containsstring-function-dax

 

with Switch true()

 

example  -- Correct logic as per need. Order is also important

Switch (
CONTAINSSTRING('Table'[NAME],"Office 365") && CONTAINSSTRING('Table'[NAME],"Visio"), 2,
not(CONTAINSSTRING('Table'[NAME],"Office 365")) ,0 ,
CONTAINSSTRING('Table'[NAME],"Office 365") && not(CONTAINSSTRING('Table'[NAME],"Word")) , 1,
0)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

harshnathani
Community Champion
Community Champion

HI @sharpedogs ,

 

 

You can try these measures

 

Only has Office365 =
VAR _texttobefound = "Office 365"
VAR _lengthoftext =
    LEN ( _texttobefound )
RETURN
    COUNTROWS (
        FILTER (
            'Table',
            CONTAINSSTRING (
                'Table'[Licenses],
                _texttobefound
            )
                && LEN ( 'Table'[Licenses] ) = _lengthoftext
        )
    )

 

Contains Office365 & Visio =
VAR _texttobefound1 = "Office 365"
VAR _texttobefound2 = "Visio"
RETURN
    COUNTROWS (
        FILTER (
            'Table',
            CONTAINSSTRING (
                'Table'[Licenses],
                _texttobefound1
            )
                && CONTAINSSTRING (
                    'Table'[Licenses],
                    _texttobefound2
                )
        )
    )

 

Contains Office365 & not Word =
VAR _texttobefound1 = "Office 365"
VAR _textnottobefound2 = "Word"
RETURN
    COUNTROWS (
        FILTER (
            'Table',
            CONTAINSSTRING (
                'Table'[Licenses],
                _texttobefound1
            )
                && NOT CONTAINSSTRING (
                    'Table'[Licenses],
                    _textnottobefound2
                )
        )
    )

 

Contains Office365 =
COUNTROWS (
    FILTER (
        'Table',
        CONTAINSSTRING (
            'Table'[Licenses],
            "Office 365"
        )
    )
)

 

 

1.jpg

 

 

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

View solution in original post

3 REPLIES 3
harshnathani
Community Champion
Community Champion

HI @sharpedogs ,

 

 

You can try these measures

 

Only has Office365 =
VAR _texttobefound = "Office 365"
VAR _lengthoftext =
    LEN ( _texttobefound )
RETURN
    COUNTROWS (
        FILTER (
            'Table',
            CONTAINSSTRING (
                'Table'[Licenses],
                _texttobefound
            )
                && LEN ( 'Table'[Licenses] ) = _lengthoftext
        )
    )

 

Contains Office365 & Visio =
VAR _texttobefound1 = "Office 365"
VAR _texttobefound2 = "Visio"
RETURN
    COUNTROWS (
        FILTER (
            'Table',
            CONTAINSSTRING (
                'Table'[Licenses],
                _texttobefound1
            )
                && CONTAINSSTRING (
                    'Table'[Licenses],
                    _texttobefound2
                )
        )
    )

 

Contains Office365 & not Word =
VAR _texttobefound1 = "Office 365"
VAR _textnottobefound2 = "Word"
RETURN
    COUNTROWS (
        FILTER (
            'Table',
            CONTAINSSTRING (
                'Table'[Licenses],
                _texttobefound1
            )
                && NOT CONTAINSSTRING (
                    'Table'[Licenses],
                    _textnottobefound2
                )
        )
    )

 

Contains Office365 =
COUNTROWS (
    FILTER (
        'Table',
        CONTAINSSTRING (
            'Table'[Licenses],
            "Office 365"
        )
    )
)

 

 

1.jpg

 

 

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

amitchandak
Super User
Super User

@sharpedogs , 1 and 2 and are contradictory

 

You can use https://docs.microsoft.com/en-us/dax/containsstring-function-dax

 

with Switch true()

 

example  -- Correct logic as per need. Order is also important

Switch (
CONTAINSSTRING('Table'[NAME],"Office 365") && CONTAINSSTRING('Table'[NAME],"Visio"), 2,
not(CONTAINSSTRING('Table'[NAME],"Office 365")) ,0 ,
CONTAINSSTRING('Table'[NAME],"Office 365") && not(CONTAINSSTRING('Table'[NAME],"Word")) , 1,
0)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks.... that's exactly the function I needed...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors