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 February 1rst, then it is considered active for the next two months. So it is active until the end of 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. Also I need the query to be included into the query I already have written out. This Query will just add an extra column to the table I already have from my original query. I will post my original query below.
WITH active_centers AS (
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))
–This query returns each month, the order volume of each month, and the active centers for each month. The active centers I have in this query already is only counting the center once. I want an extra column that count each individual center for jan, feb, march if it made an order in january. If that center made another order in feburary, it will reset the cycle, we will now count it once for feb, march, april. The extra column I am trying to add is basically compounding.
niam dickerson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.