Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
mpressey
Creator
Creator

Calculate Average Over All Dimension Values in Pivot Table

In the attached example, how can I calculate the average over all weekdays versus the average over just days with sums?

1 Solution

Accepted Solutions
sunny_talwar

Try this

If(Dimensionality() = 0,

Sum(Aggr(Avg(Aggr(Sum(Visit),Hour,WeekDay,Location))/Avg(Aggr(Count(DISTINCT Visit),Hour,WeekDay,Location)),Hour,WeekDay,Location))/Count(DISTINCT TOTAL WeekDay),

Avg(Aggr(Sum(Visit),Hour,WeekDay,Location))/Avg(Aggr(Count(DISTINCT Visit),Hour,WeekDay,Location)))

Capture.PNG

View solution in original post

6 Replies
sunny_talwar

What is your expected output for the two numbers and which object do you need this in?

Anil_Babu_Samineni

Is this you want to see?

avg(aggr(sum(Visit),Hour,WeekDay,Location))

Capture.PNG

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
mpressey
Creator
Creator
Author

In the avg pivot, I would like the average calculation to treat the nulls, '-', as zero values.Desired Pivot AVG Results.PNG

sunny_talwar

Try this

If(Dimensionality() = 0,

Sum(Aggr(Avg(Aggr(Sum(Visit),Hour,WeekDay,Location))/Avg(Aggr(Count(DISTINCT Visit),Hour,WeekDay,Location)),Hour,WeekDay,Location))/Count(DISTINCT TOTAL WeekDay),

Avg(Aggr(Sum(Visit),Hour,WeekDay,Location))/Avg(Aggr(Count(DISTINCT Visit),Hour,WeekDay,Location)))

Capture.PNG

sunny_talwar

Simplified version of the expression

If(Dimensionality() = 0,

Sum(Aggr(Avg(Visit),Hour,WeekDay,Location))/Count(DISTINCT TOTAL WeekDay),

Avg(Visit))

mpressey
Creator
Creator
Author

Thank you Sunny. This is very helpful. I have not used dimensionality very much.