# New to QlikView

Discussion board where members can get started with QlikView.

Contributor

## Calculate difference in sum based on previous day, week, month,year

Hi

I need help on how to find the consumption of a heat meter based on the previous date.

My Data

 Meter No] Created Energy (wH) What i need 82251145 17-03-2019 100 82251145 18-03-2019 250 150 82251145 19-03-2019 500 250 82251145 20-03-2019 1200 700 82251145 21-03-2019 5000 3800 82251145 22-03-2019 6000 1000 82251145 23-03-2019 8500 2500 82251145 24-03-2019 9500 1000

```Heat_meter:
LOAD      Num(@2) as [Meter No], //Heat meter serial no.
Date(@3) as [Created], //Timestamp
Num(@7) as [Energy (wH)] //Actual energy used since the day it was installed. //What i need is to subtract the Energy from the previous day, to get the consumption used the last day.
FROM
[D:\Elvaco_FTP\Elvaco_Teknikrum\HeatMeter\*.csv]
(txt, codepage is 28591, no labels, delimiter is ';', msq, header is 1 lines where Date(@3)>=today()-7;```

1 Solution

Accepted Solutions
Partner

## Re: Calculate difference in sum based on previous day, week, month,year

```Heat_meter:
Num(@2) as [Meter No], //Heat meter serial no.
Date(@3) as [Created], //Timestamp
Num(@7) as [Energy (wH)], //Actual energy used since the day it was installed.
Num(@7 - peek('@7') as [What i need]

FROM
[D:\Elvaco_FTP\Elvaco_Teknikrum\HeatMeter\*.csv]
(txt, codepage is 28591, no labels, delimiter is ';', msq, header is 1 lines where Date(@3)>=today()-7;
```

https://help.qlik.com/en-US/qlikview/November2018/Subsystems/Client/Content/QV_QlikView/Scripting/In...

Plees ekskuse my Swenglish and or Norweglish spelling misstakes
3 Replies
Partner

## Re: Calculate difference in sum based on previous day, week, month,year

```Heat_meter:
Num(@2) as [Meter No], //Heat meter serial no.
Date(@3) as [Created], //Timestamp
Num(@7) as [Energy (wH)], //Actual energy used since the day it was installed.
Num(@7 - peek('@7') as [What i need]

FROM
[D:\Elvaco_FTP\Elvaco_Teknikrum\HeatMeter\*.csv]
(txt, codepage is 28591, no labels, delimiter is ';', msq, header is 1 lines where Date(@3)>=today()-7;
```

https://help.qlik.com/en-US/qlikview/November2018/Subsystems/Client/Content/QV_QlikView/Scripting/In...

Plees ekskuse my Swenglish and or Norweglish spelling misstakes
Partner

## Re: Calculate difference in sum based on previous day, week, month,year

```Heat_meter:
Num(@2) as [Meter No], //Heat meter serial no.
Date(@3) as [Created], //Timestamp
Num(@7) as [Energy (wH)], //Actual energy used since the day it was installed.
Num(@7 - peek('@7') as [What i need]

FROM
[D:\Elvaco_FTP\Elvaco_Teknikrum\HeatMeter\*.csv]
(txt, codepage is 28591, no labels, delimiter is ';', msq, header is 1 lines where Date(@3)>=today()-7;
```

https://help.qlik.com/en-US/qlikview/November2018/Subsystems/Client/Content/QV_QlikView/Scripting/In...

Plees ekskuse my Swenglish and or Norweglish spelling misstakes
Contributor

## Re: Calculate difference in sum based on previous day, week, month,year

(Jeg siger tak for hjælpen, det var lige det jeg skulle bruge. :))

Just a msg. for my Scandinavian buddy 🙂
The Peek() was just what i needed.

This is my result if someone else needs the solution.

```Heat_meter_temp:
Meter_no,
date(Created, 'YYYY-MM-DD HH:MM:ss') as Created,
num(Energy_wH/1000) as Energy_wH,
Volume_m3,
Volume_flow_m3H,
Flow_temp_C,
Return_temp_C,
Temp_diff_C
FROM
[C:\Heat_meter.qvd]
(qvd);

Heat_meter:
NoConcatenate