# QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

Not applicable

## Subtotals for a calculated dimension?

Spent a few days and couldn't find a solution -- your help is much appreciated.

Data fields: Type, Product, Qty

PIVOT TABLE

Dimensions:

=Type

=if(aggr(sum(Qty),Product,Type)>500, '>500','<500')    /* labelled as Group

Expressions:

=Sum(Qty)

Calculated dimension is grouping for Products with Sum(Qty)>500 and <500.

Question: How to get subtotals for the calculated dimension to calculate percentage ?

This is the table I have:

This is the table I need to get:

Problem is not that so trivial as it seems -- try to play with the application (attached).

Thanks!

Tags (2)
1 Solution

Accepted Solutions
Not applicable

## Subtotals for a calculated dimension?

OK, here is the answer. Works like a charm with any number of rows in a calculated dimension, and without any additional data structures.

=sum(Qty)/rangesum(top(Sum(Qty),1,NoOfRows()))

8 Replies
Honored Contributor

## Re: How to create subtotals for a calculated dimension?

Hi Dmitry,

In [% of Type] Expression try with this

`=NUM(Sum(Qty) / (IF(ISNULL(AGGR(SUM(Qty),Type)),ABOVE(AGGR(SUM(Qty),Type)),AGGR(SUM(Qty),Type))),'00%')`

Do let me know, if you looking for this one.

Regards,

Sokkorn

Not applicable

## Re: How to create subtotals for a calculated dimension?

Thanks, Sokkorn -- it works exactly as needed.

Not applicable

## Re: How to create subtotals for a calculated dimension?

This solution works well if there are only two values in Group. What about more flexible solution -- when it could be any number of values in group?

Actually what is needed is to aggregate over a calculated dimension.

Message was edited by: Dmitry Gudkov

Contributor

## Re: How to create subtotals for a calculated dimension?

Hi, Dmitry

You can use valuelist('<500','>500') in calculated dimension. And the same in the expression: if(valuelist('<500','>500')='<500',.....)

BR,

Konstantins

Honored Contributor

## Re: How to create subtotals for a calculated dimension?

Hi Dmitry,

Try to load data like this

`[Data1]:LOAD * INLINE [Type,Product,QtyXXX,A,13XXX,A,34XXX,A,123XXX,A,325XXX,B,13XXX,B,34XXX,B,123XXX,B,325XXX,C,34XXX,C,123XXX,C,325XXX,C,453XXX,D,4XXX,D,13XXX,E,325XXX,E,454ZZZ,A,45ZZZ,A,56ZZZ,A,65ZZZ,B,45ZZZ,B,435ZZZ,C,45ZZZ,C,65ZZZ,C,435ZZZ,C,657ZZZ,D,5ZZZ,D,34ZZZ,D,45ZZZ,E,45ZZZ,E,53];[Data2]:LOAD *,IF([TotalQty]>500, '>500',    IF([TotalQty]<=500 AND [TotalQty]>=400,'400-500','<400'))    AS [Range];LOAD    Type &' - '& Product    AS [Key],    SUM(Qty)                AS [TotalQty]RESIDENT [Data1] GROUP BY Type &' - '& Product;`

Then use the second table to do with business need.

This one just an idea to solve your problem. It not reply to your issue yet. So we need to do more on it. Will reply you back when I'm in office.

Hope this help.

Regards,

Sokkorn

Not applicable

## Re: How to create subtotals for a calculated dimension?

Sokkorn,

Thanks for helping me. This sample application is just a representation of the problem. Actual application is much more complex and table data changes dynamically, so additional static data structures barely help here.

Probably I should find a way how to get rid of the calculated dimension, like konstantins advised.

Honored Contributor

## Re: How to create subtotals for a calculated dimension?

Hi Dmitry,

Check my sample attached file.

Regards,

Sokkorn

Not applicable

## Subtotals for a calculated dimension?

OK, here is the answer. Works like a charm with any number of rows in a calculated dimension, and without any additional data structures.

=sum(Qty)/rangesum(top(Sum(Qty),1,NoOfRows()))