Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to calculate Inventory of max date

Hi all,

     I have a table like this:

Month     Date     Inv

1            25        101

1            27         99

1            29         78

2            6           19

2           10          6

2            21         10

I want to calculate the Inv of the Max date in each month. The result table i want is like this :

Month            Inventory

1                    78

2                    10

78 is the inventory of 1-29 and 10 is the inventoy of 2-21.

Pls help me, thanks.

zhou

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi,

Use this expression

=Sum(Aggr(If(Dt =Date(Max(TOTAL<Month> Dt)), Sum(Inv)), Dt, Month))

Regards,

Jagan.

View solution in original post

9 Replies
Not applicable
Author

My qvw file ple see the attachment.

Sokkorn
Master
Master

Hi Zhou,

Create new expression with FirstSortedValue(Inv, -Dt)

Regards,

Sokkorn

Not applicable
Author

I worked only when there is 1 records of the max date.

Sokkorn
Master
Master

Zhou,

What is the issue you face right now? I totally don't understand your reply above.

Regards,

Sokkorn

Not applicable
Author

What i mean is : If there are two records at date 1-29, then your expression 'firstsortedvalue(Inv,-Dt)' will return 'Null'.

You can refer my qvw file in the attachment.

Thanks.

Anonymous
Not applicable
Author

In the script:

     If(Month <> Peek(Month,-1),Inv,'') as MaxInv

Warning: There is probably a better solution.

jagan
Luminary Alumni
Luminary Alumni

Hi,

Use this expression

=Sum(Aggr(If(Dt =Date(Max(TOTAL<Month> Dt)), Sum(Inv)), Dt, Month))

Regards,

Jagan.

Not applicable
Author

Find the

Hi,

Use this

FirstSortedValue(aggr(max(Inv),Dt),Dt)

If duplicate values, it will return max,

If need min value USe

FirstSortedValue(aggr(min(Inv),Dt),Dt)


Find the attached file.

Not applicable
Author


You are right!  You solved my problem. Thank you!