Forum Discussion

MSW's avatar
MSW
Icon for Helper I rankHelper I
3 years ago
Solved

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:  ID Text 2 Apple 3 ...
  • lazurens2's avatar
    lazurens2
    3 years ago

    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.

  • tamerj1's avatar
    tamerj1
    3 years ago

    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.