Search code examples
google-sheetsgoogle-sheets-formula

Google Sheets query to get sum of two columns


I am trying to get sum of two columns using Query function and am getting perfect result when all the two columns have value, however, if any of the column is not having a value than the result will be blank. In such a case I want to reflect the value of the second column having data. Check the below image:

enter image description here

Formula used =QUERY(A2:C,"select A,B+C label B+C ''",0)

Sharing the link of the sheet too for reference. https://docs.google.com/spreadsheets/d/1TID_7m6MTNviLkU0dlPoCDyA8Uv9Iann2WtCYL9CJQo/edit#gid=0

Any help on above will be appreciated. I had also searched community for similar issue but not found the exact match.


Solution

  • Give a try on below formula-

    =QUERY({A2:A,INDEX(IF(B2:C="",0,B2:C))},"select Col1,Col2+Col3 where Col1 is not null label Col2+Col3 ''")
    
    • Here IF(B2:C="",0,B2:C) will convert null cells to zero 0 values.

    enter image description here