Error "Can't compare boolean and string values" When
Date de publication : 14 Nov 2016 Date de dernière modification : 25 Oct 2022
Problème
Error in calculation:
Can't compare boolean and string values.
Environnement
Tableau Desktop
Résolution
The steps below correctly format the boolean as a value TRUE or FALSE:
Step 1: Create boolean expression
Create new calculated field called "boolean"
Use the following formula: [Segment] - "Consumer"
Step 2: Create Adjusted amount
Create new calculated field called "Adjusted amount"
Use the following formula:
If [boolean] = True
THEN [Profit]
ELSE [Sales]
END
Note: do not use quotes around "True" - see the calculated field called "Adjusted amount Error" and click on the error at the bottom. This replicates the error in the case subject.
Step 3: Create example calculation using Adjusted amount
Create a new calculated field called Adjusted amount divided
Use the following formula: SUM([Adjusted amount])/SUM([Quantity])
This calculation, finally, does the math of dividing the true field by a third measure.
Cause
Using quotes around "True" or "False" when using a boolean in a calculation will create the error "Can't compare boolean and string values" because the text in quotes is considered a string, rather than a boolean value.
Merci de nous avoir donné votre avis sur l’efficacité de l’article.