Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Read about the latest Qlik Community enhancements on the Community News blog!
cancel
Showing results for 
Search instead for 
Did you mean: 
geogou1973
Creator
Creator

Subtract the current from the previous line in a chart

  Hi.

I have the folllowing chart.

 

HourCurrent
954.749
10141.743
11269.626
12419.151
13581.241
14722.507
15841.649
16936.237
171.018.161
181.105.595
191.212.814
201.381.175
211.553.628
221.571.625

How can i subtract the Hour 22 from the Hour 21, the Hour 21 from the Hour 20 and e.t.c in a chart to have the following results ?

 

986.993
10127.884
11149.524
12162.090
13141.266
14119.142
1594.588
1681.925
1787.434
18107.219
19168.360
20172.454
2117.996

Thank you in advance

6 Replies
swuehl
MVP
MVP

Try chart inter record functions like Below():

Create your chart with dimension Hour and use as expression:

=Below(Sum(Current)) - sum(Current)

sunny_talwar

May be like this in the script:

Table:

LOAD Hour,

    Current

FROM

[https://community.qlik.com/thread/218744]

(html, codepage is 1252, embedded labels, table is @1);

FinalTable:

LOAD Hour,

  Current,

  Num(Peek('Current') - Current) as Diff

Resident Table

Order By Hour desc;

DROP Table Table;


Capture.PNG

Peter_Cammaert
Partner
Partner

I should stay awake, even on sunday...

geogou1973
Creator
Creator
Author

I found this formula and i have the following results

[Current]-above([Current])

 

HourCurrentDiff
967.509-
10164.98097.471,52
11297.143132.162,57
12447.743150.599,89
13593.142145.399,48
14723.848130.706,02
15834.814110.965,57
16925.86591.051,28
17996.62070.754,97
181.076.05779.436,44
191.177.834101.777,55
201.307.128129.294,29
211.449.573142.444,75
221.462.15912.585,81
Peter_Cammaert
Partner
Partner

Do not follow my first post (I deleted it because it was wrong. Sorry). Follow Stefan's suggestion.

Best,

Peter

sunny_talwar

I am going to offer a slight modification to Stefan's solution (and I am sure he would approve the changes I propose)

(Below(Sum({1}Current)) * Avg(1)) - Sum(Current)

or

(Below(Sum({<Hour>}Current)) * Avg(1)) - Sum(Current)

This will help if you plan to make selection in the Hour field.

When no selections are made:

Capture.PNG

When single hour is selected:

Capture.PNG

When hours are selected continuously (14,15,16,17):

Capture.PNG

When non continuous hours are selected (13, 15, 17):

Capture.PNG

So if you don't plan to make selections in hour field, you might be good with what Stefan provided. But if you plan to make selection in Hour, then you might want to make the above modifications.