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 " )
You need to write a formula like which will count all the rows containing "This Value"
CountValues = CALCULATE ( COUNTROWS ( TableName ); TableName[ColumnName] = " This Value " )
how would I utilized this formula to look for multiple values in the same column? using this example I would want to count rows that have "This Value" "That Value" "It Value" etc. Thank you so much
- DouweMeer6 years agoImpactful Individual
Old question with an old post :). Hope this is what your looking for:
Mentioned earlier:
So something like:
count name =
VAR a1 =
selectcolumns (
filter ( table , containsstring ( 'table'[Name] , 'distinct table'[name] )
, "stuff" , 'table'[name]
)
RETURN
countrows ( a1 )
Solution would be by changing the return to:
countrows ( filter ( a1 , [stuff] = "This Value" ) )
"This Value" can also be replaced by a value from its own table. Just make sure you use a 'table'[column] instead of only [column] as [column] doesn't exist in table reference a1.
Alternatively as addition after a1 statement in the intial expression :
VAR a2 = countrows ( filter ( a1 , [stuff] = "This Value" ) )
VAR a3 = countrows ( filter ( a1 , [stuff] = "That Value" ) )
VAR a4 = countrows ( filter ( a1 , [stuff] = "It Value" ) )
RETURN
"Count 'This Value' " & a2 & ". Count 'That Value' " & a3 ". Count 'It Value' " & a4.
Shouldn't be too difficult :).
- rgreener6 years agoFrequent Visitor
Thank you, works perfect!