0

is it possible to sum field under condition?

I would like to sum fields within my table but only if they correspond to something...

for exemple, I have product with 2 different type, let say type A and type B. I have a table that correspond to purchased. I would like to be able to sum type A product and type B product.

With this formula I only get the first to be calculated...  

sum(if product.type = "A" then purchase.price end, if product2.type ="A" then purchase2.price end)

 

here the table exemple

purchase   price          purchase2    price2           purchase3      price3

product1    10             product3       5                 product5        20

 

So I would like to check if the product is type A or B in it s table and sum or not...

 

thank you!

2 replies

null
    • Mconneen
    • 4 yrs ago
    • Reported - view

    Hmm.. without drawing out the data model.. Sounds like a view that is grouped on Type.. with a sum on price. 

    • Jorg
    • 4 yrs ago
    • Reported - view

    Hi, 

    If you want both parts to be calculated the formula could be:

     

    sum(if product.type = "A" then purchase.price end) + sum(if product2.type ="A" then purchase2.price end)

     

    Kind regards,

    Jörg

Content aside

  • 4 yrs agoLast active
  • 2Replies
  • 1465Views