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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
gouthamkk
Creator
Creator

Median Expression

Hi Experts,

I am trying to write an Expression in a chart object to calculate the median of weight.

I have date, empid, branch,flag and position. And i have a history of 3 years data.

i would like to calculate the median of weight for past 24 months, excluding current month. I tried below expression

Median({<empid=,branch=, flag =, position=,>}  aggr( weight,branch,flag, position ))

When no selection made i am getting correct median. But if i select an empid, the median is changing also i have to add date selections.

Can some please Advise. 

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Yes, that's possible. Something like:

({<empid=,branch=, flag =, position=, date={"=date=>$(=monthstart(max(date),-24)) and date<$(=monthstart(max(date)))"}>}


talk is cheap, supply exceeds demand

View solution in original post

4 Replies
marcus_sommer

The expression had not a valid syntax - it should be look more like:

median(aggr(sum(Value), YourDimensions))

if you really needed an aggr-function and if you will need to consider if possible set analysis conditions belong to inner or outer aggregation.

AGGR...

When should the Aggr() function NOT be used?

Pitfalls of the Aggr function

- Marcus

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

You use the implicit aggregation function Only() when you don't specify on explicitly. And you need to add the set modifier to that aggregation too. So you must make the aggregation explicit:"

Median({<empid=,branch=, flag =, position=>}  aggr( only({<empid=,branch=, flag =, position=>}weight) ,branch,flag, position ))

You may want to use sum() instead of only() if there are several weight values per combination of empid, branch, flag and position values.


talk is cheap, supply exceeds demand
gouthamkk
Creator
Creator
Author

HI,

this is helpfull. Is there any way i could also add date dimesion so that it caluclates only for last 24 month excluding current month

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Yes, that's possible. Something like:

({<empid=,branch=, flag =, position=, date={"=date=>$(=monthstart(max(date),-24)) and date<$(=monthstart(max(date)))"}>}


talk is cheap, supply exceeds demand