I’d like to sum up one of our daily sales objects by month and year, hoping to improve reporting speed.
Found the code for it in another forum for Oracle.
CASE WHEN To_Number ( To_Char (SalesDate, ‘yyyy’)) = To_Number ( To_Char (Sysdate, ‘yyyy’)) THEN SUM(SalesRevenue)
ELSE Sum(0)
Can anyone help me translate this into SQL to create those objects?
Is there a way to calculate month do date and ytd too?
I think as far as oracle is concerned the code you mention will work fine for your object except there is no need to use sum. Just create a measure and then specify sum function for aggregation and BO will handle it.
Regarding MTD and YTD i think this topic has been discuessed before many times. Please do a search on the forum. That will save you some time.
Measures should have SQL aggregation on them. Let your database do the summing and not the reports.
The code given will work, but I prefer it like:
Sum(CASE WHEN To_Number ( To_Char (SalesDate, ‘yyyy’)) = To_Number ( To_Char (Sysdate, ‘yyyy’)) THEN SalesRevenue
ELSE 0
END )
Why use again?
Where are you using SUM twice?
What is the exact SQL code of your measure (defined in the SELECT box of Designer)?
In addition, do refrain from posting the essentially same question twice, Please do not cross-post. It leads to fragmented discussions and is against our forum rules.
This is the SQL I use in the SELECT part of Measure Object properties. User prompts forTrans_Date and on the report I should display MTD, YTD according to thedates passed by the user
MTD:-
SUM
(
CASE WHEN Trans_Date >= trunc(Trans_Date,'mm') AND Trans_Date <= Trans_Date
THEN DECODE (SKU_FLAG, 'ABC', SALE_AMOUNT, BCA', (SALE_AMOUNT)*10), 0)
ELSE 0
END
)
Since it is a Measure Object, Do I need to use SUM again in the SELECT part? In the object properties I am choosing SUM aggregate projection. So, if I use it again in the SQL it would be two times. Isn’t it?