Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikwiz123
Creator III
Creator III

Create Years between Two Dates

Hi,

I have a table 

IDEndYearCost
1202550
22038100

 

Result Table should be 50/6  for ID 1 and distributed across years until 2025 (6 years from today to 2025 including current year)

and for ID 2, it is 100/19 (2020 to 2038 including 2020 is 19 years) and distributed over years until 2038.

IDEndYearCost
120208.3
120218.3
120228.3
120238.3
120248.3
120258.3
220205.26
220215.26
220225.26
220235.26
220245.26
220255.26
220265.26
...
...
...
220385.26
Labels (2)
1 Solution

Accepted Solutions
albertovarela
Partner - Specialist
Partner - Specialist

Please take a look at the attached qvw

 

Script.jpg

View solution in original post

8 Replies
albertovarela
Partner - Specialist
Partner - Specialist

Please take a look at the attached qvw

 

Script.jpg

qlikwiz123
Creator III
Creator III
Author

Exceptional. Thank you so much 🙂

qlikwiz123
Creator III
Creator III
Author

Hi @albertovarela 

 

When I try to use the same logic on my real and bigger data set, it throws me an error

Syntax error

Unexpected token: 'Cost', expected one of: ',', ':', 'OPERATOR_PLUS', 'OPERATOR_MINUS', 'OPERATOR_MULTIPLICATION', 'OPERATOR_DIVISION', 'OPERATOR_STRING_CONCAT', ...

Cost:
LOAD
1 as ID,
2020 + IterNo() -1 as EndYear,
as >>>>>>Cost<<<<<<
AutoGenerate
(1)
While
2020 + IterNo() - 1 <=

 

--------

 

The DEBUG Mode gives me this:

Capture.JPG

 

albertovarela
Partner - Specialist
Partner - Specialist

You don't need the square brackets enclosing DISPOSITION YEAR in the definition of vL_EndYear.  Also, try adding the Let Statement before the variables.

 

Script.jpg

qlikwiz123
Creator III
Creator III
Author

@albertovarela 

I removed the Square Brackets and added Let

I think the problem here is with the Term 'Cost' either as Table Name or Field Name. If you see the image below, ID and End Year has values but Cost comes up as ' as Cost' which is strange

Capture 1.JPG

 

Capture 2.JPG

 

albertovarela
Partner - Specialist
Partner - Specialist

ah! Look at the End Year on your screenshots; It's 2019. This  means that field Cost_Year can have negatives!

The quick fix - on line 188  update to:  '$(vL_Cost)' as Cost

Alberto

qlikwiz123
Creator III
Creator III
Author

Thank you, will try this and hopefully don't have to get back to you again 🙂

qlikwiz123
Creator III
Creator III
Author

@AlbertoV 

Sorry to bother you but is there a way we can adjust this logic at month level too?

Lets say if ID 1 has EndDate in 2025 in February, the Cost must be adjusted in years based on number of months in each year. Meaning, the total cost of 50 for ID 1 should be calculated only for 10 months in 2020, 12 months each until 2024 and 2 months in 2025.