Forum Discussion

Chrisblanc's avatar
Chrisblanc
Regular Visitor
7 years ago
Solved

COUNTIF formula to PowerBI

Hi all !

 

As you can see in the screenshot below, I have different titles in one colomn that I would like to sort into 2 categories. I have written the formula in Excel but I don't know how to translate it to Power BI (especially because of the function COUNTIF). 

 

Excel screenshot

 

Here is the Formula I wrote in Excel : 

=IF(OR(COUNTIF([@[Raw Title]],"Mr"),(COUNTIF([@[Raw Title]],"Heer"))),"Men","Women")

 

Thank you in advance for you help ! 

 

 

  • Basically, COUNTIF os translated into CALCULATE(COUNT(countable item/column), <condition>)

    So, depending on whether you want the calculation as an added column or as a measure, the direct translation will look like

     

    =IF(CALCULATE(COUNT(Table1[Raw Title]),Table1[Raw Title]="Mr")>0, "Men", "Women")

     

    and alternatively, you can simply write the following calculated column

    NewColumn = if(or([Raw Title]="Mr", [Raw Title]="Heer"), "Men", "Women")

    Then a new measure to count Men and Women if needed

2 Replies

  • Basically, COUNTIF os translated into CALCULATE(COUNT(countable item/column), <condition>)

    So, depending on whether you want the calculation as an added column or as a measure, the direct translation will look like

     

    =IF(CALCULATE(COUNT(Table1[Raw Title]),Table1[Raw Title]="Mr")>0, "Men", "Women")

     

    and alternatively, you can simply write the following calculated column

    NewColumn = if(or([Raw Title]="Mr", [Raw Title]="Heer"), "Men", "Women")

    Then a new measure to count Men and Women if needed

    • Chrisblanc's avatar
      Chrisblanc
      Regular Visitor

      I knew it was simple I was complicating everything for nothing. Thank you so much you just saved me from burnout