-1

I am trying to write a IIF statement in Tableau to check if a condition passes. If it fails the condition, I want it to show "No values" rather than filtering out the row.

Given below is the IIF statement I am using:

IIF(([Average monthly count] > [Today]),[Average monthly count],"No values in the range")
Sam M
  • 4,136
  • 4
  • 29
  • 42
Taukheer
  • 1,091
  • 2
  • 13
  • 20
  • 1
    I'm assuming [Average monthly count] and [Today] are floats, your fails condition needs to be the same data type, not a string. – Bernardo Mar 07 '18 at 14:00
  • 1
    ok so what is the problem with the IIF statement? – Siva Mar 07 '18 at 17:19
  • 1
    What results are you getting and how do they differ from what you want to see? – Ben P Mar 08 '18 at 10:27
  • It throws an error when I run this. But if I change it to IIF(([Average monthly count] > [Today]),[Average monthly count],1,0) it works fine. Any idea how to pass string. – Taukheer Mar 08 '18 at 18:42

1 Answers1

1

As mentioned in comments, in Tableau isn't possible to return two different data types in IF or IIF statements, so if you really need to pass a string like "no values in range", you must return a string in true case. This can be done using the function STR as follows:

IIF(([Average monthly count] > [Today]),STR([Average monthly count]),"No values in the range")

Another option may be just return NULL in false case.

IIF(([Average monthly count] > [Today]),[Average monthly count],NULL)
Armin
  • 363
  • 4
  • 12