COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: rsfall on 09 Mar 2015 05:11:32 PM

Title: Retrieve value based on Max date where max date is <= Prompt Date
Post by: rsfall on 09 Mar 2015 05:11:32 PM
Need to retrieve a value based on the newest date (max).   The max date has to be less than or equal to Prompt Date.  I can get the max date and the value associated with it, but can't seem to get the max date less than or equal to prompt date condition to work. In the example below , am getting value 30, instead of 10.
Syntax to accomplish this within a report studio query / filter would be much appreciated.

Date          value     Prompt Date
----------    ------     -------------
01/01/15    10         01/15/15
02/01/15    20
03/01/15    30

Title: Re: Retrieve value based on Max date where max date is <= Prompt Date
Post by: MFGF on 10 Mar 2015 06:10:21 AM
Quote from: rsfall on 09 Mar 2015 05:11:32 PM
Need to retrieve a value based on the newest date (max).   The max date has to be less than or equal to Prompt Date.  I can get the max date and the value associated with it, but can't seem to get the max date less than or equal to prompt date condition to work. In the example below , am getting value 30, instead of 10.
Syntax to accomplish this within a report studio query / filter would be much appreciated.

Date          value     Prompt Date
----------    ------     -------------
01/01/15    10         01/15/15
02/01/15    20
03/01/15    30

Hi,

I do have an approach you might try, but it's not very efficient.

1. Bring in the date and sort it descending.
2. Add a query calculation using running-count() summary based on the date item - ie running-count([your date item])
3. Filter your report based on your date parameter from the prompt - ie [your date item] <= ?Your date param? - set the timing of this to "Before auto aggregation"
4. Filter your report based on the running count - ie [your running count calculation] = 1 - set the timing of this to "After auto aggregation"

Cheers!

MF.
Title: Re: Retrieve value based on Max date where max date is <= Prompt Date
Post by: bdbits on 10 Mar 2015 08:59:21 AM
Relational or dimensional? If relational, what database? If I understand you correctly, there are expressions to get you what you want, but the data source matters.
Title: Re: Retrieve value based on Max date where max date is <= Prompt Date
Post by: rsfall on 10 Mar 2015 11:16:55 AM
It's relational.   Database is Oracle.