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

Need to get the most recent value based on a range of dates defined in a set analysis expression

Is it possible to write an expression that returns/calculates the most recent available value based on a range of dates defined in a set analysis expression?

For example, if I have just two hospitals in a particular region and select April 2010 from my data island, the YTD licensed bed calculation based on the data below should return 140 for the region. (60 for Hospital1-March and 80 for Hospital2-April).

AsOfDateNum of Licensed Beds
Hospital101/31/201052
02/28/201052
03/31/201060
Hospital 201/31/201074
02/28/201074
03/31/201074
04/30/201080
05/31/201091


Here is the set analysis expression I am using for several other YTD calculations... {$<AsOfDate = {">=$(vCalCYrStart)<=$(vCalCMthEnd)"}>} where the variables vCalCYrStart and vCalCMthEnd are dynamically set based on a single selection from the data island.

Thank you in advance for any ideas or help you might be able to provide!

2 Replies
pover
Partner - Master
Partner - Master

Try a nested set analysis expression

{$<AsOfDate={'date(max({$<AsOfDate = {">=$(vCalCYrStart)<=$(vCalCMthEnd)"}>} AsOfDate))'}>}

Regards.

Not applicable
Author

Thank you for the quick response. I had to add an aggr to the formula to return the max available date by hospital and have part of it working at the moment. I must be missing some punctuation though because when I add the results of the nested max date expression to the outer set analysis expression, it returns zeros. I need to set this aside for the moment but will send an update if/when I get this working. Thanks again!