4 Replies Latest reply on Nov 26, 2018 3:57 AM by Laurène Ruban

# How to calculate a sum with condition

Hi there,

Thanks in advance for the help and sorry for the beginner question.

I am working on a database looking like that :

ID

RegistrantSectorMaterialTotal amount
1A1Wood123
2A1Plastic123
3A2Wood40
4B1Wood82
5B1Plastic82
6B2Wood20

I want to represent the total amount depending on the sector. In my example, the total amount for the sector "1" is 123+82=205

Problem is in the Tableau sheet I can only select a few aggregation functions, among them"Sum" (which would result in 410 here) and "Max" (which would result in 123 here), which don't give me the wanted answer. How should I do?

For information, I have only 2 registrants (A and B, no C).

I have thought of calculating a sum under condition, for example :

If registrant = A

a = Max(Total amount)

end if

If registrant = B

b = Max(Total amount)

end if

c = a+b

But I don't know if such a code is possible in Tableau.

Thanks a lot,

Laurène