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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Calculating Average when using cross table

Hello

Previously I created a cross table to show data on a line chart in a specific manner.

Original data:

ProjectCost1Cost2Cost3
A156
B336
C143
D345
E464

Cross table data:

ProjectCostValue
ACost11
ACost25
ACost36
BCost13
BCost23
etcectetc

This was the result, and it is great:

Chart_Qlikview.png.png

I now want to show the Average Cost for all of the Project at the specific Cost dimension.

Could you please aid me as to how I can still show the line for each Project, as well as a line for the average Cost?

I did try to get this working by using the aggr function and adding more expressions, and also by altering the load script, but I just can't get the solution to a seemingly simple problem. Also adding the Average trendline doesnt work, as it gives the Average for each Project.

3 Replies
nirav_bhimani
Partner - Specialist
Partner - Specialist

Hi,

Try this expression for avg TrendLine

( Avg({<Project=>} Cost1) + Avg({<Project=>} Cost2) + Avg({<Project=>} Cost3) ) /3

Regards,

Nirav Bhimani

Not applicable
Author

Thank you for your answer.

When I put that in as an expression, this is my result:

ChartWrong.png

When I change the Cost1, Cost2, Cost3 to [Value], it calculates the Average correctly, but still compresses the other lines:

ChartWrongAlmostRight.png

I want to have all the lines of the Projects still visible as well.

Not applicable
Author

hi,

If you fetch data from table, then you can use CASE function.

like

SELECT project, SUM(CASE WHEN cost = 'Cost1' THEN value ELSE 0 END) AS Cost1, SUM(CASE WHEN cost = 'Cost2' THEN value ELSE 0 END) AS Cost2, SUM(CASE WHEN cost = 'Cost3' THEN value ELSE 0 END) AS Cost3 from table GROUP BY project;

--Prabhu Ch