Skip to content
Advertisement

Error Using the iif statement in MS access

The completion_metric field from this query I made in MS ACCESS keeps giving me zero percent for all the records. I think something is wrong with my IIF statement. Also, how would can I populate a text box on a ms access form with this query. For text-boxes there seems to not be an option to let my record source be a query.

SELECT 
FORMAT(SUM(IIF (status='Completed',1,0)) / COUNT(Status),"percent") AS completion_metric
FROM   promis_lt 
GROUP BY Short_ID;

Advertisement

Answer

I suspect the problem is integer division. Instead:

SELECT FORMAT(AVG(IIF(status = 'Completed', 1.0 , 0)), "percent") AS completion_metric
FROM promis_lt
GROUP BY Short_ID
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement