Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

View all the Fabric Data Days sessions on demand. View schedule

Reply
pbihelpplz
New Member

How to Countif Multiple Columns in PBI?

Hi everyone,

 

I am new to PBI, not sure if my question is too basic. I have a data table in this structure 

 

other fieldfield 1field 2field 3other field
 name 1nullnull 
 name 2name 1null 
 name 1name 2name 3 

 

And I want to count how many times each name appears in 3 columns (field 1/2/3), so the result (visualization) would be another table like

 

Name# of count
name 13
name 22
name 31
..........

 

I tryied COUNTA function, and add COUNTA(field1)+COUNTA(field2)+COUNTA(field3) but the result seems wrong. 

 

Much appreciate your help on this. 

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @pbihelpplz 
I assume no relationship betweem the two tables

=
VAR CurrentName =
    SELECTEDVALUE ( Table2[name] )
RETURN
    COUNTROWS (
        FILTER (
            Table1,
            TableName[field 1] = CurrentName
                || TableName[field 2] = CurrentName
                || TableName[field 3] = CurrentName
        )
    )

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

Hi @pbihelpplz 
I assume no relationship betweem the two tables

=
VAR CurrentName =
    SELECTEDVALUE ( Table2[name] )
RETURN
    COUNTROWS (
        FILTER (
            Table1,
            TableName[field 1] = CurrentName
                || TableName[field 2] = CurrentName
                || TableName[field 3] = CurrentName
        )
    )

wow, it's working! thank you so much @tamerj1 

SpartaBI
Community Champion
Community Champion

@pbihelpplz best you unpivot the columns field 1, field 2, field 3 in Power Query before loading to the model. Then it will be straighforward.

Here is a link to download a sample solution file:
How to Countif Multiple Columns in PBI 2022-08-08.pbix



2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Showcase Report – Contoso By SpartaBI

Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Thank you SpartaBI. 

 

I have other fields as values, and I tried the unpivot method but the value fields become duplicated or even triplicated. I am sure there is a way to fix this but I don't know how:) still, thanks a lot for your input!

@pbihelpplz my pleasure, hope I could help the next time 🙂
P.S. Check out my showcase report - got some high level stuff there. Sure you will find there a lot of cool ideas. Please give it a thumbs up over there if you liked it 🙂
https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors