Forum Discussion
amon151
4 years agoFrequent Visitor
Countif for dynamic criteria range
Hello! I'm trying to replicate the excel COUNTIF function in DAX. I basically want to count the number of instances each value of column B appears in column A range. Excel Formula =COUNTIF($...
- 4 years ago
amon151 if a column then this is the code:
Output = VAR _b = 'Table'[Column B] VAR _result = COUNTROWS( FILTER( 'Table', 'Table'[Column A] = _b ) ) RETURN _resultIf a measure then this:
Output Measure = VAR _b = SELECTEDVALUE('Table'[Column B]) VAR _result = COUNTROWS( FILTER( ALL('Table'), 'Table'[Column A] = _b ) ) RETURN COALESCE(_result, "")
SpartaBI
4 years agoCommunity Champion
amon151 if a column then this is the code:
Output =
VAR _b = 'Table'[Column B]
VAR _result =
COUNTROWS(
FILTER(
'Table',
'Table'[Column A] = _b
)
)
RETURN
_result
If a measure then this:
Output Measure =
VAR _b = SELECTEDVALUE('Table'[Column B])
VAR _result =
COUNTROWS(
FILTER(
ALL('Table'),
'Table'[Column A] = _b
)
)
RETURN
COALESCE(_result, "")
amon151
4 years agoFrequent Visitor
The solution you provided for the column is just what I needed!!
Thank you so much for the quick response 👍
- SpartaBI4 years agoCommunity Champion
amon151 my pleasure 🙂
Check out my showcase report - got some high level stuff there. Sure you will find there a lot of cool ideas.
https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543
Give it a thumbs up over there if you liked it 🙂