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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
microwin88x
Creator III
Creator III

Fill Values for a Field

Hello,

I have the following table:

GROUPCODESALESMEDIAN
12129284,6-
1229230,8-
12318461,5-
12463907,78.769
1257292,3-
1266553,8-
1277376,9-
12811076,9-
1296769,2-
12108307,7-
16269461,5-
162710984,69.342
16288461,5-
16299223,1-
173017076,915.077
173112923,1-
173215076,9-

I calculate the MEDIAN field in my table as: AGGR(MEDIAN(SALES),GROUP). This is for every GROUP.

The thing is I'd need to fill that MEDIAN value for every GROUP and compare if SALES > MEDIAN then STATUS = 1, if not 0:

GROUPCODESALESMEDIANSTATUS
12129284,68.7691
1229230,88.7691
12318461,58.7691
12463907,78.7691
1257292,38.7690
1266553,88.7690
1277376,98.7690
12811076,98.7691
1296769,28.7690
12108307,78.7690
16269461,59.3421
162710984,69.3421
16288461,59.3420
16299223,19.3420
173017076,915.0771
173112923,115.0770
173215076,915.0770

Finally count those CODES with STATUS = 1 and STATUS = 0:

CODE > MEDIAN (STATUS = 1)8
CODE < MEDIAN (STATUS = 0)9

Do you know how could I do that?

Thanks.

1 Solution

Accepted Solutions
devarasu07
Master II
Master II

Hi Micro,

Seems same requirements, solutions already provided. help to close this duplicated thread. Thanks

=count({<CODE= {"=sum(SALES) >= Aggr(Median(Total <GROUP>SALES),GROUP,CODE)"} > } CODE)

Best Regards,

Deva

View solution in original post

5 Replies
ziadm
Specialist
Specialist

Hi micro

Try this in script .. you can achieve the same on the front end Table

// This is on the script

Table1:

load * Inline [

GROUP, CODE, SALES

12, 1, 29284

12, 2, 9230

12, 3, 18461

12, 4, 63907

12, 5, 7292

12, 6, 6553

12, 7, 7376

12, 8, 11076

12, 9, 6769

12, 10, 8307

16, 26, 9461

16, 27, 10984

16, 28, 8461

16, 29, 9223

17, 30, 17076

17, 31, 12923

17, 32, 15076 ];

Left Join

load GROUP,

Median(SALES) as MEDAIN

Resident Table1

Group by GROUP;

NoConcatenate

DataTable:

LOAD *,

if (SALES > MEDAIN,1,0) as STATUS

Resident Table1;

microwin88x
Creator III
Creator III
Author

Hello,

Isn't there any way to do it directly in my chart as an expression?

Because actually the median is dynamic and could be affected by multiple variables...

ziadm
Specialist
Specialist

Yes ..

Create a straight table and your dimension is GROUP

expression

Median(SALES)

if(Median(SALES) > SALES,1,0)

ziadm
Specialist
Specialist

you could the expression

Agg(Median(SALES),GROUP)

devarasu07
Master II
Master II

Hi Micro,

Seems same requirements, solutions already provided. help to close this duplicated thread. Thanks

=count({<CODE= {"=sum(SALES) >= Aggr(Median(Total <GROUP>SALES),GROUP,CODE)"} > } CODE)

Best Regards,

Deva