|Description||Example||Cardinality of Result Set||Result of ATTR(ID)||Result of ISNULL(ATTR(ID)|
|Single Value||1,1,1||1||the value (1 for this example)||False|
|All Null||Null, Null, Null||1||Null||True|
|Single Value and Null||1,1,Null||2||the value (1 for this example)||False|
// If all records are Null then there is only one value. This test is necessary // here because otherwise the following test can be erroneously triggered. IF COUNT([ID])==0 THEN "Single" //First test is whether the comparison of the ID to a dummy string returns Null, //if so then multiple records have been returned ELSEIF ISNULL(ATTR(STR([ID]))=="~") THEN "Multiple" //This covers the case when the set of values being tested contains 1 distinct value and Null. //ATTR([value]) would return a single value and ignore the Null, and therefore be skipped in //the above tests and indicate a single result. If that is desired, then either delete or comment //out these two lines: ELSEIF COUNT([ID]) != SUM([Number of Records]) THEN "Multiple" //Otherwise there is a single value ELSE "Single" END
[ID]: has the set of values to be tested. If field has a string data type, then the calculation can be optimized by removing the single call to the STR() function in the second test.
Alternatively, in many datasources a test like COUNTD([ID]) > 1 may accomplish the same result, though COUNTD() may only return 1 for a combination of a single value and Null. The seed for this test is is based on Joe Mako's post at http://community.tableau.com/thread/108930.