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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
pepe2209
Creator
Creator

calculate value for last record per group

Hello

Please look at the example below, i would like to create in the script the field 'Remaining':

IDCycleValueEndvalueRemaining
118150
1211150
1313152
218200
2211200
2313200
2416204

So, every time the max cycle of an ID is reached I want to calculate the remaining difference between 'Endvalue' and 'Value'. But for the other cycles 'Remaining' should be zero. So it's an calculation per group (ID).

Your help would be much appreciated,

Regards,

Peter

1 Solution

Accepted Solutions
Not applicable

Peter,

I would do sth like that. I create a list of the last value of cycle (use of Max but also we could use LastValue) concatenated with the ID. So that I get a list of ID_LastValue.
Afterwards, just a test to see if we compute the remaining or not.

 

Temp:
LOAD ID,
Max(Cycle) as LC
FROM [108376.xlsx](ooxml, embedded labels, table is Feuil1)
GROUP BY ID;

Left Join(Temp)
LOAD *, ID & '_' & LC as IDLC

Resident Temp;

Data:;
LOAD ID,
Cycle,
Value,
EndValue,
if (exists(IDLC, ID & '_' & Cycle), EndValue-Value, 0 ) as Remaining

FROM [108376.xlsx](ooxml, embedded labels, table is Feuil1);

drop table Temp;

Fabrice

View solution in original post

2 Replies
Not applicable

Peter,

I would do sth like that. I create a list of the last value of cycle (use of Max but also we could use LastValue) concatenated with the ID. So that I get a list of ID_LastValue.
Afterwards, just a test to see if we compute the remaining or not.

 

Temp:
LOAD ID,
Max(Cycle) as LC
FROM [108376.xlsx](ooxml, embedded labels, table is Feuil1)
GROUP BY ID;

Left Join(Temp)
LOAD *, ID & '_' & LC as IDLC

Resident Temp;

Data:;
LOAD ID,
Cycle,
Value,
EndValue,
if (exists(IDLC, ID & '_' & Cycle), EndValue-Value, 0 ) as Remaining

FROM [108376.xlsx](ooxml, embedded labels, table is Feuil1);

drop table Temp;

Fabrice

pepe2209
Creator
Creator
Author

Ok thanks!