3 Replies Latest reply: Jun 26, 2013 8:12 AM by Danielle van Eeden

# 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!

• ###### Re: Aggr and Set Analysis (YTD Expression)

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

• ###### Re: Aggr and Set Analysis (YTD Expression)

Hi David,

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

• ###### Re: Aggr and Set Analysis (YTD Expression)

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