Forum Discussion
DAX function to count specific text values from a column
- 10 years ago
You need to write a formula like which will count all the rows containing "This Value"
CountValues = CALCULATE ( COUNTROWS ( TableName ); TableName[ColumnName] = " This Value " )
Hi konstantinos ,
I tried the DAX you provided, the formula returned a count of one when it should've returned a count of two. Any Idea on what I did wrong?
Regards,
Gus Dahu
How about you guys use 'selectcolumns'. This DAX command creates a table reference and combined with 'filter', each row of the table is checked against a boolean expression. 'containstring' can be used to validate whether a value exist in the record value.
So something like:
count name =
VAR a1 =
selectcolumns (
filter ( table , containsstring ( 'table'[Name] , 'distinct table'[name] )
, "stuff" , 'table'[name]
)
RETURN
countrows ( a1 , [stuff] )
You could ofcourse make the calculation over its own table. Then you first have to set the whole table up in an earlier VAR and refer at filter ( 'table' to that VAR instead of 'table'. If you want this as a measure, you have to add some value like name into the VAR before the table reference as VAR = 'selectedvalue'. Should do the trick.