-
Check Length and Concatenate expression
I am importing data from an Excel file and I need to insert leading zeroes
when the lenght the the employee id is less than 5. I have the following
expression but it is not working. Could someone please tell me what I am
doing wrong,
LEN((DT_STR,5,1252)[Employee ID]) == 5 ? (DT_STR,5,1252)[Employee ID] :
(LEN((DT_STR,5,1252)[Employee ID]) == 4 ? "0" + (DT_STR,5,1252)[Employee ID]
: (LEN((DT_STR,5,1252)[Employee ID]) == 3 ? "00" + (DT_STR,5,1252)[Employee
ID] : (LEN((DT_STR,5,1252)[Employee ID]) == 2 ?
"000" + (DT_STR,5,1252)[Employee ID] : "0000" + (DT_STR,5,1252)[Employee
ID])))
Thanks
Dean
-
RE: Check Length and Concatenate expression
Hello Dean:
We are doing the same basic thing, except with Zip Codes. Ours come in Excel
as a Dounle Precision Float so something like '02381' will be 2381.
This is how I handle it:
First, put in a Data Conversion Transform and change it to String(dt-str),
length 5.
Next is a Derived Column Transform with the following new column defined:
RIGHT("00000" + ZipCode,5)
Basically, it 'pads' leading zeros in front of the text-based number, then
strips it out with the RIGHT( ) function. So what if you pad in extra zeros?
The 5 of the RIGHT function means that I will always get a zip that is 5
digits long.
HTH
--
Todd C
[If this response was helpful, please indicate by clicking the appropriate
answer at the bottom]
"Dean" wrote:
> I am importing data from an Excel file and I need to insert leading zeroes
> when the lenght the the employee id is less than 5. I have the following
> expression but it is not working. Could someone please tell me what I am
> doing wrong,
> LEN((DT_STR,5,1252)[Employee ID]) == 5 ? (DT_STR,5,1252)[Employee ID] :
> (LEN((DT_STR,5,1252)[Employee ID]) == 4 ? "0" + (DT_STR,5,1252)[Employee ID]
> : (LEN((DT_STR,5,1252)[Employee ID]) == 3 ? "00" + (DT_STR,5,1252)[Employee
> ID] : (LEN((DT_STR,5,1252)[Employee ID]) == 2 ?
> "000" + (DT_STR,5,1252)[Employee ID] : "0000" + (DT_STR,5,1252)[Employee
> ID])))
>
> Thanks
> Dean
>
>
>