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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
MSW
Helper I
Helper I

Counting Text occurrences per Unique ID

Hello. I am trying to figure out how to make a measure to count the number of times a specific text appears in a column based on a Unique ID

 

Would look like this: 

IDText
2Apple
3Bannana
1Apple
2Bannana
3Kiwi
2Bannana
3Apple
1Bannana

 

When I wanted to count say "Bannna' it would give me 3 -- it would not count banana twice for the same ID. Apple would give me 3 and Kiwi would give me 1. 

2 ACCEPTED SOLUTIONS
lazurens2
Frequent Visitor

I am getting 3 for Bannana with this DAX Measure : 

CountTextById = Calculate ( 
    COUNTROWS ( VALUES ( 'Fruits'[ID] ) ),
    FILTER(ALL('Fruits'), 'Fruits'[Text] = "Bannana")
)

Tell me if it works for you.

View solution in original post

tamerj1
Community Champion
Community Champion

@MSW 

Yes but if you select a [Text] from the slicer it will give you the right number. Similirly if you place [Text] along with this measure in a table visual it should give the correct count for each text. If you are interested in summing these counts you can use

=
SUMX (
    VALUES ( 'Table'[Text] ),
    COUNTROWS ( CALCULATETABLE ( VALUES ( 'Table'[ID] ) ) )
)

This will give you 3 for banana, 3 for apple, 1 for kiwi and 7 for total. The total will change depending on the selected [Text] values. For example if you select "banana" and "kiwi" the total would be 4. You'll get the same number when using a card visual.

View solution in original post

4 REPLIES 4
tamerj1
Community Champion
Community Champion

Hi @MSW 

you may try

DISTINCTCOUNT ( 'Table'[ID] )

or

COUNTROWS ( VALUES ( 'Table'[ID] ) )

That doesn't give me the count based on the text criteria. That is giving me the total unique IDs of 3. I want to look at how many times a text criteria exists and only count it once per ID in the table.

tamerj1
Community Champion
Community Champion

@MSW 

Yes but if you select a [Text] from the slicer it will give you the right number. Similirly if you place [Text] along with this measure in a table visual it should give the correct count for each text. If you are interested in summing these counts you can use

=
SUMX (
    VALUES ( 'Table'[Text] ),
    COUNTROWS ( CALCULATETABLE ( VALUES ( 'Table'[ID] ) ) )
)

This will give you 3 for banana, 3 for apple, 1 for kiwi and 7 for total. The total will change depending on the selected [Text] values. For example if you select "banana" and "kiwi" the total would be 4. You'll get the same number when using a card visual.

lazurens2
Frequent Visitor

I am getting 3 for Bannana with this DAX Measure : 

CountTextById = Calculate ( 
    COUNTROWS ( VALUES ( 'Fruits'[ID] ) ),
    FILTER(ALL('Fruits'), 'Fruits'[Text] = "Bannana")
)

Tell me if it works for you.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.