Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to Calculate Average of Average

Greetings everyone

I have the following Data

MACHINEID MONTHMONTHTIME_MINS
11100Apr-133211
11100May-133511
11100Jun-133600
11100Jul-133302
11121Jun-136212
11121Jul-136331
11132Jul-132212
11143May-135212
11143Jul-135521

Some Machines are not operational in certain months

So I want to Average TIME_MINS  based on MACHINEID. This will give AVERAGE per machine. Then AVERAGE_BY_MACHINEID to find the NET_AVERAGE

So if I manually calculate

average.PNG.png

What is the expression I should use?

Thank you

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think the solutions suggesting aggr() on on the right track. You can't use TOTAL for the Net Avg, because you want an avg of avg.

Create a Pivot Table and check "show partial sums" for MACHINEID and MONTH on the presentation pane. You can use dimensionality() to limit the display to just the subtotal lines. So for each machine, I would use:

=if(Dimensionality()=1

  ,avg(aggr(NODISTINCT avg(TIME_MINS),MACHINEID, MONTH))

  ,''

)

and for the Net Avg, I would use:

=if(Dimensionality()=0

  ,avg(aggr(

  avg(aggr(NODISTINCT avg(TIME_MINS),MACHINEID, MONTH))

  ,MACHINEID))

  ,''

)

See attached example.

View solution in original post

9 Replies
Not applicable
Author

Hi Ram, you shuould use the aggregate function(aggr) for the above scenario.

PFA the example.

BR,

Abhinava

tresesco
MVP
MVP

May be something like this?

PFA

ashwanin
Specialist
Specialist

I think you required the data same as per the mentioned pivot.

Create Chart

Make expression of avg of Time_Min as per Machine and put another Net average of whole Time_Min.( if you take the average of whole or average of average , both are same things)

it will gave you the same output as you required.

rgds Ashwani

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think the solutions suggesting aggr() on on the right track. You can't use TOTAL for the Net Avg, because you want an avg of avg.

Create a Pivot Table and check "show partial sums" for MACHINEID and MONTH on the presentation pane. You can use dimensionality() to limit the display to just the subtotal lines. So for each machine, I would use:

=if(Dimensionality()=1

  ,avg(aggr(NODISTINCT avg(TIME_MINS),MACHINEID, MONTH))

  ,''

)

and for the Net Avg, I would use:

=if(Dimensionality()=0

  ,avg(aggr(

  avg(aggr(NODISTINCT avg(TIME_MINS),MACHINEID, MONTH))

  ,MACHINEID))

  ,''

)

See attached example.

tresesco
MVP
MVP

Thanks Rob, I should have noticed that earlier.

I use the below formula for Avg of avg.

Avg(total Aggr(Avg(TIME_MINS),MACHINEIDMONTH))

Hello Ram, PFA, by now you have multiple solutions. However, Rob's solution is more acceptable.

Not applicable
Author

Thanks Abhinava,

Thanks . All together 3 different approach we have.

This is one of the approach.

Great.. everyday I am learning..

Not applicable
Author

Hi Rob

Thanks. I am learning new method. First time I  have learned how to use Dimensionality()

Method -2

Thanks.

Not applicable
Author

Hi Tresesco

Thanks for the reply. This is a third method.

Anonymous
Not applicable
Author

Hi Ram,

For Net Avg I would use following expression.

if(Dimensionality()=0,

  avg(aggr( avg(TIME_MINS),MACHINEID)),''

  )