Automate Formula | Excel [closed]

I have quite a complex formula issue that I am trying to fix with excel, not sure if it’s possible.

Basically what I want to do is the following for my total treated patients by Product I want to do is:

Drug A:
Jan-24 = Treated Patients by Product (current month, Jan in this case) – Drops off (Jan24)
Feb-24 = Patients from Jan24 + Treated Patients by Product (from Feb) – Drops off (Feb24)
March24 = Patients from Jan24 + Patients from Feb24 + Treated Patients by Product (from March) – Drops off (March)

For April24, I want to start over again as Jan, cause the treatments are only for 3 months. So basically, on April24 would be = Current Treated Patients (April) – Drops off (April)
May24 = Patients from April 24 + Treated Patients by Product (from May) – Drops off (May24)
June24 = Patients from April24 + Patients from May24 + Treated Patients by Product (from June) – Drops off (June)

And this every 3 months, and I would like to enter a formula on the cell for Jan24 and when I drag it it just automate this process, not sure if it’s possible.

Please note that I have my data as shown on the picture. Please note that I am trying to place this formula on the C52

If someone has any idea on how to do it I will appreciate a lot! I have been struggling with these for the last two weeks

The best thing that I could do was this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>=OFFSET(D36,0,MAX(0,C55-2),1,1)-OFFSET(D49,0,MAX(0,C55-2),1,1)+OFFSET(D24,0,MAX(0,C55-2),1,1)
</code>
<code>=OFFSET(D36,0,MAX(0,C55-2),1,1)-OFFSET(D49,0,MAX(0,C55-2),1,1)+OFFSET(D24,0,MAX(0,C55-2),1,1) </code>
=OFFSET(D36,0,MAX(0,C55-2),1,1)-OFFSET(D49,0,MAX(0,C55-2),1,1)+OFFSET(D24,0,MAX(0,C55-2),1,1)

But only did it right for Feb24, for March24 was already not working

3

Reducing with MOD:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>=LET(
treated_patients_by_product, $C$34:$P$37,
months, $C$33:$P$33,
n_months, 3,
treatment_failure_by_product_as_percentage, $C$40:$G$43,
treatment_failure_for_year, LAMBDA(y,
INDEX(treatment_failure_by_product_as_percentage, , XMATCH(y, $C$39:$G$39))
),
inital_totals, EXPAND(0, ROWS(treated_patients_by_product), , 0),
net_patients_for_month, LAMBDA(accumulated, year_month,
HSTACK(
accumulated,
IF(
MOD(MONTH(year_month), n_months) = 1,
inital_totals,
TAKE(accumulated, , -1)
) +
INDEX(treated_patients_by_product, , XMATCH(year_month, months)) *
(1 - treatment_failure_for_year(YEAR(year_month)))
)
),
DROP(REDUCE(inital_totals, months, net_patients_for_month), , 1)
)
</code>
<code>=LET( treated_patients_by_product, $C$34:$P$37, months, $C$33:$P$33, n_months, 3, treatment_failure_by_product_as_percentage, $C$40:$G$43, treatment_failure_for_year, LAMBDA(y, INDEX(treatment_failure_by_product_as_percentage, , XMATCH(y, $C$39:$G$39)) ), inital_totals, EXPAND(0, ROWS(treated_patients_by_product), , 0), net_patients_for_month, LAMBDA(accumulated, year_month, HSTACK( accumulated, IF( MOD(MONTH(year_month), n_months) = 1, inital_totals, TAKE(accumulated, , -1) ) + INDEX(treated_patients_by_product, , XMATCH(year_month, months)) * (1 - treatment_failure_for_year(YEAR(year_month))) ) ), DROP(REDUCE(inital_totals, months, net_patients_for_month), , 1) ) </code>
=LET(
    treated_patients_by_product, $C$34:$P$37,
    months, $C$33:$P$33,
    n_months, 3,
    treatment_failure_by_product_as_percentage, $C$40:$G$43,
    treatment_failure_for_year, LAMBDA(y,
        INDEX(treatment_failure_by_product_as_percentage, , XMATCH(y, $C$39:$G$39))
    ),
    inital_totals, EXPAND(0, ROWS(treated_patients_by_product), , 0),
    net_patients_for_month, LAMBDA(accumulated, year_month,
        HSTACK(
            accumulated,
            IF(
                MOD(MONTH(year_month), n_months) = 1,
                inital_totals,
                TAKE(accumulated, , -1)
            ) +
                INDEX(treated_patients_by_product, , XMATCH(year_month, months)) *
                    (1 - treatment_failure_for_year(YEAR(year_month)))
        )
    ),
    DROP(REDUCE(inital_totals, months, net_patients_for_month), , 1)
)

1

See if this is the sort of thing you’re looking for. The summation restarts after three months.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>=LET(startCol,COLUMN($C:$C),startIndex,QUOTIENT(COLUMN()-startCol,3)*3+1,SUM(INDEX($C34:$N34,startIndex):C34)-SUM(INDEX($C46:$N46,startIndex):C46))
</code>
<code>=LET(startCol,COLUMN($C:$C),startIndex,QUOTIENT(COLUMN()-startCol,3)*3+1,SUM(INDEX($C34:$N34,startIndex):C34)-SUM(INDEX($C46:$N46,startIndex):C46)) </code>
=LET(startCol,COLUMN($C:$C),startIndex,QUOTIENT(COLUMN()-startCol,3)*3+1,SUM(INDEX($C34:$N34,startIndex):C34)-SUM(INDEX($C46:$N46,startIndex):C46))

One thing I’m not sure of is that it looks like the treatment failure % applies to the whole of 2024. That’s what I’ve assumed but it’s not clear from your screenshot.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật