title: Sum if condition is true and background color is not - Google Spreadsheet
body: <p>I'm trying to use a function with two conditions - Sum if condition is true and sum if background color is not. </p>
  
  <p>Normally I'll use function SUMIFS but here I have one built-in function and one custom function. Both of this functions work fine separately but I cannot combine them together as one.</p>
  
  <p><a href="https://i.stack.imgur.com/uoEhy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uoEhy.png" alt="enter image description here"></a></p>
  
  <p>To "Sum if condition is true" I've used built-in function SUMIF and for "Sum if background color is not" I've used a function from Script Library.</p>
  
  <p>Here is a link to my spreadsheet <a href="https://docs.google.com/spreadsheets/d/1ug2BsJ18cRrMg_xQ6NKatHFEfyJnpu2kqOmR3l5FGio/edit?usp=sharing" rel="nofollow noreferrer">Spreadsheet</a></p>
  
  <p>Additional thing is that I need to sum different columns ex. Values2 with same conditions.</p>
  
  <p>Using @Ritz code I'm trying to modify his code and I have this script:</p>
  
  <pre><code>  /**
       * @return The sum of range B where the corresponding value in Column A matches the color
       * @customfunction
       */
  
  function conditionalCheck(color,rangeCondition, rangeSum, criteria){
    var condition = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(2,rangeCondition,11).getValues();
    var val = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(2,rangeSum,11).getValues();
    var bg = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(2,rangeSum,11).getBackgrounds();
    var sum = 0;
    for(var i=0;i&lt;val.length;i++){
       if(condition[i] == criteria &amp;&amp; bg[i] != color){
         sum += val[i];
       }
    }
    return sum;
  }
  </code></pre>
  
  <p>But result is that variable "sum" doing concatenation of the values but doesn't sum it. (The result is shown on print screen on cell H10).</p>
  
  <p>I'll be grateful for any clues.</p>