• I see your query failed a syntax check; when i reformatted it, i see you got three trailing ,0), as if they were part of NULLIF/COALESCE, but you need only two,.


    SELECT coalesce (o.customerid,'GrandTotal') AS CUSTID
    ,[AVG SHELF DELIV] = COALESCE(convert(DECIMAL(5,1),
    SUM(case
       WHEN o.Status in ('ready','stock present')
       AND o.Status not in ('delivered')
       THEN 1
       ELSE 0
       END
      ))
    /
    NULLIF(
       SUM(
        CONVERT(DECIMAL(5,1),
                CASE
                 WHEN o.Status = 'delivered and approved'
                 AND o.Deliveryconfirmed >= getdate()-7
                 AND ((DATEPART(dw, o.Deliveryconfirmed) + @@DATEFIRST) % 7) NOT IN (0, 1)
                 THEN 1
                 ELSE 0
                END
           )
        )--sum
       ,0)--nullif
    ,0) --HIGHEST coalesce
    * .143

    from
    orders o
    group by rollup (customerid)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!