Forum Discussion
Add IF not zero to calculated measure (while dividing)
- Anonymous8 years ago
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 () )
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 () )
- donbonbon8 years agoFrequent Visitor
Thnx, I did as you told me, but it doesnt work anyway, shows to me the same error
- Anonymous8 years agoNot 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 () )- donbonbon8 years agoFrequent Visitor
yes, got it, thnx a lot!