Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
vignesh_s
Creator
Creator

least 13

hi all

How could i find the sum of least 13 values in load script

1 Solution

Accepted Solutions
tresesco
MVP
MVP

You can still utilized the script I shared above like:

t1:

load key Inline [

key

A

B

C

D

F

G

];

JOIN

 

load * Inline [

key value

A 2

A 3

A 4

A 5

B 6

B 7

C 8

D 9](delimiter is spaces);

//t1:

//Load

// Floor(RowNo()*Rand()*100) as Value

//AutoGenerate 20 ;

NoConcatenate

t2:

Load Distinct

       value

Resident t1 Order By value desc;

Drop Table t1;

Let vMin13th=FieldValue('value',3);        //Change the number here for Xth value

Load

       Sum(value) as SumOfLeast13Values

Resident t2 where value<=$(vMin13th);

View solution in original post

9 Replies
sunny_talwar

May be like this

LOAD ...,

     RangeSum(Min(Value, 1), Min(Value, 2), Min(Value, 3)....., Min(Value, 13)) as SumOf13MinValue

Resident/From ....

Group By ....;

vignesh_s
Creator
Creator
Author

hi sunny thanks,what is expression for to find least 50 r least 100,can v write dynamic expression ?

tresesco
MVP
MVP

If you are taking about single field values.. try something like:

t1:

Load

       Floor(RowNo()*Rand()*100) as Value

AutoGenerate 20 ;

NoConcatenate

t2:

Load Distinct

       Value

Resident t1 Order By Value desc;

Drop Table t1;

Let vMin13th=FieldValue('Value',13);    // change here your XXth value

Load

       Sum(Value) as SumOfLeast13Values

Resident t2 where Value<=$(vMin13th);

vignesh_s
Creator
Creator
Author

thanks tresesco,but im nt using single field im using group function in it

tresesco
MVP
MVP

Could you post sample data and expected output against that?

sunny_talwar

I agree, it would be easier to help if we know what all fields you have and at what level are you trying to do your Min

vignesh_s
Creator
Creator
Author

input:

table1:

load

key

A

B

C

D

F

G

FROM....

JOIN

load

key value

A 2

A 3

A 4

A 5

B 6

B 7

C 8

D 9

. .

. .

. .

. .

. .

from...........

like this i have 1000 of value

i wanna sum of least 50 r least 100 values , need expression dynamicaly in load script

output:

load *

sum of value

resident table1

group by key;

drop table table1;

vignesh_s
Creator
Creator
Author

input:

table1:

load

key

A

B

C

D

F

G

FROM....

JOIN

load

key value

A 2

A 3

A 4

A 5

B 6

B 7

C 8

D 9

. .

. .

. .

. .

. .

from...........

like this i have 1000 of value

i wanna sum of least 50 r least 100 values , need expression dynamicaly in load script

output:

load *

sum of value

resident table1

group by key;

drop table table1;

tresesco
MVP
MVP

You can still utilized the script I shared above like:

t1:

load key Inline [

key

A

B

C

D

F

G

];

JOIN

 

load * Inline [

key value

A 2

A 3

A 4

A 5

B 6

B 7

C 8

D 9](delimiter is spaces);

//t1:

//Load

// Floor(RowNo()*Rand()*100) as Value

//AutoGenerate 20 ;

NoConcatenate

t2:

Load Distinct

       value

Resident t1 Order By value desc;

Drop Table t1;

Let vMin13th=FieldValue('value',3);        //Change the number here for Xth value

Load

       Sum(value) as SumOfLeast13Values

Resident t2 where value<=$(vMin13th);