COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: jway on 21 Mar 2018 11:47:33 AM

Title: Expression to return last 6 months
Post by: jway on 21 Mar 2018 11:47:33 AM
I'm having trouble coming up with an expression in a relational report to return the last 6 months' data. So basically the maximum data in the fact table and then the 5 months before.  I have a data item MaxDate that has the most recent month. Then I tried a filter expression:

[Customer Integration].[By Customer Integration Post Date].[Month] >= _add_months([MaxDate], -5)

But that's not appearing to have any effect on the data displayed in the report.  Any ideas on what i can do to get this working?
Title: Re: Expression to return last 6 months
Post by: Cognos_Jan2017 on 21 Mar 2018 12:00:48 PM
Quote[Customer Integration].[By Customer Integration Post Date].[Month] >= _add_months([MaxDate], -5)

Do you have another Field/ Data Item other than '[Month]'?

Something like ...
[Customer Integration].[By Customer Integration Post Date].[DateOfInterest]

HTH, Bob
Title: Re: Expression to return last 6 months
Post by: jway on 21 Mar 2018 12:39:22 PM
We have other fields from the date dimension.  Date, MonthDayYearSlash, ShortMonthYear, etc.  In our dimension Month is in the format  YYYYMMDD, Date is: YYYY-MM-DD, ShortMonthYear is:  MAR 2018
Title: Re: Expression to return last 6 months
Post by: Cognos_Jan2017 on 21 Mar 2018 01:15:37 PM
I have Authored only Relational Data, so we need a Dimension Person to help on this.
Title: Re: Expression to return last 6 months
Post by: jway on 21 Mar 2018 04:23:17 PM
It is a relational package that i'm using on this.
Title: Re: Expression to return last 6 months
Post by: Cognos_Jan2017 on 21 Mar 2018 08:54:56 PM
You said " ... in our dimension Month ...

In my relational App, things like "Date Of Incident' are filtered (like 5 Months worth of data) based on 'Date Of Incident'.  Can you use that technique?
Title: Re: Expression to return last 6 months
Post by: Lynn on 22 Mar 2018 03:23:17 AM
Quote from: Cognos_Jan2017 on 21 Mar 2018 08:54:56 PM
You said " ... in our dimension Month ...

Data warehouses are designed with fact tables and dimension tables. A relational model is often produced over this dimensional data warehouse design. Any of the Ralph Kimball books on data warehousing explain these concepts.

The confusion comes because OLAP and ROLAP models are also referred to as "dimensional".

Quote from: jway on 21 Mar 2018 11:47:33 AM
I'm having trouble coming up with an expression in a relational report to return the last 6 months' data. So basically the maximum data in the fact table and then the 5 months before.  I have a data item MaxDate that has the most recent month. Then I tried a filter expression:

[Customer Integration].[By Customer Integration Post Date].[Month] >= _add_months([MaxDate], -5)

But that's not appearing to have any effect on the data displayed in the report.  Any ideas on what i can do to get this working?

If the filter isn't filtering anything out then the issue could be with the [MaxDate] calculation. What is the expression you are using for that? Is the filter set to before or after auto aggregation? Can you view the tabular data to verify that you have data that should be filtered out?
Title: Re: Expression to return last 6 months
Post by: jway on 22 Mar 2018 03:09:16 PM
My expression for MaxDate is:   maximum([Customer Integration].[By Customer Integration Post Date].[Month])  It's set to Before Autoaggregation.  When i look at the tabular data Month=20161001 and MaxDate=20161001.  Is the problem that these values are not actual dates so the _add_months fails ?
Title: Re: Expression to return last 6 months
Post by: MFGF on 23 Mar 2018 03:55:02 AM
Quote from: jway on 22 Mar 2018 03:09:16 PM
My expression for MaxDate is:   maximum([Customer Integration].[By Customer Integration Post Date].[Month])  It's set to Before Autoaggregation.  When i look at the tabular data Month=20161001 and MaxDate=20161001.  Is the problem that these values are not actual dates so the _add_months fails ?

Hi,

You figured out the issue here - your Month item isn't a Date data type, it's a numeric field. _add_months only works with dates, not with numbers.

Cheers!

MF.
Title: Re: Expression to return last 6 months
Post by: jway on 26 Mar 2018 12:08:50 PM
Changed my MaxDate expression to be:  cast(maximum([Customer Integration].[By Customer Integration Post Date].[Date]),date)

The filter expression is:  [Customer Integration].[By Customer Integration Post Date].[Date] >= _add_months([MaxDate], -6)

But I'm still seeing all the months available in the crosstab, not just the 6 most recent.  I'm not understanding what i've done wrong......
Title: Re: Expression to return last 6 months
Post by: sdf on 03 Aug 2018 01:48:23 PM

why not something like this

[Date] between current_date and _add_months(current_date,-6)