Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
laxanders
Contributor II
Contributor II

Rename a list of numbers backwards

I have a list with data that are generated by IterNo() fuction but I now would like to make a new field with the numbers in oposit deirection. I would  like to solve this in the script but have no clue how to do it. In the example below the field "New field" is what I'm tying to solve. The list of ID is massive....

laxanders_0-1685523830659.png

 

 

Labels (1)
1 Solution

Accepted Solutions
MarcoWedel

You could create this new field like this:

 

Schedule:
Load
ID,
IterNo() as IterNo,
EndDate-StartDate+2-IterNo() as NewField,
Date(StartDate + IterNo() - 1) as BelTime.Date,
Qty
Resident tmpSchedule
While StartDate + IterNo() - 1 <= EndDate;

View solution in original post

5 Replies
Kushal_Chawda

@laxanders  try below

 

Data:
LOAD ID,
     Date
FROM Table;

New:
LOAD *,
     if(ID<>previous(ID),1,rangesum(peek('New Field'),1)) as [New Field]
resident Data
order by ID, Date desc;

drop table Data;

 

mikaelsc
Specialist
Specialist

generate a similar field by ordering your table in the opposite direction... (order by date desc instead of date asc ? ) 

MarcoWedel

"I have a list with data that are generated by IterNo() fuction "

can you post the load statement containing this IterNo() function?

laxanders
Contributor II
Contributor II
Author

Here comes the IterNo() script.

Schedule:
Load
ID,
IterNo() as IterNo,
Date(StartDate + IterNo() - 1) as BelTime.Date,
Qty
Resident tmpSchedule
While StartDate + IterNo() - 1 <= EndDate;

MarcoWedel

You could create this new field like this:

 

Schedule:
Load
ID,
IterNo() as IterNo,
EndDate-StartDate+2-IterNo() as NewField,
Date(StartDate + IterNo() - 1) as BelTime.Date,
Qty
Resident tmpSchedule
While StartDate + IterNo() - 1 <= EndDate;