Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
sheker_amrutham
Contributor II
Contributor II

Max or Min Date issue with Aggr function

Hi,

I have one table with below fields

Inventorytable:

LOAD * Inline [

InvDate, InvQuantity, Price, TotalSales

02-01-2014, 44, 4, 266

03-01-2014, 45, 4, 266

04-01-2015, 46, 4, 266

05-01-2015, 47, 4, 266

06-01-2016, 48, 4, 266

07-01-2016, 11, 4, 266

08-06-2017, 12, 4, 266

09-06-2017, 13, 4, 266

];

I am trying to display Sum(InvQuantity*Price) for Max(InvDate) of each and every Year, but my expression returing worng results.

Aggr(Sum({$<InvDate = {"$(=Date(Max(InvDate)))"}>}InvQuantity*Price),Year)

Please help me in solving this issue.

Please find the attached qvw file for more clarity.

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try like:

Max Date Sales: FirstSortedValue(Aggr(Sum(InvQuantity*Price),InvDate, Year), -InvDate)

Min Date Sales: FirstSortedValue(Aggr(Sum(InvQuantity*Price),InvDate, Year), InvDate)

Capture.PNG

View solution in original post

4 Replies
Anonymous
Not applicable

$(=Date(Max(InvDate))) is dimensionless if you use it like that

tresesco
MVP
MVP

Try like:

Max Date Sales: FirstSortedValue(Aggr(Sum(InvQuantity*Price),InvDate, Year), -InvDate)

Min Date Sales: FirstSortedValue(Aggr(Sum(InvQuantity*Price),InvDate, Year), InvDate)

Capture.PNG

sheker_amrutham
Contributor II
Contributor II
Author

Hi tresesco,

Thank you,

I am using below expression with one change in QlikSense

FirstSortedValue(Aggr(Sum(InvPriceBase*InvQuantity),Date, $(=_RebateTrendDIMField)), -Date)

_RebateTrendDIMField has Year, Quarter, Month loaded in Inline table.

The above expression did not show any value when I did not select any Year or Quarter or Month. If I select Year or Quarter or Month, Its working as Expected.

can you please suggest me.

Thanks,

Chandu

Anonymous
Not applicable

why do you use

$(=_RebateTrendDIMField)) ? as dimension for aggr()?

however, you could try:

FirstSortedValue(distinct Aggr(Sum(InvPriceBase*InvQuantity),Date, $(=_RebateTrendDIMField)), -Date)

if this works, then there's more than 1 firstsortedvalue... but be careful, firstsortedvalue in combination with distinct returns only the first hit...