# QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld 2023, a live, in-person thrill ride. Save \$300 before February 6: REGISTER NOW!
cancel
Showing results for
Did you mean:
Contributor III

## Summing different values depnding from value of grouping dimensions

Hi guys,

i' sorry for the enigmatic subject 🙂

an example is the best thing!

Data Model:

tab:
productType, price1, price2, price3
productType1, 4, 6, 3
productType2, 3, 7, 12
productType1, 6, 15, 3
productType2, 2, 17, 22
];

i'd like to build a table/graph grouping by productType and summing the prices like this:

productType1, 95

productType2, 5

where for the product1 i sum(price1+price2+price3) but for product2 i sum just price 1.

It is possible?

Any idea?

many thanks!!!

1 Solution

Accepted Solutions
Contributor III
Author

eureka!

maybe i found the solution

an expr like this:

=SUM({<productType = {'productType1'}>}aggr(sum(total price2 + price3), productType))+ sum(price1)

it seems to work!

i need to test it better, but i'm confident

5 Replies
Partner - Specialist

In the real data, how many product types are there?

Contributor III
Author

Very few...

4 or 5..

Partner - Specialist

May be oversimplified, but try something like this:

tab:
productType, price1, price2, price3
productType1, 4, 6, 3
productType2, 3, 7, 12
productType1, 6, 15, 3
productType2, 2, 17, 22
];

NoConcatenate

table:
*,
if(productType='productType1',price1+price2+price3) as productType1_Price,
if(productType='productType2',price1) as productType2_Price
Resident tab;
Drop Table tab;

The in the app you sum productType1_Price or productType2_Price

Contributor III
Author

thanks but does not work becouse in the record "productType1" you have to consider the price2 and price3 of the productType2 also..

it is not simple..

Contributor III
Author

eureka!

maybe i found the solution

an expr like this:

=SUM({<productType = {'productType1'}>}aggr(sum(total price2 + price3), productType))+ sum(price1)

it seems to work!

i need to test it better, but i'm confident

Community Browser