最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Using a multi-select cell to create a total Sum in Google Sheets formula - Stack Overflow

programmeradmin5浏览0评论

I've got a google sheet seen here

| Column A | Column B | Column C |
| -------- | -------- | -------- |
| Product  | $100     ||
| Add-on 1 | $20      ||
| Add-on 2 | $10      ||
| Add-on 3 | $5       ||
|
|
|Customer. | Add-ons  | Total Due |
| John Doe | Multi-select | Formula Needed here |

Google sheet:

I'm trying to write a formula in cell C8 that will allow me to multi-select in B8 and get a total in C8.

Here's what I have tried

=B1 + SUMPRODUCT(--(A2:A4=TRANSPOSE(B8)),B2:B4)

If I select one item in B8, it creates a sum as expected. But when I select 2 items, the value returns to just the value of B1. I suppose that is because once I select two values in B8 it becomes a list instead and this formula doesn't know how to deal with that.

Is there a way to solve this inside the cell formula? Or will I need to do this in apps script?

I've got a google sheet seen here

| Column A | Column B | Column C |
| -------- | -------- | -------- |
| Product  | $100     ||
| Add-on 1 | $20      ||
| Add-on 2 | $10      ||
| Add-on 3 | $5       ||
|
|
|Customer. | Add-ons  | Total Due |
| John Doe | Multi-select | Formula Needed here |

Google sheet:

I'm trying to write a formula in cell C8 that will allow me to multi-select in B8 and get a total in C8.

Here's what I have tried

=B1 + SUMPRODUCT(--(A2:A4=TRANSPOSE(B8)),B2:B4)

If I select one item in B8, it creates a sum as expected. But when I select 2 items, the value returns to just the value of B1. I suppose that is because once I select two values in B8 it becomes a list instead and this formula doesn't know how to deal with that.

Is there a way to solve this inside the cell formula? Or will I need to do this in apps script?

Share Improve this question edited yesterday marc_s 755k184 gold badges1.4k silver badges1.5k bronze badges asked yesterday arlovandearlovande 1351 silver badge9 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Try these Google sheets formula instead:

=B1 + SUM(BYROW(TOCOL(SPLIT(B8,",")), LAMBDA(r, FILTER(B2:B4,A2:A4 = trim(r)))))

or if you want to multiply each value, use this:

=B1 + PRODUCT(BYROW(TOCOL(SPLIT(B8,",")), LAMBDA(r, FILTER(B2:B4,A2:A4 = trim(r)))))

References:

  • BYROW()
  • FILTER()

Try this modification:

=B1+sumproduct(ifna(xmatch(A2:A4,split(B8,", ",))^0),B2:B4)
发布评论

评论列表(0)

  1. 暂无评论