0
votes

I am trying to create a calculated field that will populate an NA in the event we have a percent larger than 1000. This is centered around economic growth. Tableau seems to be very finicky on combining Strings with Floats, or vise versa. Any help or insight would be appreciated!

IF [Percent] < 1000 
  THEN 'NA' 
  ELSE [Percent] 
END
1
Have you considered using NULL instead 'NA'? - Armin
Does this achieve your goal? IF [Percent] < 1000 THEN 'NA' ELSE str([Percent]) END - Bernardo
Armin, Null works, but we're trying to throw an NL in, as an acronym for something, as its recognized by peers. Null unfortunately will raise questions as to where the data went. - Prog
Bernado, it does not. The field stays as a Measure, but not one that I can insert as a value. - Prog
Bumping for more help. I've had no luck so far unfortunately. Also IF [Percent] < 1000 THEN 'NA' ELSE str([Percent]) END does work if I convert it to a Decimal, but it does not input the 'NA' it just gives it a NULL value. - Prog

1 Answers

0
votes

You can't define a table calculation that will produce two different output types: this isn't Excel, this is database technology where each field has to contain a single type.

But there are ways around the problem that still give the result you want. Instead of trying to flag the dodgy value in the single result field, define a different field for the rows containing the dodgy data. So, instead of a single output called something like DisplayPercentage use a calculation to create a field called something like %OK defined like this:

if [percentage] > 1000
   then 'NA'
   else 'percentage OK'
end 

and use the resulting text field to highlight or filter the dodgy values.

This is both better and more versatile than trying to combine flags for bad data with the data itself in a single field, variabel or calculation. You can make it even more advanced by defining the cutoff into a parameter and using that rather than a hardcoded value in the calculation so the cutoff can be altered dynamically without having to rewrite any code.