Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Accumulative values per month

Hello,

I am doing a ratio that involves accumulative values per month, I was thinking about assigning a numeric value to each month and then with an if statement create a conditional that, depending on the number of the moth would add the previews months or start over (that would be the case in January), but I read something about a previous(expression) statement and I think that might help me get the same result but with only one expression, unfortunatley I havent ben able to find a post describing the complete use of the expresion, could you please help me?

The table I am looking to build will looks like this:

   Month, Income, Accumulative

    Jan, 10, 10

    Feb, 10, 20

    Mar, 10, 30

    Apr, 10, 40

    May, 10, 50

    Jun, 10, 60

    Jul, 10, 70

    Aug, 10, 80

    Sep, 10, 90

    Oct, 10, 100

    Nov, 10, 110

    Dec, 10, 120

Thank you in advance.

1 Reply
maxgro
MVP
MVP

in script?

// test data

S:

load

addmonths(makedate(2015), iterno()+2) as date,

10 as income

AutoGenerate 1

while iterno() <= 28;

// make the final table with accumulative field

F:

LOAD

date,

income,

if(year(date)<>year(peek('date')), income, income + peek('accumulative')) as accumulative

Resident S;

DROP

Table S;




1.png

peek and previous

Peek() vs Previous() – When to Use Each