Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
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($A:$A,B2)
I came across the DAX formula below, but it doesn't seem to be doing what I want or perhaps I'm implementing it incorrectly.
Solved! Go to Solution.
@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 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, "")
The solution you provided for the column is just what I needed!!
Thank you so much for the quick response 👍
@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 🙂
@amon151 , Check update from SpartaBI
Try a new column
= countx(filter(Table, Table[ColumnA] = earlier(Table[Column B]) ), [ColumnA])+ 0
A new measure
= countx(filter(allselected(Table), Table[ColumnA] = max(Table[Column B]) ), [ColumnA])+ 0
Thank you!
This approach seemed to work for the most part but wasn't able to handle when Column B was blank (ignore the third column, the output of your formula is in column D).
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the September 2025 Power BI update to learn about new features.