Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikwiz123
Creator III
Creator III

Price per Month aggregated by Year

I have Price, Today() as Start Date and 10/25/2025 as EndDate

How do I generate months between Today() and EndDate, Add Price Per Month to each Month and show them in Years?

As an example

Current:

PriceIDStartDateEndDate
5013/31/20202/25/2021
3023/31/20205/14/2020

 

Result:

PriceIDYearMonthPrice Per Month
3022020Mar10
3022020Apr10
3022020May10
5012020Jan0
5012020Feb0
5012020Mar4.16
5012020Apr4.16
5012020May4.16
5012020June4.16
5012020Jul4.16
5012020Aug4.16
5012020Sep4.16
5012020Oct4.16
5012020Nov4.16
5012020Dec4.16
5012021Jan4.16
5012021Feb4.16
1 Solution

Accepted Solutions
lironbaram
Partner - Master III
Partner - Master III

hi 

this script will do the trick 

dataTemp:
load * inline [
Price,ID,StartDate,EndDate
50, 1, 3/31/2020, 2/25/2021
30, 2, 3/31/2020, 5/14/2020
];

data:
load *,
Price/(round((MonthStart(EndDate)- MonthStart(StartDate))/30)+1) as PricePerMonth,
date(AddMonths(MonthStart(StartDate),IterNo()-1)) as Month
Resident dataTemp
while date(AddMonths(MonthStart(StartDate),IterNo()-1))<=MonthStart(EndDate);

drop table dataTemp;

View solution in original post

1 Reply
lironbaram
Partner - Master III
Partner - Master III

hi 

this script will do the trick 

dataTemp:
load * inline [
Price,ID,StartDate,EndDate
50, 1, 3/31/2020, 2/25/2021
30, 2, 3/31/2020, 5/14/2020
];

data:
load *,
Price/(round((MonthStart(EndDate)- MonthStart(StartDate))/30)+1) as PricePerMonth,
date(AddMonths(MonthStart(StartDate),IterNo()-1)) as Month
Resident dataTemp
while date(AddMonths(MonthStart(StartDate),IterNo()-1))<=MonthStart(EndDate);

drop table dataTemp;