Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Aggregate Function Help!

Hi,

I am having a problem with aggregate function which I thought I knew how it works but now I am just confused.

Scenario:

I have a set of data that looks like the image below, what I am trying to do now is to have a chart that shows the sum(Amount) of the last month of each year, therefore, the desired result should should be:

2012 : 30

2013 : 50


I have tried the expression below which I thought aggregate function should return me with the latest month of each year but it didn't give me the desired result but just empty cells :

sum({<Date={"$(=aggr(max(Date),Year))"}>} Amount)

Data.JPG.jpg


I have attached the test application that contain the data for this scenario, appreciate if anyone can help. Thank you.


Regards.


1 Solution

Accepted Solutions
tresesco
MVP
MVP

Use:

=FirstSortedValue( AGGR(Sum(Amount),Date), -AGGR(Date,Date))

PFA

View solution in original post

4 Replies
tresesco
MVP
MVP

Use:

=FirstSortedValue( AGGR(Sum(Amount),Date), -AGGR(Date,Date))

PFA

Anonymous
Not applicable
Author

Hi,

see below scipt

hi see the below script,

tt:

LOAD year,

     yearmonth,

     amount

     

    

FROM

xyz.xls;

Left join

load

year,

max(yearmonth) as maxdates

resident tt group by  year;

load

year,

if(yearmonth= maxdates,'y','n') as flag,

amount

resident tt;

drop Table tt;

now use    =sum({<flag={'y'}>}amount) in your chart

anant

sudeep_d
Partner - Creator
Partner - Creator

Hi ,

Create a variable

maxmnth=month(max(Date))

then the expression wud be

sum(if(month(Date)=maxmnth,Amount))..

See the attached file.

Cheers!!!

Anonymous
Not applicable
Author

Thank you Tresesco, it solved my problem!