Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
MindaugasBacius
Partner - Specialist III
Partner - Specialist III

Aggr or FirstSortedValue

Hello

I need some help.

I need to sum quantity according to the max date in the month:

Screenshot_1.jpg

The result:

Year month, Sum

2017-02, 3

2017-03, 5

Thank you for your help!

1 Solution

Accepted Solutions
sunny_talwar

Try this:

FirstSortedValue(Aggr(Sum(Quantity), Date), -Date)

Capture.PNG

View solution in original post

9 Replies
sunny_talwar

Try this:

FirstSortedValue(Aggr(Sum(Quantity), Date), -Date)

Capture.PNG

aarkay29
Specialist
Specialist

Try this,

Sum (Aggr (Firstsortedvalue (quantity,-Date),Year Month))

MindaugasBacius
Partner - Specialist III
Partner - Specialist III
Author

And how that would work in case we have two dimensions Year month, Product?

sunny_talwar

Difficult to say without looking, but may be this:

FirstSortedValue(Aggr(Sum(Quantity), Product, Date), -Aggr(Date, Product, Date))

MindaugasBacius
Partner - Specialist III
Partner - Specialist III
Author

Thanks once again!

Not applicable

Hi Sunny,

many thanks for your suggestion: it works very well! Instead, I have a problem when I try to apply the expression to calculate the previous year value.

In fact, it seems that the function FirstSortedValue is not able to consider a set analysis expression:

=sum(aggr(FirstSortedValue({<Date={'<=$(=max(Date)-100)>=$(=min(Date)-100)'}>}aggr(Costs,Project,Date),-aggr(Date,Project,Date)),Project))

 

The date format is YYYYMM (i.e. 201701)

Am I wrong? How can I manage this issue?

Best,

Matteo

sunny_talwar

Not entirely sure, but try this

=Sum({<Date = {"$(='<=' & Date(Max(Date)-100, 'YYYYMM') & '>=' & Date(Min(Date)-100, 'YYYYMM'))"}>} Aggr(FirstSortedValue({<Date = {"$(='<=' & Date(Max(Date)-100, 'YYYYMM') & '>=' & Date(Min(Date)-100, 'YYYYMM'))"}>} Aggr(Only({<Date = {"$(='<=' & Date(Max(Date)-100, 'YYYYMM') & '>=' & Date(Min(Date)-100, 'YYYYMM'))"}>} Costs), Project, Date), -Aggr(Only({<Date = {"$(='<=' & Date(Max(Date)-100, 'YYYYMM') & '>=' & Date(Min(Date)-100, 'YYYYMM'))"}>} Date), Project, Date)), Project))

Not applicable

Hi Sunny,

I implemented this formula because yours seems not to work in my dashboard:

=sum(aggr(FirstSortedValue({<Date={'<=$(=max(Date)-100)>=$(=min(Date)-100)'}>}aggr(only({<Date={'<=$(=max(Date)-100)>=$(=min(Date)-100)'}>} Costs),Project,Date),-aggr(only({<Date={'<=$(=max(Date)-100)>=$(=min(Date)-100)'}>}Date),Project,Date)),Project))

This one is fine on a local test qvw with a limited amount of data.

My current problem is to insert into this expression the sum function regarding Costs while keeping the set analysis for the previous year.

Do you have any idea on that?

Many thanks

writetoprithvi
Contributor II
Contributor II

Hi Sunny,

I need to calculate as of date figure for respective years and for previous years. For current years, the formula below is working:

FirstSortedValue(Aggr(Sum([Amount]), [Period]), -Aggr([Period], [Period]))

But I am struggling to calculate prior year figures using same. I have already tried for a week now but with no success. Can you help?

Let me know if more information is required.

Thanks