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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
peetman
Frequent Visitor

Countrows if text is in one or the other column

Hi,

I have two columns where I want to find data and then count the number of rows found.

 

SWPR
SWSW
PRSS
TRTR

 

In the table above how can I count the number of rows where SW appears? Result expected would be 2.

 

I was trying to use the following, but successful.

Count SW covered = CALCULATE(COUNTROWS('Table1'),SEARCH("SW",OR('Col1','Col2'),,0))
 

 

Thanks

1 ACCEPTED SOLUTION

In that case, you can use the following:

 

Count SW Rows =
COUNTROWS (
    FILTER (
        SearchTable,
        SEARCH (
            "SW",
            SearchTable[Column1],
            ,
            0
        ) > 0
            || SEARCH (
                "SW",
                SearchTable[Column2],
                ,
                0
            ) > 0
    )
)

 

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

6 REPLIES 6
Icey
Community Support
Community Support

Hi @peetman ,

 

Please let us know if the latest reply of @mahoneypat could meet your requirements.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

mahoneypat
Employee
Employee

Please try this measure to get the rows with SW in them.  Replace SearchTable with your actual table name.

 

Count SW Rows = COUNTROWS(FILTER(SearchTable, "SW" in {SearchTable[Column1], SearchTable[Column2]}))
 
FYI you can use this expression to count the overall # of SW values.
Count SW = SUMX(SearchTable, COUNTROWS(FILTER({SearchTable[Column1], SearchTable[Column2]}, [Value] = "SW")))
 
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


Thanks. It does work.

I forgot to mention that sometimes is not explicitly written SW, but ASW or BSW. I've tried to use wildcards "*SW*" but it did not produce any result.

In that case, you can use the following:

 

Count SW Rows =
COUNTROWS (
    FILTER (
        SearchTable,
        SEARCH (
            "SW",
            SearchTable[Column1],
            ,
            0
        ) > 0
            || SEARCH (
                "SW",
                SearchTable[Column2],
                ,
                0
            ) > 0
    )
)

 

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


pranit828
Community Champion
Community Champion

Hi @peetman 

Count SW covered = CALCULATE(COUNTROWS('Table1'),SEARCH("SW",[Col1]) > 0  ||   SEARCH("SW",[Col2]) > 0)





PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile

Hello,

It does not work. Throws this error

 

The expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors