Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
danielle_v
Creator
Creator

Aggr and Set Analysis (YTD Expression)

Hi All,

My dataset is based around orders, and there can be multiple items per order, so my data is at Order-Item level.However, I need to calculate the average number of DaysToDeliver at Order level, so I have been using the following expression;

avg(aggr(only(DaysToDeliver),Order))

This works fine, but when I try and amend the expression so that it is looking at Year to Date (based on week and month calendar selections), it doesn't seem to bring back the correct results.

The expression I have been using is;

avg(aggr(only(

{$<DeliveryCalWeek = {"<=$(=max(DeliveryCalWeek))"}, 

DeliveryCalMonth = {"<=$(=max(DeliveryCalMonth))"}>}

DaysToDeliver), Order))

Whatever I try, it seems to be ignoring the week and month parts of the expression. This works fine without AGGR, so I'm assuming it is this thats stopping the calculation from working correctly. I just can't figure out why, or how to correct it.

Not sure if this makes any difference. but it's a straight table I'm trying to use this expression in.

Any help much appreciated!

3 Replies
daveamz
Partner - Creator III
Partner - Creator III

Hi Danielle,

Like I replied in your last post, a simple and clar way to calculate the average for DaysToDeliver is to use avg(distinct DaysToDeliver).

Best regards,

David

er_mohit
Master II
Master II

try this

avg({<DateField = {">=$(=YearStart(max(Datefield))) <=$(=max(Datefield))"},DeliveryCalWeek =, DeliveryCalMonth = >} DaysToDeliver) or if doen't helps then try to use

with aggrgation function

avg(aggr(only({$<DateField = {">=$(=YearStart(max(Datefield))) <=$(=max(Datefield))"},DeliveryCalWeek =,DeliveryCalMonth = >}

DaysToDeliver), Order))

hope it helps

danielle_v
Creator
Creator
Author

Hi David,

Thanks for your response.

However, I don't think this will work as there may be multiple orders with the same number of DaysToDeliver, so I don't think I'd be able to use avg(distinct DaysToDeliver) for this