Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

sum a value based on finding the most recent date

I have a stock value saved for a number of weeks (aligned in the table with the "week beginning" date). Every week a new value is added with a new date.

I am trying to produce an expression that will always pick the most recent weeks value to display...and this is what I have so far:

=Sum({$<Date={$(=LatestDate)}>}[Value (USD)])

where Latest Date is a variable representing the formula MaxString(Date).

I cannot get this to produce a result even though the variable on its own in a text box returns the latest date OK...

Can somebody please point me in the right direction.

Thanks......

10 Replies
Not applicable
Author

Hi Mike

QlikView has a very handy little function for just your kind of issue.  You have a list that grows each week with a new date and value.  You want to display the most recent value in the list.  Hence, your list will be in date order ascending by default with each 'week commencing' date having a different 'value' as in the table below

Week Commencing     Value

21/07/2013                  10

28/07/2013                  15

04/08/2013                  56

To display your latest value you can use the 'FirstSortedValue' function.  Create a text box and type in:

=Firstsortedvalue(Value,-[Week Commencing])

You will see the value 56 appear in the text box when you reload the application.

If you add another line e.g. 11/08/2013 with a value of 76 then reload your application you will see 76 displayed in the text box.

The function works by taking the first value in a sorted list.  The minus sign tells it to look from the end of the list first hence giving you the most recent entry.

Hope that helps.

Kind regards

Steve