Multiple conditions "if" to summarize data

Hi,

I would like to have a different formula for each row based on some value of a row.
SUM(r.Amount for r in Budget.all if r.condition1 == $column1 and r.condition2 == $column2)

I would like that if the column1 for the row is empty the condition is ignored (ie true)

I tried something like

f not $column1 :
  return SUM(r.Amount for r in Budget.all if r.condition1 == $column1 and r.condition2 == $column2)
  else:
  return SUM(r.Amount for r in Budget.all if r.condition2 == $column2)

but this bring a python syntax error.

Of course the formula can be different for each row because some row will have a value in column1 some will have an empty value.

Thank you very much for your help

Laurent

OK I found the answer that is pretty easy:
SUM(r.Amount for r in Budget.all if (r.condition1 == $column1 or not $column1) and (r.condition2 == $column2 or not $column2) )

2 Likes