Forum Discussion
Count( if column value = string)
- 7 years ago
Anonymous add new measure with following expression
MyBalanceCount = CALCULATE( COUNTROWS( MyTable ), MyTable[Location] = "In Storage" ) - CALCULATE( COUNTROWS( MyTable ), MyTable[Location] = "Out Storage" )
Hello,
The syntax for checking if a column's string value equals a certain value in DAX is to use the "=" operator inside the IF statement. Here's the correct syntax for your calculation:
COUNT(IF(Table[Location] = "In Storage 1", 1, BLANK())) - COUNT(IF(Table[Location] = "Out Storage 1", 1, BLANK()))
Note that the BLANK() function should be used instead of 0 in the IF statement to avoid incorrect results. Also, if you want to include all rows that don't match the conditions, you can use the COUNTROWS function outside the IF statements, like this:
COUNTROWS(Table) - COUNT(IF(Table[Location] = "In Storage 1", 1, BLANK())) - COUNT(IF(Table[Location] = "Out Storage 1", 1, BLANK()))
This will give you the count of rows that don't match the conditions.
I hope this helps! Let me know if you have any further questions.