1 Reply Latest reply: Dec 7, 2017 12:34 PM by Sunny Talwar

# avg Age

Hi Community,

we got the task to calculate the avg age of our customers in a table regarding ad hoc dimension and dynamic time-periods.

now we have to calulate in these steps:

1.We have the age of a single customer per order :

customer1: 49+50+50 (men)

customer2: 32+32  (men)

customer3: 43+43+44 (women)

We put our dimensions-selections in following ad-hoc dimension:

vSelectedDim = GetFieldSelections(_dimensionname)

2. Then we want to aggratage this age for the selected timeperiod and ad hoc-dimensions:

customer1: (49+50+50)/3 =      49,67

customer2: (32+32)/2 =          32,0

customer3: (43+43+44)/3 =      43,33

what works for us is:
vAge
= 'aggr(avg([Age]),Customer, Order, '&\$(vSelectedDim)&')'

3. At last we want to get the average-age of all customers, who bought in the selected time period, separeted by gender:

men: Ø Age = (49,67+32)/2 = 40,83 years

women: Ø Age = (43,33)/1 = 43,33 years

Do you have an idea, how to get the last step?

Thanks a lot,
Katalina and Nina

• ###### Re: avg Age

What happens when you wrap your expression around with Avg?

Avg(Aggr(Avg(Age), Customer, Order, \$(=vSelectedDim)))

I didn't understand the usage of '&\$(vSelectedDim)&')' in your expression. Since I don't know what that is doing, I am proposing to add something else... but this may not be perfect based on your field names with spaces and multiple selections etc