My manager wants me count each center that has an order. If a center make one order within the beginning of the last two months, it is considered active for the next two months from the month that it made an order. Example: if center ‘AR238’ made an order in February then it is considered active for the next two months. So it is active until April if it does not make another order in march or April. I am trying to count each active center for each month, compounding from the previous months. So if a center made an order in February I need to be able to count that for Feb, Mar, and April. Please assist on how to do that.
SELECT DateName( month , DateAdd( month , MONTH(dmeorderdate) , 0 ) - 1 ) as Month, count(distinct
DmeOrderNumberDisplay) as NPWT_Order_Volume, count(distinct CenterCode) as NPWT_Active_Centers
FROM [AtHome].[Reporting].[WoundQOrderDetails] w
left join[AtHome].[Reporting].[DimCenter] c on c.CenterSK = w.CenterSK
where DmeOrderDate between '2024-01-01' and GETDATE()
and DmeSignedByProvider = 1
and OrderType = 'NPWT'
and CenterCode is not null
group by DateName( month , DateAdd( month , MONTH(dmeorderdate) , 0 ) - 1 ),MONTH(dmeorderdate)
order by MONTH(dmeorderdate)
niam dickerson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.