Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
buc_christian
Partner - Contributor III
Partner - Contributor III

Addieren von zwei "aggr" Funktionen

Hallo Community,

ich habe eine Frage zu dem addieren von zwei "aggr" Funktionen.

Beispiel:

x-Achse = Zeit

Y-Achse = €

erste Linie: Hier aggregiere (mit der "aggr" Funktion) ich den Umsatz nach Produktgruppe über die Zeit. Wird ein Produkt in einer (z.B.) Kalenderwoche nicht verkauft, entsteht hier auch kein Umsatz.

zweite Linie: Hier aggregiere (ebenfalls mit der "aggr" Funktion) ich Kosten ebenfalls nach Produktgruppe über die Wochen.

Anmerkung: Es können nun aber auch Kosten in Wochen entstehen in denen kein Umsatz gemacht wird und umgekehrt.

dritte Linie: Hier möchte ich jetzt die Summe aus Linie 1 und 2 bilden. wenn ich die beiden Formeln einfach zusammenfüge: aggr(...) - aggr (...), dann funktioniert dies für die Wochen in denen es sowohl Umsatz als auch Kosten gibt.

Habe ich allerdings Wochen, in denen nur Umsatz oder Kosten vorhanden sind, zeigt die 3. Linie null an, was aber nicht stimmt.

Nun meine Frage: Warum macht QV das und wie kann ich es "richtig" machen?

Lieben Dank schon mal für Eure Hilfe,

Chris

1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

Conditional aggregations is not a problem. There are several ways:

You can do it through

     Sum( If( <condition> , Amount1, Amount2 ) )

which would evaluate the condition once per row in the data table. Or you can do a

     If( <condition> , Sum(Amount1), Sum(Amount2) )

which would evaluate the condition once per dimensional value (Month/Day/Minute/etc) on your x-axis.

Or you can have an expression with Set Analysis - which basically is a selection in the formula:

     Sum( {$<Product={'A','B'}>} Amount )

All the Aggr() function does, is to create an additional For-Next loop inside each dimensional value of your chart (Month/Day/etc.). So I don't think that the Aggr() function is necessary. See more here: http://community.qlik.com/blogs/qlikviewdesignblog/2013/03/11/when-should-the-aggr-function-not-be-u...

HIC

View solution in original post

4 Replies
hic
Former Employee
Former Employee

The Aggr() is not an aggregation function. Instead, it returns an n-tuple of values - one aggregation per distinct value of the second parameter. So, you cannot really use an Aggr() function without wrapping it in an aggregation function, e.g. Sum().

Further, I don't think you need the Aggr() function - you only need this for nested aggregations. If you use the following expressions, it will probably work straight away:

First line: Sum(Verkauf) 

2nd line: Sum(Kosten)

3rd line; Sum(Verkauf) - Sum(Kosten)

HIC

buc_christian
Partner - Contributor III
Partner - Contributor III
Author

Hi Henric,

thanks for your answer.

I think maybe i have state my question to generally. In fact simple SUM functions do not work for my Problem, since i have some extra Parameters and my aggr function looks like:

aggr(if(... and(...), sum(...)), Parameter, parameter, ...)

so the easy way unfortunatelly doesnt work for me here...
(i think). In Excel i might work with the sumifs() Funktion, ... not sure if that would work, but i think thats not a way in Qlikview....

maybe you have some other idea??

Thanks a lot in advance...

Chris

hic
Former Employee
Former Employee

Conditional aggregations is not a problem. There are several ways:

You can do it through

     Sum( If( <condition> , Amount1, Amount2 ) )

which would evaluate the condition once per row in the data table. Or you can do a

     If( <condition> , Sum(Amount1), Sum(Amount2) )

which would evaluate the condition once per dimensional value (Month/Day/Minute/etc) on your x-axis.

Or you can have an expression with Set Analysis - which basically is a selection in the formula:

     Sum( {$<Product={'A','B'}>} Amount )

All the Aggr() function does, is to create an additional For-Next loop inside each dimensional value of your chart (Month/Day/etc.). So I don't think that the Aggr() function is necessary. See more here: http://community.qlik.com/blogs/qlikviewdesignblog/2013/03/11/when-should-the-aggr-function-not-be-u...

HIC

buc_christian
Partner - Contributor III
Partner - Contributor III
Author

Hi Henric,

you opened up my eyes

that works now way better than with the aggr function. I m gonna try to use that on some other crazy formulas i made in other occasions...

THANKS.

Chris