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
stu3000
Frequent Visitor

Measure to count rows which contain multiple test strings

Dear PowerBI Community, 
I'm looking for a dax-measure that counts the rows of th comissions-table which contain multiple codes that I have selected with a slicer.

The result in this case would be "2"

 

   slicer.jpgtable.jpg

So far I have found the containsstrings command, but I don't know how to combine the selected codes

Do you have any advise? 

3 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@stu3000 , Try a approch like this

Power BI- Text Part slicer to filter/search text - https://youtu.be/MKKWeOqFG4c

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

stu3000
Frequent Visitor

Dear @amitchandak 

thanks for your reply. It's a good approach, however I couldn't really solve the problem with it yet. Let me try to explain it better with the following example:

I have

  • the "CodesTable" with all the necessary Codes, which is also the data for the slicer.
  • the CommissionsTable with the Commission Numbers and the Codes which are basically all in on Column. In real life it's a huge table which I actually don't want to change if possible.

 

screenshot.jpg

So far I have the following measure which works fine when only one code is selected:

 

AffectedCommissions =

var selectedcode = SELECTEDVALUE(CodesTable[Codes])

RETURN

calculate(COUNT(CommissionsTable[CommissionNo]),CONTAINSSTRING(CommissionsTable[Codes],selectedcode))

 

However, if more than one code is selected with the slicer, only the rows which contain the selected codes should be counted. For example, if Codes 3, 4 and 5 are selected, then the result must be 2 (CommissionNo 3 and 6).

Furthermore, the Codes in the orders are not alway in the same order.
Is it possible to adjust the measure accordingly?

View solution in original post

Anonymous
Not applicable

Hi @stu3000 ,

Please try below steps:

1. below is my test table

Table1:

vbinbinyumsft_0-1675664295289.png

Table2:

vbinbinyumsft_1-1675664310285.png

2. create a measure with below dax formula

Measure =
VAR _a =
    ADDCOLUMNS (
        'Table2',
        "Flag",
            IF (
                SUMX (
                    ADDCOLUMNS (
                        SELECTCOLUMNS ( 'Table1', "Selected", [Slicer] ),
                        "Max Codes", IF ( CONTAINSSTRING ( [Codes], [Selected] ), 1, 0 )
                    ),
                    [Max Codes]
                )
                    = COUNTROWS ( SELECTCOLUMNS ( 'Table1', "Selected", [Slicer] ) ),
                1,
                0
            )
    )
RETURN
    SUMX ( _a, [Flag] )

3. add a slicer with field, add a cred visual with measure

vbinbinyumsft_2-1675664397800.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
stu3000
Frequent Visitor

Dear @amitchandak 

thanks for your reply. It's a good approach, however I couldn't really solve the problem with it yet. Let me try to explain it better with the following example:

I have

  • the "CodesTable" with all the necessary Codes, which is also the data for the slicer.
  • the CommissionsTable with the Commission Numbers and the Codes which are basically all in on Column. In real life it's a huge table which I actually don't want to change if possible.

 

screenshot.jpg

So far I have the following measure which works fine when only one code is selected:

 

AffectedCommissions =

var selectedcode = SELECTEDVALUE(CodesTable[Codes])

RETURN

calculate(COUNT(CommissionsTable[CommissionNo]),CONTAINSSTRING(CommissionsTable[Codes],selectedcode))

 

However, if more than one code is selected with the slicer, only the rows which contain the selected codes should be counted. For example, if Codes 3, 4 and 5 are selected, then the result must be 2 (CommissionNo 3 and 6).

Furthermore, the Codes in the orders are not alway in the same order.
Is it possible to adjust the measure accordingly?

Anonymous
Not applicable

Hi @stu3000 ,

Please try below steps:

1. below is my test table

Table1:

vbinbinyumsft_0-1675664295289.png

Table2:

vbinbinyumsft_1-1675664310285.png

2. create a measure with below dax formula

Measure =
VAR _a =
    ADDCOLUMNS (
        'Table2',
        "Flag",
            IF (
                SUMX (
                    ADDCOLUMNS (
                        SELECTCOLUMNS ( 'Table1', "Selected", [Slicer] ),
                        "Max Codes", IF ( CONTAINSSTRING ( [Codes], [Selected] ), 1, 0 )
                    ),
                    [Max Codes]
                )
                    = COUNTROWS ( SELECTCOLUMNS ( 'Table1', "Selected", [Slicer] ) ),
                1,
                0
            )
    )
RETURN
    SUMX ( _a, [Flag] )

3. add a slicer with field, add a cred visual with measure

vbinbinyumsft_2-1675664397800.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

this works perfectly. Thanks, Binbin Yu!!

amitchandak
Super User
Super User

@stu3000 , Try a approch like this

Power BI- Text Part slicer to filter/search text - https://youtu.be/MKKWeOqFG4c

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.