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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
tcarolus
Partner - Contributor III
Partner - Contributor III

Sum(amount) based on max(value)

Hi all,

I'm having trouble figuring the following out.

I have the following situation. Imagine a travel agency with bookings (bookid), different versions per bookid (bookversid), different bookdates per version (bookdate) and different amount per version, amountCY. See table below:

BookId bookversid Bookdate Amount CY
105895105895217-12-20132660,52
105895316-1-20144152,5
105895421-7-20142700

With no selection on bookdate I want to sum the amountCY of the latest bookdate. In this case 2700,-

If my selection on Bookdate is >= 16-1-2014 I want amount CY 2700 as a result.

With a Bookdate >= 17-12-2013, <= 16-1-2014 I want amount CY 4152,50 as a result.


The last thing I tried was:


Max(aggr(Sum(AmountCY),bookversid))


But that does no give me the result I want. With a Bookdate selection of >1-1-2014 this formula returns two rows, 16-1-2014 and 21-7-2014. But I want only the last row.


I hope somebody can help me out here.


Thank you so much in advance!

1 Solution

Accepted Solutions
tcarolus
Partner - Contributor III
Partner - Contributor III
Author

Marcus and sasi thank u so much for sharing your ideas.

I must say my colleague helped me out and he found the solution with the following formula:

Sum(If(Aggr(NODISTINCT Max(bookversid),BookId)=bookversid,AmountCY))

View solution in original post

4 Replies
marcus_sommer

Try it with: firstsortedvalue([Amount CY], -Bookdate). Also the use of the bookversid might be working in this case.

- Marcus

sasikanth
Master
Master

Also try this

=FirstSortedValue(Aggr(sum([Amount CY]),BookId,bookversid) ,-  Aggr(max(Bookdate),BookId,bookversid))

tcarolus
Partner - Contributor III
Partner - Contributor III
Author

Marcus and sasi thank u so much for sharing your ideas.

I must say my colleague helped me out and he found the solution with the following formula:

Sum(If(Aggr(NODISTINCT Max(bookversid),BookId)=bookversid,AmountCY))

soloeeeoff
Contributor III
Contributor III

Hi Tamarah,

Please try this logic.

=Sum( {<Bookdate={'=Bookdate=$(=max(Bookdate))'}>}  [Amount CY])

Thanks.