Quantcast
Channel: OBIEE, Endeca and ODI
Viewing all articles
Browse latest Browse all 49

Rolling months using Answers ( without AGO and TIME dimension) : OBIEE

$
0
0
Let say I want to get Previous months value for a measure called sold quantity as shown below (assume you don't have access to RPD and time dimension is not configured)
EmployeeSold Quantity - SeptSold - Quantity - OctSold Qunaity - Aug
A125220524
B291254241
C15045247
We can achieve this using 
  • AGO function Using time hierarchy -- RPD
  • TIMESTAMPADD(SQL_TSI_MONTH) and filter function  --- Answers
what if my Created Month date format is YYYY / MM  : 2013 / 09 ? 
Two ways
1) Creating a repository variable and writing some sql to retrieve value as 2013 / 09 format 
FILTER ( "- Sales Facts"."Sold Quantity" USING "- Created Date"."Created Month" = valueof(previousmonth_sept) ) FILTER ( "- Sales Facts"."Sold Quantity" USING "- Created Date"."Created Month" = valueof(previousmonth_Oct) ) 
but you need to create variables in rpd 
2) when you don't have access to RPD and time dimension is not configured
     a) Extract Last Month using below formula (-1 last month on current date you can change          - 2,-3 to get other month values.....)
(TIMESTAMPADD(SQL_TSI_MONTH, -1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)))
     b) Extract YEAR and MONTH as shown below and contact both to get 2013 / 09 format
(CAST((YEAR(TIMESTAMPADD(SQL_TSI_MONTH, -1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(4)))  || ' / ' ||
CASE WHEN LENGTH(CAST((MONTH(TIMESTAMPADD(SQL_TSI_MONTH, -2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(2)))= 1 THEN  CAST( 0 AS CHAR(1))|| CAST ( (MONTH(TIMESTAMPADD(SQL_TSI_MONTH, -2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(2))
ELSE (CAST((MONTH(TIMESTAMPADD(SQL_TSI_MONTH, -2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(2))) END)
 Pull a dummy column to criteria and in answer Edit the column formula with below formula
FILTER ( "- Sales Facts"."Sold Quantity" USING "- Created Date"."Created Month"= (CAST((YEAR(TIMESTAMPADD(SQL_TSI_MONTH, -1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(4)))  || ' / ' ||CASE WHEN LENGTH(CAST((MONTH(TIMESTAMPADD(SQL_TSI_MONTH, -2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(2)))= 1 THEN  CAST( 0 AS CHAR(1))|| CAST ( (MONTH(TIMESTAMPADD(SQL_TSI_MONTH, -2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(2)) ELSE (CAST((MONTH(TIMESTAMPADD(SQL_TSI_MONTH, -2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(2))) END)
Rolling back based on number you have entered in prompt ?

Create Tex box Type prompt  and assign presentation variable for example 'monthnum' then Fx formula should as shown below
FILTER ( "- Sales Facts"."Sold Quantity" USING "- Created Date"."Created Month"= (CAST((YEAR(TIMESTAMPADD(SQL_TSI_MONTH, -@{monthnum}, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(4)))  || ' / ' ||CASE WHEN LENGTH(CAST((MONTH(TIMESTAMPADD(SQL_TSI_MONTH, -2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(2)))= 1 THEN  CAST( 0 AS CHAR(1))|| CAST ( (MONTH(TIMESTAMPADD(SQL_TSI_MONTH, -2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(2)) ELSE (CAST((MONTH(TIMESTAMPADD(SQL_TSI_MONTH, -2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))))  AS CHAR(2))) END) 
Note : You will see impact on report performance when you use same formula for more than 2 months prefer this option only if you don't have access to RPD and Time dimension is not configured or only for limited months (Previous and Current Month) with different Month Name format . Otherwise AGO function gives better query performance in more efficient way

Viewing all articles
Browse latest Browse all 49