12 Replies Latest reply on Jun 1, 2016 2:48 AM by lenaic.ridinger

# Test boolean value in "if" function

Hi all,

I'm working on tableau desktop and i'm block.

I have to use different formula according to the result of a boolean value but tableau said that calcul is wrong :

IF [Prorata temporis] = True

THEN SUM([Quantité]) * sum([Durée (en mois)])*MEDIAN([Prix catalogue])

ELSE SUM([Quantité]) * MEDIAN([Prix catalogue])

END

Prorata temporis is my boolean value.

Thank you

• ###### 1. Re: Test boolean value in "if" function

Bonjour Pierre Oms !

Could you please provide us with a workbook (.twbx), so we can check what is wrong with this calculated field?

I also moved this thread to the Crow's Nest, where our community help each others most of the time.

Cheers,

1 of 1 people found this helpful
• ###### 2. Re: Test boolean value in "if" function

Unfortunately I can't provide you the workbook because most of the datas are confidentials

I know that my question is complicated so

• ###### 3. Re: Test boolean value in "if" function

What exactly did it say was wrong about the calc?  If you check show details it will give you more info on the problem.

• ###### 4. Re: Test boolean value in "if" function

Hi Pierre,

You previously said the following:

It's written : "You can't combine comparision of aggregation and non-aggregation or results in "IF" expressions

and here was my solution. As you deleted your message, my solution disappeared as well.

-----

This message is shown when a calculation contains a mix of disaggregated (row-level) values and aggregated values.  Aggregations allow you to look at numerical data in summary form, such as sum or average. In the formula below, the Sales field is an aggregated value (SUM), but the Profit field is a disaggregated value:

`[Profit]/SUM([Sales)]`

To resolve the issue, apply an aggregation to the Profit field, or remove the aggregation from the Sales field.

In other cases, you may have both a dimension and a measure in your formula:

`IF [Category] = 'Technology" THEN SUM([Sales]) END`

Because Category is not aggregated, Tableau will show the same error as in the first example. Resolve the issue by applying an aggregation (ATTR) to the dimension field:

`IF ATTR([Category]) = 'Technology" THEN SUM([Sales]) END`

Although Category is a dimension, it needs to be aggregated because Sales is aggregated.

1 of 1 people found this helpful
• ###### 5. Re: Test boolean value in "if" function

Thank you very much for all your help

I try your solution but i still have a mistake wich is different than before :

"The '==' function can't be apply to the table's calculs or to the field coming from severals data sources"

• ###### 6. Re: Test boolean value in "if" function

The real probleme that i have is :

Is it possible to use boolean value in if function

If boolean is true

Then ....

Is it possible to do this?

thanks

• ###### 7. Re: Test boolean value in "if" function

Hello Pierre,

The error you are getting is because the field you are testing in your condition seems to be a Table calculation or coming from more than one field. That's my rough translation to the error. Based on the fact that you said data is confidential, would you be able to provide us with what exactly the prorata field is? (c'est un champ de la base de donnes ou vous l'avez cree dans Tableau?)

Best,

B

• ###### 8. Re: Test boolean value in "if" function

The prorata temporis field is in the data base (i didn't create it on teableau). It's a field which is a boolean value that return true or false. (il indique simplement si le produit est composé d'un abonnement ou non. Ex: soit vous acheter un journal => prorata = False soit vous vous abonnez au journal => prorata = true)

What i want to do is: if prorata is true then i want this calcul and if it's false i want another calcul.

Thank you for your time and patience guys

• ###### 9. Re: Test boolean value in "if" function

Okay so I was able to recreate the error with dummy data. Your error arises from using the ATTR function, just replace it in your calc with either MAX() or MIN().

Example:

Best,

B

1 of 1 people found this helpful
• ###### 10. Re: Test boolean value in "if" function

Thank you very much Bassem Khalil

It works perfectly !!

THANK YOU !!

Pierre

• ###### 11. Re: Test boolean value in "if" function

Great!

Enjoy Tableau!

• ###### 12. Re: Test boolean value in "if" function

Fantastic, thanks everyone.

Pierre Oms, don't forget to Mark as Correct the post that solved your issue

Bonne journée !