Using case statement to make a value if null and run a calculation if not
I'm trying to find the availability of an application for each month using two date fields in our incident data. I've got it to give me a number when the data exists (the calculation is summing the difference between the times for a given month -> subtracting that number from the total number -> dividing that difference by the total time in the month). However, i've not been successful in adding a '1' (100% availability) to months when there are no fields that affect the calculation. This leaves gaps in my line graph and isn't a great representation of the data (if it has 100%, it would be nice to show that instead of a blank space for that month).
I'm using a case statement to try to run the calculation when the field exists, and place a '1' when the fields are NULL to represent 100% availability. Below is what I have. Does anyone have any suggestions? Any help would be greatly appreciated.
WHEN `time2` IS NULL THEN '1'
ELSE ((DAYOFMONTH(LAST_DAY(`date_created`))*1440) -SUM(TIME_TO_SEC(TIMEDIFF(`time2`,`time1`)))/60) / (DAYOFMONTH(LAST_DAY(`date_created`))*1440)