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

unique count of filter text

Hello,

 

I am looking to create a measure that shows unique count for each name. We have a column names but as the field is multi select it combines multi names into one text value. 

 

ex. column value1 = Name1; Name2; Name3

ex. column value2 = Name1; Name3

 

What I want to see is how many rows have Name1 or Name2 or etc.

 

Name1 = 2

Name2 = 1

Name3 = 2

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @ap12 

It would be easy if you have a name_table with all the names:

v-xiaotang_0-1619146040433.png

Then, create a measure:

 

countrows =
VAR _name =
    MAX ( 'name table'[name] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        CONTAINSSTRING ( 'Table'[column name], _name )
)

 

you will get the following:

v-xiaotang_1-1619145829394.png

Hope this helps.

 

Best Regards,

Community Support Team _ Tang

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

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @ap12 

It would be easy if you have a name_table with all the names:

v-xiaotang_0-1619146040433.png

Then, create a measure:

 

countrows =
VAR _name =
    MAX ( 'name table'[name] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        CONTAINSSTRING ( 'Table'[column name], _name )
)

 

you will get the following:

v-xiaotang_1-1619145829394.png

Hope this helps.

 

Best Regards,

Community Support Team _ Tang

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

MFelix
Super User
Super User

Hi @ap12 ,

 

I have made a similar approach but instead of a count I matched the words with found not found, making some adjustments I was abble to get the final result.

 

For this you need to have an additional table with all the names then add the following measure:

 

 

Name Count =
// Character that split phrase into words
VAR SplitByCharacter = "; " // Temporary table that splits selected phrase into words
VAR Words_table_column_1 =
    ADDCOLUMNS (
        GENERATE (
            SELECTCOLUMNS ( ALLSELECTED ( Base[Column1] ), "Find_Text", Base[Column1] ),
            VAR TokenCount =
                PATHLENGTH ( SUBSTITUTE ( [Find_Text], SplitByCharacter, "|" ) )
            RETURN
                GENERATESERIES ( 1, TokenCount )
        ),
        "Word", PATHITEM ( SUBSTITUTE ( [Find_Text], SplitByCharacter, "|" ), [Value] )
    )
VAR Words_table_column_2 =
    ADDCOLUMNS (
        GENERATE (
            SELECTCOLUMNS ( ALLSELECTED ( Base[Column2] ), "Find_Text", Base[Column2] ),
            VAR TokenCount =
                PATHLENGTH ( SUBSTITUTE ( [Find_Text], SplitByCharacter, "|" ) )
            RETURN
                GENERATESERIES ( 1, TokenCount )
        ),
        "Word", PATHITEM ( SUBSTITUTE ( [Find_Text], SplitByCharacter, "|" ), [Value] )
    )
RETURN
    SUMX (
        Words_table_column_1,
        FIND ( UPPER ( [Word] ), UPPER ( SELECTEDVALUE ( 'Table'[Names] ) ),, 0 )
    )
        + SUMX (
            Words_table_column_2,
            FIND ( UPPER ( [Word] ), UPPER ( SELECTEDVALUE ( 'Table'[Names] ) ),, 0 )
        )

 

 

Then setup you visualization with the names from the names tables and this measure:

MFelix_1-1619092006321.png

 

This solution was created using has reference the links below:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Find-Words-on-sentence-from-another-selected...

DAX : Pivot Text into a List of Words 

DAX – “CONTAINSX” – Finding if a value in table 1 has a matching value in table 2 

 

Check PBIX file attach.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.