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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
sb2848
Regular Visitor

Convert COUNTIF in Excel to DAX

Hi,

I am relatively new to using DAX and was wondering if the below excel formula be converted into DAX?

=IF(COUNTIF('County Player List'!A:A,[@County])>0,"Yes", "No")

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@sb2848 COUNTIF is COUNTX(FILTER(...),...) in DAX. CO-CU Excel to DAX Translation - Microsoft Power BI Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Hi, @sb2848 

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1665029693008.png

vyueyunzhmsft_1-1665029704540.png

(2)We can click "New Column" to  create a calculated column :

Flag = var _current_cou='County List'[Country] 
var _count =COUNTROWS( FILTER('All Data 2021 & 2022','All Data 2021 & 2022'[County] = _current_cou ))
return 
IF(_count >0 ,"Yes" ,"No")

(3)The result is as follows:

vyueyunzhmsft_2-1665029778894.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

View solution in original post

3 REPLIES 3
sb2848
Regular Visitor

I tried a different approach converting the below excel formula into DAX, I tried a different approach, but I am not getting the right output. Hoping you can point me in the right direction.

 

=IF(COUNTIF('County List'!A:A,[@County])>0,"Yes", "No")

 

my approach

County  = CALCULATE(COUNT('County List'[County] >0, FILTER('All Data 2021 & 2022', 'All Data 2021 & 2022'[County] = "Yes" || 'All Data 2021 & 2022' [County] = "No"))

Hi, @sb2848 

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1665029693008.png

vyueyunzhmsft_1-1665029704540.png

(2)We can click "New Column" to  create a calculated column :

Flag = var _current_cou='County List'[Country] 
var _count =COUNTROWS( FILTER('All Data 2021 & 2022','All Data 2021 & 2022'[County] = _current_cou ))
return 
IF(_count >0 ,"Yes" ,"No")

(3)The result is as follows:

vyueyunzhmsft_2-1665029778894.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

Greg_Deckler
Super User
Super User

@sb2848 COUNTIF is COUNTX(FILTER(...),...) in DAX. CO-CU Excel to DAX Translation - Microsoft Power BI Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.