cancel
Showing results for
Did you mean:
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

Accepted Solutions
Highlighted
ThomasFoster Solution Specialist

## Re: Add IF not zero to calculated measure (while dividing)

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 () )`

4 REPLIES 4
ThomasFoster Solution Specialist

## Re: Add IF not zero to calculated measure (while dividing)

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 () )```

Frequent Visitor

## Re: Add IF not zero to calculated measure (while dividing)

Thnx, I did as you told me, but it doesnt work anyway, shows to me the same error Highlighted
ThomasFoster Solution Specialist

## Re: Add IF not zero to calculated measure (while dividing)

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 () )`

Frequent Visitor

## Re: Add IF not zero to calculated measure (while dividing)

yes, got it, thnx a lot!

Announcements #### New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community! #### ‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries. #### Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now. #### Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities. #### Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications Top Solution Authors
Top Kudoed Authors
Users online (847)