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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Difference when using Max() or Min()

Hi!

For our sales team I want to display a chart that shows months as dimension and the counts of first as well as last orders of customers as Y-values. So first order means "new customer" and last order shows when the last order of a customer was placed.

Now I figured out how to count the first orders:

=Sum(If(Aggr( Min([Posting Date]), Name) = [Posting Date], 1)) 

Result: 39 New Customers spread across serveral months

But when I try to do the same for last orders by exchanging Min for Max, the result ge

Latest Orders:

=Sum(If(Aggr( Max([Posting Date]), Name) = [Posting Date], 1)) 

Result: Only 12 Last Orders.

Logically thinking, every Cusomer should have a first and a last order. So both values should have the same sum in total.

I just don't get the mistake... 🙂

Thanks a lot in advance!!
Timm

result table (diagram):  

YearMonthlast orderfirst order
1239
20120802
20120913
20121211
20130201
20130402
20130523
20130723
20130801
20130901
20131035
20131201
20140102
20140302
20140503
20140702
20140914
20141001
20141211
20150311
Labels (1)
2 Replies
marcus_sommer
MVP
MVP

I don't think it will be the same result and your expression compared an aggregation directly with a field without aggregation which will be always return NULL if there isn't a unique value. I believe your expression should be more look like this:

=Sum(Aggr(sum({< [Posting Date] = {"$(=Max([Posting Date]))"}>}1), Name, YearMonth))

- Marcus

ramoncova06
Partner - Specialist III
Partner - Specialist III

if I understood right, what you want to do is to get the min and max posting date for each customer, right ?


=Sum(If(Aggr( Max(total <Name>[Posting Date]), Name) = [Posting Date], 1))

=Sum(If(Aggr( Min(total <Name>[Posting Date]), Name) = [Posting Date], 1))