Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
shivamkedia
Partner - Contributor II
Partner - Contributor II

storing the value of summission of a column in variable

Table A:

ColumnName1,colmnName2

a                                   2

b                                  3

c                                  4

vVariable1=sum(columnName2) where columnName1=(a and b) i.e. vVariable1=5

i want sum (columnName2) with where condition(columnName2=a and b) and store into an variable vVariable1.

 

1 Solution

Accepted Solutions
sunny_talwar

Here is the alternative

Table:
LOAD * INLINE [
    ColumnName1, colmnName2
    a, 2
    b, 3
    c, 5
];

TempTable:
LOAD Sum(colmnName2) as SumAB
Resident Table
Where Match(ColumnName1, 'a', 'b');

LET vSumAB = Peek('SumAB');

DROP Table TempTable;

FinalTable:
LOAD *,
	 colmnName2 - $(vSumAB) as Result
Resident Table;

DROP Table Table;

View solution in original post

10 Replies
sunny_talwar

May be create a variable like this

Sum({<columnName1 = {'a', 'b'}>} columnName2)
shivamkedia
Partner - Contributor II
Partner - Contributor II
Author

All Things must be in Script.

shivamkedia
Partner - Contributor II
Partner - Contributor II
Author

 This will work in script..???

 

sunny_talwar

I am not sure I understand... are you looking to use this value in the script?

shivamkedia
Partner - Contributor II
Partner - Contributor II
Author

yes.

sunny_talwar

Can you elaborate on how you are planning to use this in the script?

shivamkedia
Partner - Contributor II
Partner - Contributor II
Author

Suppose Table B:
Column1
5
2
3;
i want to subtract the vVariable (which i get from the above condition (Reference to Table A))
from column which results in
vvariable will be = 5(sum of columnname2 of Table A)
new Table result will be:
5-vVariable
2-vVariable
3-vVariable

Final Result:
0
-3
-2
sunny_talwar

May be try this

Table:
LOAD * INLINE [
    ColumnName1, colmnName2
    a, 2
    b, 3
    c, 5
];

Left Join (Table)
LOAD Sum(colmnName2) as SumAB
Resident Table
Where Match(ColumnName1, 'a', 'b');

FinalTable:
LOAD *,
	 colmnName2 - SumAB as Result
Resident Table;

DROP Table Table;
shivamkedia
Partner - Contributor II
Partner - Contributor II
Author

This is acceptable but doing left join with a large data(5 GB) is not logical which will increase my time thats why i was asking for the variable aproach.