Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
ali_hijazi
Partner - Master II
Partner - Master II

Help in expression

Hello got a pivot table with 2 dimensions (Month-Year) and Category

I got an expression very simple sum(Amount)

now what I want is demonstrated in the following image:

desired.png

so for each month-year (I need to display the value of the last year's month-year

Please advise

I can walk on water when it freezes
9 Replies
terezagr
Partner - Creator III
Partner - Creator III

Have you tried to have a look at Peek() function?

Peek function allows you to 'peek' to number of records you specify.

in your load script you can add this and you will 'peek' 1 record in your read table:

e.g. Peek(Dates,-1) as Peek_dates 

ali_hijazi
Partner - Master II
Partner - Master II
Author

I don't know how many combinations the end user may select

so it is not feasible to make it in the script as the selections are endless

I can walk on water when it freezes
stabben23
Partner - Master
Partner - Master

Hi, try this:

above(Total above( Total sum( volume)))

terezagr
Partner - Creator III
Partner - Creator III

The whole script:

Table:

LOAD Dates,

     Categorie_Flag,

     Volume

FROM

load.txt

(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

LOAD

  Dates,

     Categorie_Flag,

     Volume,

Peek(Volume,-2) as Peek_Table

Resident Table

Order by Dates;

And I got this:

Capture.PNG

terezagr
Partner - Creator III
Partner - Creator III

Staffan solution is cool, but as soon as you select e.g. 2013 year, it will not show you anything for volume. Despite the fact that there were volume data for 2012. See picture below:

Capture1.PNG

Capture.PNG

stabben23
Partner - Master
Partner - Master

And much cooler:

above( total above( Total sum({1} volume)))

terezagr
Partner - Creator III
Partner - Creator III

And might affect performance of the application more than the Peek ()

terezagr
Partner - Creator III
Partner - Creator III

With the {1} you will always evaluate the full record set of all the data in the document - ignoring all your selections:

Capture.PNG

With peek() function:

Capture1.PNG

Capture.PNG

terezagr
Partner - Creator III
Partner - Creator III

That's why you should use the Peek() as I suggested

Table:

LOAD Dates,

     Categorie_Flag,

     Volume

FROM

load.txt

(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

LOAD

  Dates,

     Categorie_Flag,

     Volume,

Peek(Volume,-2) as Peek_Table

Resident Table

Order by Dates;