Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
alvinford
Contributor III
Contributor III

Derive New Field

Hi Struck with the basic thing . I have the following table

 

StarDate

 

EndDate

 

ID

 

01/01/2010

 

31/12/2012

 

540

 

01/05/2012

 

31/12/2012

 

540

 

01/05/2012

 

31/12/2012

 

540

 

01/05/2012

 

31/12/2012

 

540

 

01/01/2013

 

28/02/2013

 

540

 

01/01/2013

 

28/02/2013

 

540

 

01/01/2013

 

28/02/2013

 

540

 

01/01/2013

 

28/02/2013

 

540

I want to create new column based on my EndDate. Want to group the values when EndDate is Same as shown below.

 

StarDate

 

EndDate

 

ID

 

Group

 

01/01/2010

 

31/12/2012

 

540

 

Group1

 

01/05/2012

 

31/12/2012

 

540

 

Group1

 

01/05/2012

 

31/12/2012

 

540

 

Group1

 

01/05/2012

 

31/12/2012

 

540

 

Group1

 

01/01/2013

 

28/02/2013

 

540

 

Group2

 

01/01/2013

 

28/02/2013

 

540

 

Group2

 

01/01/2013

 

28/02/2013

 

540

 

Group2

 

01/01/2013

 

28/02/2013

 

540

 

Group2

Need your help to achieve this.

Regards,

Alvin.

1 Solution

Accepted Solutions
Not applicable

Hi Alvin,

U can write a Script like Below

Tb1:

Load Distinct

ID

,
Start_Date,End_Date
,'Group'&
Text(AutoNumber(End_Date,ID)) as Group;

LoadInline

[Start_Date,End_Date,ID

01/01/2010,31/12/2012,540

01/05/2012,31/12/2012,540

01/05/2012,31/12/2012,540

01/05/2012,31/12/2012,540

01/01/2013,28/02/2013,540

01/01/2013,28/02/2013,540

01/01/2013,28/02/2013,540

01/01/2013,28/02/2013,540

24/12/2010,23/12/2012,250

01/05/2012,23/12/2012,250

01/05/2012,23/12/2012,250 

01/05/2012,23/12/2012,250

24/12/2012,29/02/2013,250

24/12/2012,29/02/2013,250

01/03/2012,31/08/2013,250

01/03/2013,31/08/2013,250

]
;

Regards,

Kabilan K.

View solution in original post

15 Replies
sujeetsingh
Master III
Master III

Just try to derive a new column with crosstable function..

go to the following post and you will find the way to deal with.....

http://community.qlik.com/message/185230#185230

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

'Group' & text(autonumber(EndDate)) as Group

-Rob

http://robwunderlich.com

sujeetsingh
Master III
Master III

Rob ,

A good and short way can you please explain the function used,,

Anonymous
Not applicable

Rob's simple solution is actually quite genious.

Each unique value in EndDate will get a new number assigned by the Autonumber() function.

This number is then concatenated with the word 'Group' to create Group1, Group2 etc.

Simple and elegant!

alvinford
Contributor III
Contributor III
Author

Hi Rob,

Thanks for your reply. I need to group the values based upon ID and EndDate as shown below.

 

StartDate

 

EndDate

 

Group

 

ID

 

01/01/2010

 

31/12/2012

 

Group1

 

540

 

01/05/2012

 

31/12/2012

 

Group1

 

540

 

01/05/2012

 

31/12/2012

 

Group1

 

540

 

01/05/2012

 

31/12/2012

 

Group1

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

24/12/2010

 

23/12/2012

 

Group1

 

250

 

01/05/2012

 

23/12/2012

 

Group1

 

250

 

01/05/2012

 

23/12/2012

 

Group1

 

250

 

01/05/2012

 

23/12/2012

 

Group1

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

Request help to achieve it.

Regards,

Alvin.

alvinford
Contributor III
Contributor III
Author

Hi Rob,

Thanks for your reply. I need to group the values based upon ID and EndDate as shown below.

StartDate

 

EndDate

 

Group

 

ID

 

01/01/2010

 

31/12/2012

 

Group1

 

540

 

01/05/2012

 

31/12/2012

 

Group1

 

540

 

01/05/2012

 

31/12/2012

 

Group1

 

540

 

01/05/2012

 

31/12/2012

 

Group1

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

24/12/2010

 

23/12/2012

 

Group1

 

250

 

01/05/2012

 

23/12/2012

 

Group1

 

250

 

01/05/2012

 

23/12/2012

 

Group1

 

250

 

01/05/2012

 

23/12/2012

 

Group1

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

Request help to achieve it.

Regards,

Alvin.

alvinford
Contributor III
Contributor III
Author

Hi Rob,

Thanks for your reply. I need to group the values based upon ID and EndDate as shown below.

 

StartDate

 

EndDate

 

Group

 

ID

 

01/01/2010

 

31/12/2012

 

Group1

 

540

 

01/05/2012

 

31/12/2012

 

Group1

 

540

 

01/05/2012

 

31/12/2012

 

Group1

 

540

 

01/05/2012

 

31/12/2012

 

Group1

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

01/01/2013

 

28/02/2013

 

Group2

 

540

 

24/12/2010

 

23/12/2012

 

Group1

 

250

 

01/05/2012

 

23/12/2012

 

Group1

 

250

 

01/05/2012

 

23/12/2012

 

Group1

 

250

 

01/05/2012

 

23/12/2012

 

Group1

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

24/12/2012

 

28/02/2013

 

Group2

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

 

01/03/2013

 

31/08/2013

 

Group3

 

250

Request help to achieve it.

Regards,

Alvin.

alvinford
Contributor III
Contributor III
Author

Hi Thanks for sharing the Post. This doesn't solve my problem.

Regards,

Alvin.

rlp
Creator
Creator

LEFT JOIN( <your_table> )

LOAD DISTINCT

     ENDDATE ,

     ID ,

     Group & '-' & text( autonumber( ENDDATE & '-' & ID )) as Group

RESIDENT <your_table> ;