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

Pivot Table - Sum of Two Fields

Hello everyone,

I have a pivot table that sums up two different fields using, again, two different fields as dimension. For example:

 

Year1Year2Value1Value2
120.4558850.544115
230.5016060.498394
340.1177140.882286
450.8665230.133477
560.385560.61444
670.3919170.608083
780.5420710.457929
890.5436960.456304


It will be easy to do this via SQL and load in another table that has a shape like this:

YearValue
10.455885
21.045721
30.616108
41.748808
50.519037
61.006357
71.150154
81.001625
90.456304

However, I am loading in two very large tables already and loading another one would seriously compromise the performance of QV. Is there any way to set up the dimension and expression to achieve this?

My thoughts for the expression will be something like this:

sum(Value1) + sum(Value2)

But for the Calculated Dimension, I'm out of ideas. Hope you guys can help me out.

Thank you!

-Nathan

5 Replies
sunny_talwar

I am not sure I understand the logic behind your output table based on your input table. Would you be able to elaborate a little on how did you get from input to output?

Not applicable
Author

Hi Sunny,

Apologies for this as I created a sample using excel and the RAND() Function. I copied the wrong input table. So basically this is what happens:

For Year 1 in the output table: We get 0.455885 (Corresponds the the first record since the Year1 field is equal to 1)

For Year 2 in the output table: We get 0.544115 + 0.501606 = 1.045721  (Corresponds to the Year2 field =2 and Year1 field =2)

Hope this clarifies everything.

Anil_Babu_Samineni

Do you mean when years are same then you want to do Sum(Value1)+Sum(Value2)

Would you describe more

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
sunny_talwar

May be create an Island table for another field called Year and use that to show your new information on the front end. Please note, since you will be using Aggr() with island table, performance is going to be issue here:

Script:

Table:

LOAD Year1,

  Year2,

  Value1,

  Value2

FROM [https://community.qlik.com/thread/241470]

(html, codepage is 1252, embedded labels, table is @1);

Year:

LOAD MinYear + IterNo() - 1 as Year

While MinYear + IterNo() - 1 <= MaxYear;

LOAD RangeMin(Min(Year1), Min(Year2)) as MinYear,

  RangeMax(Max(Year1), Max(Year2)) as MaxYear

Resident Table;

Data model

Capture.PNG

Table:

Dimension:

Year

Expression:

=RangeSum(Sum(Aggr(If(Year = Year1, Value1), Year, Year1)), Sum(Aggr(If(Year = Year2, Value2), Year, Year2)))

Capture.PNG

Not applicable
Author

To illustrate:

For Year 1 in the output table: We get 0.455885 (Corresponds the the first record since the Year1 field is equal to 1)

For Year 2 in the output table: We get 0.544115 + 0.501606 = 1.045721  (Corresponds to the Year2 field =2 and Year1 field =2) So we sum up Value2 of the first row since Year2 of the first row = 2 and the Value1 of the second row since the Year1 of the second row = 2.