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)
Two ways
1) Creating a repository variable and writing some sql to retrieve value as 2013 / 09 format
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.....)
Create Tex box Type prompt and assign presentation variable for example 'monthnum' then Fx formula should as shown below
We can achieve this using
Employee Sold Quantity - Sept Sold - Quantity - Oct Sold Qunaity - Aug A 125 220 524 B 291 254 241 C 150 45 247
- AGO function Using time hierarchy -- RPD
- TIMESTAMPADD(SQL_TSI_MONTH) and filter function --- Answers
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))) || ' / ' ||Pull a dummy column to criteria and in answer Edit the column formula with below formula
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)
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