create an excel formula that does the following: sum the values in column b only if column c has a value of "dividend" and column e has a value of "xyz". in typescript

To create this formula, you can use the SUMIFS function in Excel. In TypeScript, you can write the formula as follows:

index.ts
const sumIfDividendAndXyz = (values: any[][]) => {
  let sum = 0;
  for (let i = 0; i < values.length; i++) {
    if (values[i][2] === "dividend" && values[i][4] === "xyz") {
      sum += Number(values[i][1]);
    }
  }
  return sum;
};
237 chars
10 lines

In this function, values is a 2D array representing the spreadsheet data. The function loops through each row of the data, and adds the value in column B to the sum variable if the corresponding row has a value of "dividend" in column C and "xyz" in column E.

This function can be called with a 2D array of spreadsheet data, like so:

index.ts
const data = [
  ["apple", 10, "dividend", "red", "xyz"],
  ["banana", 20, "growth", "yellow", "abc"],
  ["orange", 15, "dividend", "orange", "xyz"],
  ["peach", 5, "dividend", "pink", "xyz"],
  ["pear", 30, "growth", "green", "abc"]
];

const result = sumIfDividendAndXyz(data);

console.log(result); // 30
308 chars
12 lines

In this example, the formula should return a value of 30, since the sum of the values in column B where column C is "dividend" and column E is "xyz" is equal to 10 + 15 + 5 = 30.

gistlibby LogSnag