Hello,
I have a table with two fields(text) X, Y, both have 20 entries of yes, no.
I am trying to find the percent change in them and am running into trouble if Sum(X='yes')=0 or Sum(Y='yes')=0 or Sum(X='yes')/Sum(Y='yes')=1.
I need
IF Sum(X)=0 and Sum(Y)=0 then %change=0
IF Sum(X)<>0 and Sum(Y)=0 then %change=Sum(X)*100
IF Sum(X)=0 and Sum(Y)<>0 then %change=Sum(Y)*100
IF Sum(X)<>0 and Sum(Y)<>0 then %change=Sum(Y)/Sum(X)
IF Sum(Y)/Sum(X)=1 then %change=0
I used the IIF function for the first time, it seems to work?, dose this look right? , is there a better way to go about this.
Thanks for any insight.
I have a table with two fields(text) X, Y, both have 20 entries of yes, no.
I am trying to find the percent change in them and am running into trouble if Sum(X='yes')=0 or Sum(Y='yes')=0 or Sum(X='yes')/Sum(Y='yes')=1.
I need
IF Sum(X)=0 and Sum(Y)=0 then %change=0
IF Sum(X)<>0 and Sum(Y)=0 then %change=Sum(X)*100
IF Sum(X)=0 and Sum(Y)<>0 then %change=Sum(Y)*100
IF Sum(X)<>0 and Sum(Y)<>0 then %change=Sum(Y)/Sum(X)
IF Sum(Y)/Sum(X)=1 then %change=0
I used the IIF function for the first time, it seems to work?, dose this look right? , is there a better way to go about this.
Code:
SELECT IIF( Sum(Abs(Y ='Yes'))<>0 and Sum(Abs(X = 'Yes'))<>0 AND Sum(Abs(Y ='Yes'))/Sum(Abs(X ='Yes'))<>1 , Sum(Abs(Y ='Yes'))/Sum(Abs(X ='Yes')),IIF( Sum(Abs(Y ='Yes'))/Sum(Abs(X ='Yes'))=1,0,Sum(Abs(Y ='Yes')) + Sum(Abs(Y ='Yes'))) AS [% Change]
FROM tblFlash4;
Thanks for any insight.