Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Highlighted
Not applicable

set average of group as a variable

groupvalue
A14
A23
A53
B4
B63
B13
B7

When loading the data, I want to set variables of each group(A and B)

SET vAverageA = (average value of group A)//(14+23+53)/3

SET vAverageB = (average value of group B)//(4+63+13+7)/4

Does anybody know how to do this?

1 Solution

Accepted Solutions

Re: set average of group as a variable

May be this:

Table:

LOAD * Inline [

group, value

A, 14

A, 23

A, 53

B, 4

B, 63

B, 13

B, 7

];

AggrTable:

LOAD Avg(value) as Avg,

  group

Resident Table

Group By group

Order By group;

For i = 1 to FieldValueCount('group')

  vField = FieldValue('group', $(i));

  TempTable:

    NoConcatenate

    LOAD Avg

    Resident AggrTable

    Where group = '$(vField)';

   

    LET vAverage$(vField) = Peek('Avg');

    DROP Table TempTable;

NEXT i

Drop Table AggrTable;

2 Replies

Re: set average of group as a variable

May be this:

Table:

LOAD * Inline [

group, value

A, 14

A, 23

A, 53

B, 4

B, 63

B, 13

B, 7

];

AggrTable:

LOAD Avg(value) as Avg,

  group

Resident Table

Group By group

Order By group;

For i = 1 to FieldValueCount('group')

  vField = FieldValue('group', $(i));

  TempTable:

    NoConcatenate

    LOAD Avg

    Resident AggrTable

    Where group = '$(vField)';

   

    LET vAverage$(vField) = Peek('Avg');

    DROP Table TempTable;

NEXT i

Drop Table AggrTable;

Not applicable

Re: set average of group as a variable

Thank you so much!! It worked!!