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

Calculate difference in same feilds and show delta

I have a table such as:

name    count

java         200

java_1   400

db          500

db_1     400

sql         1000

sql_1     1000

_______________________________________

 

I want the counts to be displayed as:

name    count    delta

java       400         +200

db          500         -100

sql         1000        0

__________________________________

 

Basically taking example of one row, Java

we're calculating java_1-java and showing it in the other table with + sign if count is more, or - sign accordingly.

Labels (1)
3 Replies
raman_rastogi
Partner - Creator III
Partner - Creator III

Try This

Data:
Load * Inline [
name, count
java, 200
java_1, 400
db, 500
db_1, 400
sql, 1000
sql_1, 1000];

Load
RecNo(),
PurgeChar( (name),'_1') as Name,
count-Previous(count) as count
Resident Data where PurgeChar( (name),'_1')=PurgeChar( Previous(name),'_1');
Drop Table Data;

 


Regards,

Raman

sujit_nath
Creator III
Creator III
Author

Thanks Raman,

But previous wont work here because in actual data, it won't be necessary that the _1 thing would be just above the original data.

Is there a way to identify that from any row in the data and get the difference?

raman_rastogi
Partner - Creator III
Partner - Creator III

try this one 

Data:
Load * Inline [
name, count
java_1, 400
java, 200
db, 500
db_1, 400
sql_1, 1000
sql, 1000];

Data_temp:
Load
name,
PurgeChar( (name),'_1') as Name,
count
Resident Data Order by name ;
Drop Table Data;
Load
RecNo(),
Name,
count-Previous(count) as count
Resident Data_temp where Name=Previous(Name) ;
Drop Table Data_temp;