A particular field is supposed to be of the format "000000" (a 6 digit field containing only numbers & includes the leading zeros) but several records are coming through as unusual formats (ex. 10A3C1, 17, City, John Smith). Is there a way to group all of the records together that do not conform to a specified format?
3 Answers
Spotfire is not really great at validating data. it's best to do this outside of Spotfire.
that said, I think we can hack something together. if you create a calculated column with the following expression, you'll be able to identify matches:
if(RXReplace([column], "\\D", "X", "g") = [column] and Len([column]) = 6, "MATCH")
this Regular Expression replaces all non-digit characters with the character X
. if we compare that to the original value, additionally checking its length, we can verify if the value fits your requirements.
I do want to re-emphasize that this is hacky and you Probably Shouldn't Be Doing This™ in Spotfire :)
I don't have enough rep points to comment on AmbivalentGeek's answer but his should work for you if you cast your column to an Integer after you check the length, or handle alpha numeric 6 length cases some other way.
case when len([yourColumn])=6 then Integer([yourColumn]) else null end
This will remove the false positives you would get if you have an alpha numeric value of length 6, like 123A56. This will strip leading zeros though so you'll have to create an additional calculated column, reformatting to 6 digits.
Here is a long way since I can't think of a more elegant solution right now. test2 is the calculated column from above:
case
when Len(String([test2]))=1 then Concatenate("00000",String([test2]))
when Len(String([test2]))=2 then Concatenate("0000",String([test2]))
when Len(String([test2]))=3 then Concatenate("000",String([test2]))
when Len(String([test2]))=4 then Concatenate("00",String([test2]))
when Len(String([test2]))=5 then Concatenate("0",String([test2]))
when Len(String([test2]))=6 then String([test2])
else "000000"
end