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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

DAX function to count matched text values among rows

Hi,

 

I'm new to Power BI and hope someone could help me on this! Thank you for your help in advance!

I have a table with ItemName and Category as shown below. I want to create a slicer on ItemName for users to select and an output table shows the number of categories that can be found in the category of selected ItemName for the rest of ItemName. 

ItemNameCategory
Applered, sweet, juicy
Grapepurple, green, sweet
Bananayellow, curved
Orangesweet, juicy

 

Example: If a user selects "Apple" from the slicer of ItemName, the output table would be shown as below. The categories with underline are the category names found in the category of Apple (i.e. red, sweet, juicy). For example, Grape only has sweet category matched with one of the category of Apple so the number of overlapped category is 1.

ItemNameCategoryNumber of Overlapped Category
Grapepurple, green, sweet1
Bananayellow, curved0
Orangesweet, juicy2

 

Thanks again!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I suggest having an additional table like below for creating a slicer.

 

 

Jihwan_Kim_1-1663739335754.png

 

 

Please check the below picture and the attached pbix file.

It is for creating measures.

 

Jihwan_Kim_2-1663739351321.png

 

 

 

Jihwan_Kim_0-1663739311111.png

 

 

Category measure: = 
IF (
    HASONEVALUE ( 'Item'[ItemName] ),
    MAXX (
        FILTER ( 'Item', NOT ( 'Item'[ItemName] IN DISTINCT ( Category[ItemName] ) ) ),
        'Item'[Category]
    )
)

 

 

 

Number of overlapped category: = 
VAR _selectedcategory =
    DISTINCT ( Category[Category] )
VAR _currentrowitemnamecategory =
    SUMMARIZE (
        FILTER ( ALL ( Category ), Category[ItemName] = MAX ( 'Item'[ItemName] ) ),
        Category[Category]
    )
RETURN
    IF (
        ISFILTERED ( Category[ItemName] ) && NOT ISBLANK ( [Category measure:] ),
        COUNTROWS ( INTERSECT ( _selectedcategory, _currentrowitemnamecategory ) )
    )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I suggest having an additional table like below for creating a slicer.

 

 

Jihwan_Kim_1-1663739335754.png

 

 

Please check the below picture and the attached pbix file.

It is for creating measures.

 

Jihwan_Kim_2-1663739351321.png

 

 

 

Jihwan_Kim_0-1663739311111.png

 

 

Category measure: = 
IF (
    HASONEVALUE ( 'Item'[ItemName] ),
    MAXX (
        FILTER ( 'Item', NOT ( 'Item'[ItemName] IN DISTINCT ( Category[ItemName] ) ) ),
        'Item'[Category]
    )
)

 

 

 

Number of overlapped category: = 
VAR _selectedcategory =
    DISTINCT ( Category[Category] )
VAR _currentrowitemnamecategory =
    SUMMARIZE (
        FILTER ( ALL ( Category ), Category[ItemName] = MAX ( 'Item'[ItemName] ) ),
        Category[Category]
    )
RETURN
    IF (
        ISFILTERED ( Category[ItemName] ) && NOT ISBLANK ( [Category measure:] ),
        COUNTROWS ( INTERSECT ( _selectedcategory, _currentrowitemnamecategory ) )
    )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

It works! Thank you!!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.