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: 
ajaykumar1
Creator III
Creator III

Average help

Hi Everyone,

Greetings of the day !.

I need some help to calculate the average formula with below mentioned output format.

I tried like this ;  avg(aggr(sum(amount),[week]))

Please find the attached sample data.

Input Data :

 

IDWeekamount
1375500
13820000
14513000
14724000
15024000
54015000
54417000
104350000
124680000
1247

70000

Week is my dimension.I taken in Pivot table for to fulfil in horizontal way.

Out put :

   

IDWeek373840434445464750Grand TotalAverage
1 550020000 13000 24000240008650017300
5 15000 17000 3200016000
10 50000 5000050000
12 8000070000 15000075000
Total55002000015000500001700013000800009400024000318500

More Thanks,

Ajay

1 Solution

Accepted Solutions
sunny_talwar

This:

Capture.PNG

Script:

Table:

LOAD ID,

    Week,

    amount

FROM

Avg_Help.xlsx

(ooxml, embedded labels, table is [Data ]);

Dim:

LOAD * Inline [

Dim

1

2

];

Pivot Table

Dimensions:

ID

=Pick(Dim, Week, 'Total')

    Dimension Color Expression: If(Pick(Dim, Week, 'Total') = 'Total', RGB(245,245,245))

    Dimension Text Format: =If(Pick(Dim, Week, 'Total') = 'Total', '<B>')

Expression:

=If(Pick(Dim, Week, 'Total') = 'Total', Sum(DISTINCT Aggr(NODISTINCT Sum(amount), ID)), Avg(Aggr(Sum(amount), ID, Week)))

Background color expression:

If(Pick(Dim, Week, 'Total') = 'Total', RGB(245,245,245))

Credit to Kush141087 for introducing this Pick technique to me.

Best,

Sunny

UPDATE:

Sort Expression for calculated Dimension:

=Pick(Dim, Week, 'Total') with Descending Sort

View solution in original post

10 Replies
swuehl
MVP
MVP

I think you may need to add ID to your aggr() dimensions:

avg(aggr(sum(amount),[week], ID))

sunny_talwar

This?

Capture.PNG

Expression: =Avg(Aggr(Sum(amount), ID, Week))

ajaykumar1
Creator III
Creator III
Author

Thanks for quick reply....But its not giving expected output.

I want average also...Upto grand total i got it.

Anonymous
Not applicable

PFA..

sunny_talwar

You want average and grand total both?

ajaykumar1
Creator III
Creator III
Author

Yes....I want Grand total and Average last right side.

Your earlier output is right but i need grand total also...Your average is perfect.

sunny_talwar

This:

Capture.PNG

Script:

Table:

LOAD ID,

    Week,

    amount

FROM

Avg_Help.xlsx

(ooxml, embedded labels, table is [Data ]);

Dim:

LOAD * Inline [

Dim

1

2

];

Pivot Table

Dimensions:

ID

=Pick(Dim, Week, 'Total')

    Dimension Color Expression: If(Pick(Dim, Week, 'Total') = 'Total', RGB(245,245,245))

    Dimension Text Format: =If(Pick(Dim, Week, 'Total') = 'Total', '<B>')

Expression:

=If(Pick(Dim, Week, 'Total') = 'Total', Sum(DISTINCT Aggr(NODISTINCT Sum(amount), ID)), Avg(Aggr(Sum(amount), ID, Week)))

Background color expression:

If(Pick(Dim, Week, 'Total') = 'Total', RGB(245,245,245))

Credit to Kush141087 for introducing this Pick technique to me.

Best,

Sunny

UPDATE:

Sort Expression for calculated Dimension:

=Pick(Dim, Week, 'Total') with Descending Sort

settu_periasamy
Master III
Master III

Hi,

May be try this..

Add one dummy dimension, and use the SecondaryDimensionality() in your expression..

Like..

=if(SecondaryDimensionality()=1,sum(aggr(sum(amount),ID,Week)),

  if(SecondaryDimensionality()=0,Avg(Aggr(sum(amount),ID,Week)),(sum(amount))))

Capture.JPG

ajaykumar1
Creator III
Creator III
Author

Thanks Sunny.Its working fine.

I need to understand the 'Dim'Technique.

Please explain this logic when you get time.

Thanks,

Ajay