Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
microwin88x
Creator III
Creator III

Calculate Median

Hi,

I have a table with the following:

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 as an expression in my table as: AGGR(MEDIAN(SALES),GROUP). This is for every GROUP.

The thing is that I only get the value for 1 from the GROUP and I'd need to fill the nulls with the same value for the GROUP.

Like this:

GROUPCODESALESMEDIAN
12129284,68.769
1229230,8
8.769
12318461,5
8.769
12463907,78.769
1257292,3
8.769
1266553,8
8.769
1277376,9
8.769
12811076,9
8.769
1296769,2
8.769
12108307,7
8.769
16269461,59.342
162710984,69.342
16288461,59.342
16299223,19.342
173017076,915.077
173112923,115.077
173215076,915.077

How can I do that directly on my simple table?

Thanks

1 Solution

Accepted Solutions
devarasu07
Master II
Master II

Hi,

Try like this,

AGGR(MEDIAN(total <GROUP>SALES),GROUP,CODE)

Capture.JPG

View solution in original post

11 Replies
devarasu07
Master II
Master II

Hi,

Try like this,

AGGR(MEDIAN(total <GROUP>SALES),GROUP,CODE)

Capture.JPG

microwin88x
Creator III
Creator III
Author

Thanks! I tried it and it works.

It'd be the same to use the following?:

MEDIAN(TOTAL<GROUP>SALES)

Cause it seems to be OK aswell. Could you check that out for me?

devarasu07
Master II
Master II

Hi Micro,

Yeah, it should be ok. Tks

microwin88x
Creator III
Creator III
Author

One last question Devarasu,

If I'd have to count how many CODES are greater than the associated Median for every row (comparing Sales with its Median),

Do you know how to do that?

I need to show it as a Text box with the number.

Thanks again!

devarasu07
Master II
Master II

Hi,

Try like this,

=count({<CODE= {"=sum(SALES) > MEDIAN(TOTAL<GROUP>SALES)"} > } CODE)

Capture.JPG

microwin88x
Creator III
Creator III
Author

It worked for most of cases, I found 2 of them that should have value = 1.

Do you know what it could be?

GROUP CODE (SALES) MEDIAN Status
9461 8
121292848768,51
12292308768,50 > Shouldn't be 1? 9230 > 8768
123184618768,51
124639078768,51
12572928768,50
12665538768,50
12773768768,50
128110768768,51
12967698768,50
121083078768,50
1626946193420 > Shouldn't be 1? 9461> 9342
16271098493421
1628846193420
1629922393420
173017076150761
173112923150761 > Should be 0
173215076150761 > Should be 0 (Its 😃
devarasu07
Master II
Master II

Can you try like below

=count({<CODE= {"=sum(SALES) >= median(total <GROUP>  aggr(sum(SALES),CODE))"} > } CODE)

microwin88x
Creator III
Creator III
Author

Almost... But thanks for the help!

I think it has something to do with the agroupation between the Group and Code...

devarasu07
Master II
Master II

Hi,

Last try this, It should work

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

Capture.JPG

Hope this helps to you

Best Regards,

Deva