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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ledu
Regular Visitor

Countif formula in PowerBi

Hi everyone,

 

I was hoping for some help with a formula in PowerBi similar to a countif.

 

I have a column that contains

  • Detractors
  • Promoters
  • Passives
  • Null

I need to calculate a new measures which is basically:

=(Promoters-Detractors)/(Detractors+Promoters+Passive)

 

How would I write this formula in PowerBi?

 

Thank you!

1 ACCEPTED SOLUTION
ledu
Regular Visitor

Hi everyone!

 

Thank you all for your help. I realized that I was making this extra tricky and ended up using "quick measures" instead.

 

The formulas looked like this:

Detractors

NPS - Detractors =
CALCULATE(
    COUNTA('F_Form1'[Net Promoter Type]),
    'F_Form1'[Net Promoter Type] IN { "Detractors" }
)
 
Passives
NPS - Passives =
CALCULATE(
    COUNTA('F_Form1'[Net Promoter Type]),
    'F_Form1'[Net Promoter Type] IN { "Passives" }
)
 
Promoters
NPS - Promoters =
CALCULATE(
    COUNTA('F_Form1'[Net Promoter Type]),
    'F_Form1'[Net Promoter Type] IN { "Promoters" }
)
 
NPS Calculation
NPS Score = (([NPS - Promoters]-[NPS - Detractors])/([NPS - Promoters]+[NPS - Detractors]+[NPS - Passives]))*100
 

View solution in original post

5 REPLIES 5
ledu
Regular Visitor

Hi everyone!

 

Thank you all for your help. I realized that I was making this extra tricky and ended up using "quick measures" instead.

 

The formulas looked like this:

Detractors

NPS - Detractors =
CALCULATE(
    COUNTA('F_Form1'[Net Promoter Type]),
    'F_Form1'[Net Promoter Type] IN { "Detractors" }
)
 
Passives
NPS - Passives =
CALCULATE(
    COUNTA('F_Form1'[Net Promoter Type]),
    'F_Form1'[Net Promoter Type] IN { "Passives" }
)
 
Promoters
NPS - Promoters =
CALCULATE(
    COUNTA('F_Form1'[Net Promoter Type]),
    'F_Form1'[Net Promoter Type] IN { "Promoters" }
)
 
NPS Calculation
NPS Score = (([NPS - Promoters]-[NPS - Detractors])/([NPS - Promoters]+[NPS - Detractors]+[NPS - Passives]))*100
 
v-eachen-msft
Community Support
Community Support

Hi @ledu ,

 

You could also pivot the column to get sum.

Here is my test file with two workrounds.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
itsme
Resolver I
Resolver I

CountIf =
VAR Detractors =
    CALCULATE (
        COUNT ( 'TableName'[ColumnName] ),
        FILTER ( 'TableName', 'TableName'[ColumnName] = "Detractors" )
    )
VAR Promotors =
    CALCULATE (
        COUNT ( 'TableName'[ColumnName] ),
        FILTER ( 'TableName', 'TableName'[ColumnName] = "Promotors" )
    )
VAR Passives =
    CALCULATE (
        COUNT ( 'TableName'[ColumnName] ),
        FILTER ( 'TableName', 'TableName'[ColumnName] = "Passives" )
    )
VAR Result =
    DIVIDE ( Promotors DetractorsDetractors Promotors + Passives )
RETURN
    Result

Anonymous
Not applicable

hi @ledu ,

 

Could you please provide an example of how your data is set up? It will be much easier to come up with a solution that way.

Hi @ledu ,

 

 

Detractors = CALCULATE( SUM('Table'[Value]);FILTER('Table';'Table'[Column1] = "Detractors")) 
Promoters = CALCULATE( SUM('Table'[Value]);FILTER('Table';'Table'[Column1] = "Promoters")) 
Passives = CALCULATE( SUM('Table'[Value]);FILTER('Table';'Table'[Column1] = "Passives")) 
Measure = ([Promoters]-[Detractors])/([Detractors]+[Promoters]+[Passives])

 

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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