Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How do I calculate the sum of a field depending on the most recent date?

Hi all,

So I am trying to make a bar chart that will show me the total cost by Project Sponsor. The problem is that I want it to only calculate depending on the latest date for that project flash report.

Project NumberNameDateProject Sponsor
1Test 101/02/2014Ben
2Test 201/02/2014Luke
3Test 301/02/2014Luke
4Test 402/02/2014Adam

Project NumberDateCost
103/03/2014100
105/04/2014200
201/03/2014400
209/04/2014150
202/05/2014340
314/03/2014600
320/04/2014700
401/03/2014230
408/04/2014

250

I have something like the above. The two tables are linked by the Project Number. So if I calculate the sum of Cost only with the max date, the results I would expect are: Ben would have a total of 200. Luke would have a total of 1040. And Adam would have a total of 250.

So to make it clear, each person will have a number of projects and the cost changes every month depending on what they spend. So i want to get the total cost for each person. The person being the dimention.

Many thanks,

Bruno

1 Solution

Accepted Solutions
maxgro
MVP
MVP

try with

sum(

     aggr(FirstSortedValue(total <[Project Sponsor], [Project Number]> Cost, -Date),

          [Project Sponsor], [Project Number])

)

View solution in original post

4 Replies
Not applicable
Author

Attached with answer.

Thanks

AJ

maxgro
MVP
MVP

try with

sum(

     aggr(FirstSortedValue(total <[Project Sponsor], [Project Number]> Cost, -Date),

          [Project Sponsor], [Project Number])

)

Not applicable
Author

Your script should be

Load * inline
[
Project Number, Name, Date, Project Sponsor
1, Test 1, 01/02/2014, Ben
2, Test 2, 01/02/2014, Luke
3, Test 3, 01/02/2014, Luke
4, Test 4, 02/02/2014, Adam
]
;

Load * inline
[
Project Number, Date1, Cost
1, 03/03/2014, 100
1, 05/04/2014, 200
2, 01/03/2014, 400
2, 09/04/2014, 150
2, 02/05/2014, 340
3, 14/03/2014, 600
3, 20/04/2014, 700
4, 01/03/2014, 230
4, 08/04/2014, 250
]
;

in Dimension use Project Sponsor

and in Expression use

=sum(aggr(FirstSortedValue(total <[Project Sponsor], [Project Number]> Cost, -Date1), [Project Sponsor], [Project Number]))

you will get

Maxdatesum.PNG.png


Vinay

Not applicable
Author

Thanks guys,

They all work.

=sum(aggr(FirstSortedValue(total <[Project Sponsor], [Project Number]> Cost, -Date1), [Project Sponsor], [Project Number]))

The one above is the one I was looking for, thank you

Kind regards,

Bruno Pereira