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
donbonbon
Frequent Visitor

Add IF not zero to calculated measure (while dividing)

Hi,

 

how could I add a filter so that sum of cost is not 0 to this calculated measure?

 

Rev per click = sum(GA[Cost])/sum(GA[Clicks])

 

I want it to make calculations only if s sum of cost is more than 0.

 

Thnx!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

That is because you are having a scenario where the sum of GA[Clicks] is zero and the measure is attempting to divide by 0.

 

How you want to handle this depends on your report.

Usually you want to have your data setup so that you do not get div by zero.

 

Rev per click =
VAR CostSum =
    SUM ( GA[Cost] )
VAR ClickSum =
    SUM ( GA[Clicks] )
RETURN
    IF (
        ClickSum = 0
            || ISBLANK ( ClickSum ),
        ERROR ( "Div by 0" ),
        IF ( CostSum > 0, CostSum / ClickSum, BLANK () )
    )

However if div by zero is a normal case then you can use the divide function to replace the errors by blanks

 

Rev per click =
VAR CostSum =
SUM ( GA[Cost] )
RETURN
IF ( CostSum > 0, DIVIDE ( CostSum, SUM ( GA[Clicks] ), BLANK () ), BLANK () )

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

 

If all you want is to not see values less than 0 then this will do what you want

 

Rev per click =
VAR CostSum =
    SUM ( GA[Cost] )
RETURN
    IF ( CostSum > 0, SUM ( CostSum ) / SUM ( GA[Clicks] ), BLANK () )

 

Thnx, I did as you told me, but it doesnt work anyway, shows to me the same error Capture.JPG

Anonymous
Not applicable

That is because you are having a scenario where the sum of GA[Clicks] is zero and the measure is attempting to divide by 0.

 

How you want to handle this depends on your report.

Usually you want to have your data setup so that you do not get div by zero.

 

Rev per click =
VAR CostSum =
    SUM ( GA[Cost] )
VAR ClickSum =
    SUM ( GA[Clicks] )
RETURN
    IF (
        ClickSum = 0
            || ISBLANK ( ClickSum ),
        ERROR ( "Div by 0" ),
        IF ( CostSum > 0, CostSum / ClickSum, BLANK () )
    )

However if div by zero is a normal case then you can use the divide function to replace the errors by blanks

 

Rev per click =
VAR CostSum =
SUM ( GA[Cost] )
RETURN
IF ( CostSum > 0, DIVIDE ( CostSum, SUM ( GA[Clicks] ), BLANK () ), BLANK () )

 

yes, got it, thnx a lot! 

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!

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