Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

MalcolmCICWF
Contributor II

Restrict and create new field based on Length

I'm not sure how to word this, but I have an Excel spreadsheet that contains some account numbers that we need to use for reporting purposes. Because this field is manually entered by multiple agents, the data formatting/length is not uniform and contains an array of text and numbers. 

Without going back and fixing the data, is there a way I can limit and pick out only the entries with 10 or less numbers (These are valid)? I have already removed all alpha characters from the mix, but I have data that looks like the below. Can I use the "LEN" function somehow? Anyone have some suggestions?

Capture.JPG

1 Solution

Accepted Solutions

Re: Restrict and create new field based on Length

Try this may be:

If(Len(Trim(ACCTnum)) <= 10, Num(ACCTnum, '0000000000')) as TEST2

9 Replies

Re: Restrict and create new field based on Length

You sure can:

LOAD FieldNames

FROM Source

Where Len(Trim(A)) <= 10;

MalcolmCICWF
Contributor II

Re: Restrict and create new field based on Length

Doesnt work, using this to create a field and see what it contains, but I am getting "-1" and "0" as my only results.

LEN(TRIM(ACCTnum))<=10 as TEST2,

Re: Restrict and create new field based on Length

To create a field, try this:

If(Len(Trim(ACCTnum)) <= 10, ACCTnum) as TEST2

Re: Restrict and create new field based on Length

Perhaps create a straight table with ACCTnum as a dimension and then you can test your expression in the chart without needing to reload the data each time.

Try adding the expression len(trim(ACCTnum)) so you can compare the source data and output.

MVP
MVP

Re: Restrict and create new field based on Length

0 = false

-1 = true

MalcolmCICWF
Contributor II

Re: Restrict and create new field based on Length

yep, thanks, I am aware of this part.

MalcolmCICWF
Contributor II

Re: Restrict and create new field based on Length

alright, so this sort of seems to be working better.

I have one more question then, with the remaining accounts I have, is there a way to add leading zeros if the account is under 10 digits? I have some accounts left over that are under 10 digits that should have them. Simple formatting change in the field creation??

Ex.  456789    --------> 0000456789

Re: Restrict and create new field based on Length

Try this may be:

If(Len(Trim(ACCTnum)) <= 10, Num(ACCTnum, '0000000000')) as TEST2

Re: Restrict and create new field based on Length

Hi,

maybe

LOAD A

FROM YourExcel.xlsx (ooxml, no labels, table is Sheet1)

Where Num(A)<10000000000;

regards

Marco

Community Browser