Home > OS >  Sum first N values in a Comma Separated List (Google Sheets)
Sum first N values in a Comma Separated List (Google Sheets)

Time:10-02

Given the following conditions:

 A cell containing a Comma Separated List (Column B in table)

 A cell containing how many values to sum from the Comma Separated List (Column A in table)

enter image description here

I have seen formulas using OFFSET, but in application, OFFSET doesn't seem to work with a CS List (only an actual range).

Is there a formula that will sum up only the first N values in a Comma Separated List without using helper columns? (So the entirety of the operation will consist of only three cells... MAX Index value, the Comma Separated List, and the output cell containing the formula).

CodePudding user response:

=sum(array_constrain(split(B2, ","),1, A2))

Explanation:

  • sum over
  • a constrained array (of A2 columns and 1 row)
  • formed by splitting the contents of B2 on ,

CodePudding user response:

try:

=INDEX(IFERROR(1/(1/BYROW(
 IF(SEQUENCE(1, COLUMNS(SPLIT(B2:B, ",")))<=A2:A, SPLIT(B2:B, ","), ), 
 LAMBDA(xx, SUM(xx))))))

enter image description here

  • Related