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

Announcements
Learn how to migrate to Qlik Cloud Analytics™: On-Demand Briefing!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How AGGR is different from TOTAL

Hi All,

How AGGR is different from TOTAL?

Regards,

Raja.

1 Solution

Accepted Solutions
agilos_mla
Partner - Creator III
Partner - Creator III

TOTAL means the expression (Sum, Min) etc. is applied across all the records available to the chart, rather than just those matching the dimensions on this row.  If you include a field in the <...>, then it will create a subtotal for each unique combination of those fields.

AGGR on the other hand creates a mini-chart based on the expr and dimension.  The mini-chart will have one expression (the one defined within the Aggr function) and one or more dimensions based on the fields listed.

Example data may be

CustProd    TransDate     Price

123             1/1/11          100

123             2/1/11          110

123             3/1/11          110

Working from the inside,

Min(TOTAL <CustProd> TransDate).  Fairly easy.  This generates a list of CustProd records and the lowest TransDate for each.  If this was an expression it would return the first transdate for each Customer / Product.  Useful, but we want the price, not the date.

Next step, is to get the Price for the first date.

If(TransDate = Min(TOTAL <CustProd> TransDate),Price)

This will return the Price is the TransDate is the first date for this CustProd record.  Problem is that in the chart, we list all dates, so this only shows the Price on the first record.  We want to see the first price on all records.

To do this, need to apply the first Sum(TOTAL <CustProd> so that it all records for a CustProd can access the first price.  But can't do this without putting in an AGGR function b/w the Sum and the Min.

The AGGR(If(TransDate = Min(TOTAL <CustProd> TransDate),Price),CustProd,TransDate) creates a mini-chart that looks like this:

CustProd    TransDate     Price

123             1/1/11          100

Only the first date is returned as all other dates fail the If(TransDate = Min...) test and so return Null (which is ignored).

What's important is that every record for this CustProd will create the same chart - if it has access to all records of that CustProd - which it does as the first Sum function has TOTAL <CustProd> in it.

The final Sum(TOTAL <CustProd> .... ) simply sums the Price from that MiniChart and works out the first price is always 100.

View solution in original post

4 Replies
Not applicable
Author

AGGR is used in nested functions (like RANK)

It creates a "temp" table dimensionned by the dimensions put in arguments. Then, you use this "temp" table to do sth nested: average, rank ...

sum(TOTAL <xxx> Field) is directly used by the chart and cannot be nested

Fabrice

agilos_mla
Partner - Creator III
Partner - Creator III

TOTAL means the expression (Sum, Min) etc. is applied across all the records available to the chart, rather than just those matching the dimensions on this row.  If you include a field in the <...>, then it will create a subtotal for each unique combination of those fields.

AGGR on the other hand creates a mini-chart based on the expr and dimension.  The mini-chart will have one expression (the one defined within the Aggr function) and one or more dimensions based on the fields listed.

Example data may be

CustProd    TransDate     Price

123             1/1/11          100

123             2/1/11          110

123             3/1/11          110

Working from the inside,

Min(TOTAL <CustProd> TransDate).  Fairly easy.  This generates a list of CustProd records and the lowest TransDate for each.  If this was an expression it would return the first transdate for each Customer / Product.  Useful, but we want the price, not the date.

Next step, is to get the Price for the first date.

If(TransDate = Min(TOTAL <CustProd> TransDate),Price)

This will return the Price is the TransDate is the first date for this CustProd record.  Problem is that in the chart, we list all dates, so this only shows the Price on the first record.  We want to see the first price on all records.

To do this, need to apply the first Sum(TOTAL <CustProd> so that it all records for a CustProd can access the first price.  But can't do this without putting in an AGGR function b/w the Sum and the Min.

The AGGR(If(TransDate = Min(TOTAL <CustProd> TransDate),Price),CustProd,TransDate) creates a mini-chart that looks like this:

CustProd    TransDate     Price

123             1/1/11          100

Only the first date is returned as all other dates fail the If(TransDate = Min...) test and so return Null (which is ignored).

What's important is that every record for this CustProd will create the same chart - if it has access to all records of that CustProd - which it does as the first Sum function has TOTAL <CustProd> in it.

The final Sum(TOTAL <CustProd> .... ) simply sums the Price from that MiniChart and works out the first price is always 100.

Not applicable
Author

hi

suppose you have a table in which fields are

Customer

Region

value

now

Sum(Total value )

then its output is the total of value for all customer

**********************************

sum(aggr(value,customer))

then output is customer  wise value .

Not applicable
Author

Hi,

Thanks to all.

I have small misunderstanding,

In load script,

Cust_DT:

Load  Sum(Sal_AMT)  from <Table_Name>

Group by customer;

Now here, what is difference between into AGGR and Group by <Column Name>.


Regards,

Raja.