Hi All,
I am trying to set up a Filter for rolling 12 months Data. However I can’t find a proper calendar Date object in the universe.
What I have is a Year numeric field and a Month Numeric field. I concatenated them to make a “yyyymm” field but it is not a solution.
The Year data is :
Year
2012
2013
2104
Month
01
02
03
04
to
12
Is there a way to use these 2 numeric fields to create a Date object by which I can filter for last 12 months Data?
I need Data monthly wise.so each time Report runs, we want to see the previous 12 months,
Need Help!!
I hope you are using Oracle database. Syntax may change based on your database.
create a filter condition in the designer/IDT with the below formula.
=to_number(<Year_month_concat_Object>)
between
concat ( extract(year from add_months(sysdate,-12)),extract(month from add_months(sysdate,-12)))
and
concat ( extract(year from sysdate),extract(month from sysdate))
Thanks for your help Reddy,
I tried your formula but in IDT, it is giving error. Seems like extract(year from …is not supported. Its giving error.
I am looking for an alternative way to extract year and month from Sysdate.
I am not sure how trunk(sysdate) will work, any ideas??
Thanks for help!!
Now the formula is working using the same one given by Reddy, however, it is returning year and month from 201401 to 201412.
Here is filter object sql seen in webi:
( ( YEAR||MONTH )
between
concat(extract(year from add_months(sysdate,-12)) ,extract(month from add_months(sysdate,-12)))
and
concat(extract(year from add_months(sysdate,-1)) ,extract(month from add_months(sysdate,-1)))
)
The result is coming as 2014 with all months. Nothing from 2013. Need help on this, thanks.
( ( YEAR||MONTH )
between
concat(extract(year from add_months(sysdate,-12)) ,extract(month from add_months(sysdate,-1)))
and
concat(extract(year from add_months(sysdate,-1)) ,extract(month from add_months(sysdate,-1)))
Hang on, think I’ve figured something out. Don’t usually need to use extract but I think there was a flaw in that logic anyway.
Try this instead:
( ( YEAR||MONTH )
between
concat(extract(year from add_months(sysdate,-13)) ,extract(month from add_months(sysdate,-13)))
and
concat(extract(year from add_months(sysdate,-1)) ,extract(month from add_months(sysdate,-1)))
)
Essentially it’s the year month from 13 months ago to the year month from last month, which I believe is what you want
Thanks,
I’ve tried again and it is giving same result.
It shows:
2014 01
2014 02
until
2014 12
I noticed that even if I make the syntax add_months (sysdate,-15), it still gives only 12 rows back with the year 2014.
So I think it is reading the 12 unique values in the month object and returning them.
The webi sql is given here:
SELECT
Table.YEAR,
Table.MONTH
FROM
Table
WHERE
( ( Table.YEAR||Table.MONTH )
between
concat(extract(year from add_months(sysdate,-13)) ,extract(month from add_months(sysdate,-13)))
and
concat(extract(year from add_months(sysdate,-1)) ,extract(month from add_months(sysdate,-1)))
)
I have given up and resorted to using one of the Date fields in the table, although it is not best choice but going with it, using following syntax:
table.Date between trunc(add_months(sysdate,-12),'MM') AND last_day(trunc(sysdate,'MM')-1)