Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

Not applicable

how to create a new column filled with '1'

Hi all,

my short question:

how can i create a new column filled with '1' in every row in an existing table.

I need it to count my data without the 'count' command.

best regards

Philipp

1 Solution

Accepted Solutions
Peter_Cammaert
Not applicable

Re: how to create a new column filled with '1'

Or if your table already exists (and you don't wanna change the LOAD statement - or you can't), use this:

JOIN (ExistingTable)

LOAD 1 AS RowCounter

AUTOGENERATE 1;

We should test which is faster: another LOAD RESIDENT or a simple JOIN. Massimo's original table LOAD moditifcation will beat everything else...

8 Replies
Not applicable

Re: how to create a new column filled with '1'

my short answer: just type 1 into a new expression

maxgro
Not applicable

Re: how to create a new column filled with '1'

if I understand, in the load script

load

     field,

     ....

     1 as newfield,

     ....

from

     .....

but why you don't want count?

Not applicable

Re: how to create a new column filled with '1'

Sorry but i don't understand your idea... i need a column named 'DataCounter' that have as much as rows like the other columns in this table. But 'DataCounter' has a '1' in every row.

simone_spanio
Not applicable

Re: how to create a new column filled with '1'

Another short answer :-)

LOAD      field1

               field2,

               ...,

               fieldn,

               1 as myCounter

FROM ...

S.

mayilvahanan
Not applicable

Re: how to create a new column filled with '1'

Hi

Try like this

Load *, 1 As DataCounter

from sourcetable;

Not applicable

Re: how to create a new column filled with '1'

Load *, 1 as DataCounter from Table1;

Not applicable

Re: how to create a new column filled with '1'

This is why the long more detailed question is more helpful

You talk about a new column which sounds like a new expression in a chart, creating a new expression with just '1' in it will do just that in a chart.

Actually though it sounds like you a looking for a new field in your data model, now you have given a bit more detail.

For that you can simply add a new field to your load

1 As DataCounter

hope that helps

Joe

Peter_Cammaert
Not applicable

Re: how to create a new column filled with '1'

Or if your table already exists (and you don't wanna change the LOAD statement - or you can't), use this:

JOIN (ExistingTable)

LOAD 1 AS RowCounter

AUTOGENERATE 1;

We should test which is faster: another LOAD RESIDENT or a simple JOIN. Massimo's original table LOAD moditifcation will beat everything else...