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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
dimsandfacts
Regular Visitor

Excel CountIF Text Function in Power BI

Hi 

What is the best way to transfer the logic from excel like below to Power BI either in Power Query or in DAX ? Many thanks 

 

=(COUNTIF(A2:D2,"X")+COUNTIF(A2:D2,"XY"))/(COUNTIF(A2:D2,"X")+(COUNTIF(A2:D2,"XY") + (COUNTIF(A2:D2,"XYZ")

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @dimsandfacts ,

Check if this is your expected output:

vcgaomsft_0-1697523511961.png

 

Column = 
VAR _Count_X =
    CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column1] = "X" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column2] = "X" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column3] = "X" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column4] = "X" )
VAR _Count_XY =
    CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column1] = "XY" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column2] = "XY" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column3] = "XY" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column4] = "XY" )
VAR _Count_XYZ =
    CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column1] = "XYZ" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column2] = "XYZ" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column3] = "XYZ" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column4] = "XYZ" )
RETURN
    DIVIDE ( _Count_X + _Count_XY, _Count_X + _Count_XY + _Count_XYZ )

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @dimsandfacts ,

Check if this is your expected output:

vcgaomsft_0-1697523511961.png

 

Column = 
VAR _Count_X =
    CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column1] = "X" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column2] = "X" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column3] = "X" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column4] = "X" )
VAR _Count_XY =
    CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column1] = "XY" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column2] = "XY" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column3] = "XY" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column4] = "XY" )
VAR _Count_XYZ =
    CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column1] = "XYZ" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column2] = "XYZ" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column3] = "XYZ" )
        + CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Column4] = "XYZ" )
RETURN
    DIVIDE ( _Count_X + _Count_XY, _Count_X + _Count_XY + _Count_XYZ )

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Greg_Deckler
Super User
Super User

@dimsandfacts See if this helps: (1) Excel to DAX Translation - Microsoft Fabric 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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors