EXCEL VSTACK with a calculated SUM

I’ve got a pivot table with names in the rows and dates in the columns. I need to display actual count per name per week so the pivot table needs to look like the following.

I then also need to carve out the names and counts for Wednesday and Thursday as shown below in the intermediary working data set. The reason it is the intermediary working data set is I haven’t been able to figure out how to dynamically combine the simple horizontal count function of summing rows M and N with the main dynamic formula in cell L5.

Cell L5 formula:
=CHOOSECOLS(VSTACK(A5:OFFSET(A5,COUNTA(A:A)-4,5)),1,MATCH(4, MOD(B4:F4,7),0)+1,MATCH(5, MOD(B4:F4,7),0)+1)

Cell O5 formula:
=SUM(M5:N5)

Cell O6 formula:
=SUM(M6:N6)

Cell O7 formula:
=SUM(M7:N7)

Finally I want to group the Wednesday/Thursday data by Count and then sort by the name as shown below in the final data set.

Cell R5 formula:
=SORTBY(L5:O7,O5:O7)

While this solution works, it is not elegant. On a week-by-week basis, I can have additional names show as in the following example.

The results for the intermediary table now look like this.

As you can see, there is no automated creation of a formula for O8 set to =SUM(M8:N8).
The final resulting data set also isn’t complete as shown here.

While I can for the intermediary data set create a whole bunch of sum formulas copied down and set to display a blank if there is no value in column L, that’s not an elegant solution and creates an extra tax on the system (I’m only using a handful of names here to illustrate the point, but the real data set is about 50,000 rows and yes this could be better served in a real database but that’s a different story).

Another issue is the final data set doesn’t dynamically expand. You can create named ranges for the intermediary data set, but you still must remember to expand them. Normally you would set the intermediary data set as a table, but that causes the dynamic formula in L5 to encounter a SPILL condition. So, you have to manually manage the final data set range to the values of the updated intermediary data set range.

What I’m really looking for here is to eliminate the intermediary data set in its entirety and have the final data set sorted by count using one dynamic formula in one cell. I haven’t been able to figure out how to do that. Also, I know that the pivot table could be refactored to just the two days of the week and a count, BUT, I also need it to display all the days of the week and a count and I don’t want to have two separate pivot tables. I would also prefer not to use VBA, just native EXCEL capabilities.

Any insights would be appreciated.

I’ve tried various solutions but have not been able to figure this out.

5

Here’s quick suggestion using the sample data below:

=LET(
    weekdays_to_group_by, {4, 5},
    u_name, UNIQUE(Table2[Name]),
    counts_for_name, LAMBDA(acc, name,
        LET(
            filtered, FILTER(
                N(WEEKDAY(Table2[Date]) = weekdays_to_group_by) *
                    Table2[Item],
                (Table2[Name] = name)
            ),
            count_for_wd, MMULT(SEQUENCE(, ROWS(filtered), 1, 0), filtered),
            VSTACK(acc, HSTACK(name, count_for_wd, SUM(count_for_wd)))
        )
    ),
    counts, DROP(
        REDUCE("Count for per weekday for name", u_name, counts_for_name),
        1
    ),
    VSTACK(
        HSTACK("Name", "Wed", "Thu", "Total"),
        SORT(counts, COLUMNS(counts))
    )
)
Name Date Item
Name1 9/9/24 0.5
Name2 9/9/24 1
Name3 9/9/24 1
Name1 9/9/24 0.5
Name1 9/10/24 1
Name3 9/10/24 1
Name4 9/10/24 1
Name2 9/11/24 1
Name1 9/12/24 1
Name2 9/12/24 1
Name1 9/13/24 1
Name2 9/13/24 1
Name3 9/13/24 1

3

If you have access to Pivotby, you should be able to do it in a single step:

=PIVOTBY(Table1[Name],Table1[Date],Table1[Item],SUM,0,1,2)

and

=PIVOTBY(Table1[Name],Table1[Date],Table1[Item],SUM,0,1,2,,,(WEEKDAY(Table1[Date])=4)+(WEEKDAY(Table1[Date])=5))


The slight downside of this was that I had to format the column headers to dates manually. If this was an issue, you could try:

=LET(pivot,PIVOTBY(Table1[Name],Table1[Date],Table1[Item],SUM,0,1,2),
   seq,SEQUENCE(ROWS(pivot)),
   IF(seq=1,TEXT(pivot,"dd/mm/yy"),pivot))

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