Forum Discussion

WorkHard's avatar
WorkHard
Icon for Helper V rankHelper V
5 years ago
Solved

Count value while excluding text that contains a keyword

I'd like to count distinct results but exclude from this count entries that contain the keyword "This".

 

Sample Data:

IDDisplay As
1This value
2Other value
3This text
4Other text
5Other value
6Other value
7Other value

 

The result should be 5.

Here's what I've tried:

 

 

CountResult = 
CALCULATE (
    DISTINCTCOUNT(My Data[ID]),
    NOT SEARCH("This",My Data[Display As])
)

 

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi WorkHard

    I would create a column as

     

    NotThisColumn = SUBSTITUTE('Table'[Display As],"This ","")
    And then count 

     

    CALCULATE (
        DISTINCTCOUNT(My Data[NotThisColumn])
    )

     

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi WorkHard

    I would create a column as

     

    NotThisColumn = SUBSTITUTE('Table'[Display As],"This ","")
    And then count 

     

    CALCULATE (
        DISTINCTCOUNT(My Data[NotThisColumn])
    )

     

    • WorkHard's avatar
      WorkHard
      Icon for Helper V rankHelper V

      Appreciate the idea but I'd like to avoid creating helper columns unless strictly necessary. 

      The way I solved it is like this:

       

      CountResult =
      CALCULATE (
      DISTINCTCOUNT(My Data[ID]),
      FILTER ( My Data, SEARCH ( "This", My Data[Display As],, 0 ) = 0 )
      )

       

       

    • WorkHard's avatar
      WorkHard
      Icon for Helper V rankHelper V

      Ended up going with your original solution by creating an extra calculated column.

      Filtering the measure produces unexpected results in some contexts.