Sum based on chart of Account Name - ssas

I'm trying to create a Report Dimension (Income Statement Report) in my Cube and would like to perform calculation (Sum or Divide) based on Report Action attribute. The Dimension table looks like below
Could you kindly let me know if I could achieve this by MDX script? Thanks a lot for your help!

I tried few things and finally used Scope statement to achieve this. I'm posting my solution here which works across all measures. Please feel free to advise improving the current solution.
// Rporting Option //
Scope ([Reports].[Report Item].Members);
//Total Sales//
IF [Reports].[Report Item].CurrentMember IS [Reports].[Report Item].&[Total Sales] THEN
This = Sum({[Reports].[Sort Key].&[1]:[Reports].[Sort Key].&[2]})
END IF;
//Variable Contribution//
IF [Reports].[Report Item].CurrentMember IS [Reports].[Report Item].&[Variable Contribution] THEN
This = Sum({[Reports].[Sort Key].&[1]:[Reports].[Sort Key].&[3]})
END IF;
//Variable Margin//
IF [Reports].[Report Item].CurrentMember IS [Reports].[Report Item].&[Variable Margin] THEN
This = Divide(Sum({[Reports].[Sort Key].&[1]:[Reports].[Sort Key].&[3]}),Sum([Reports].[Sort Key].&[1]))
END IF;
//Gross Profit//
IF [Reports].[Report Item].CurrentMember IS [Reports].[Report Item].&[Gross Profit] THEN
This = Sum({[Reports].[Sort Key].&[1]:[Reports].[Sort Key].&[4]})
END IF;
// and so on for more for other report totals
END Scope;

Related

IF THEN STATEMENT ORACLE APEX PS/SQL

I am trying to calculate taxes, however, I keep getting an error ORA-06550. Can you please aid me?
How it should to work is
if gross pay is more than 225000 then we divide the gross pay by 3.
if gross pay is less than 225000 then set the value at 75000
This is what I tried so far:
IF nvl(:P37_GROSS_PAY,0) > (225000*nvl:(P37_PERIOD,0)) THEN
{nvl(:P37_GROSS_PAY,0)/3}
ELSE
{75000*nvl(:P37_PERIOD,0)}
END IF;
You have to put the result into something, such as a locally declared variable (and remove curly brackets; they are invalid in this context):
declare
tax number;
begin
if nvl(:P37_GROSS_PAY, 0) > 22500 * nvl(:P37_PERIOD, 0)) then
tax := nvl(:P37_GROSS_PAY, 0) / 3;
else
tax := 75000 * nvl(:P37_PERIOD, 0);
end if;
end;

Toad oracle 10.5 [duplicate]

I have this anonymous PL/SQL block which calculates and prints a value return from a table.
DECLARE
U_ID NUMBER :=39;
RETAIL BINARY_FLOAT:=1;
FLAG NUMBER;
BEGIN
SELECT NVL(RETAIL_AMOUNT,1),UNIT_ID INTO RETAIL, FLAG FROM UNITS WHERE UNIT_ID=U_ID;
LOOP
SELECT NVL(MAX(UNIT_ID),U_ID) INTO FLAG FROM UNITS WHERE FATHER_ID=FLAG;
IF FLAG=U_ID THEN EXIT; END IF;
SELECT RETAIL* RETAIL_AMOUNT INTO RETAIL FROM UNITS WHERE UNIT_ID=FLAG;
EXIT WHEN FLAG=U_ID;
END LOOP;
DBMS_OUTPUT.PUT_LINE( RETAIL);
END;
This block work correctly, but I wanted to do the same thing using a PL/SQL Function
I wrote the function as follow:
CREATE OR REPLACE FUNCTION GET_UNIT_RETAIL(U_ID NUMBER)
RETURN NUMBER
IS
RETAIL BINARY_FLOAT:=1;
FLAG NUMBER;
BEGIN
SELECT NVL(RETAIL_AMOUNT,1),UNIT_ID
INTO RETAIL, FLAG
FROM UNITS
WHERE UNIT_ID=U_ID;
LOOP
SELECT NVL(MAX(UNIT_ID),U_ID)
INTO FLAG
FROM UNITS
WHERE FATHER_ID=FLAG;
IF FLAG=U_ID THEN
EXIT;
END IF;
SELECT RETAIL* RETAIL_AMOUNT
INTO RETAIL
FROM UNITS
WHERE UNIT_ID=FLAG;
EXIT WHEN FLAG=U_ID;
END LOOP;
RETURN NUMBER;
END;
/
When I try to execute the above code to save the function to the database, the environment (SQL*PLUS) hangs for a long time and at the end returns this error:
ERROR at line 1:
ORA-04021: timeout occurred while waiting to lock object
What is the problem ??? Please !
Sounds like ddl_lock problem
Take a look at
dba_ddl_locks to see who is "blocking" a create or replace.
Also try to create under different name - and see what happens.
The problem was because the Object GET_UNIT_RETAIL was busy by other environment
Here is the answer:
https://community.oracle.com/thread/2321256

Suspended account after an order was entered(message error EBS Oracle)

I dont know HOW EBS Oracle is validating this information, i dont know what function or procedure is throwing this error message:
'ONTOE_PC_CREATE_VIOLATIONHeader orderReason Please, contact the
Credit Deparment'
The problem here is that the customer account was shut down after they set an order for him (entered order).
The package involved is this one: OE_PC_CONSTRAINTS_ADMIN_PUB that contains this procedure:
PROCEDURE Set_Message
( p_operation IN VARCHAR2
, p_group_number IN VARCHAR2
, p_attribute_name IN VARCHAR2
, p_object_name IN VARCHAR2
)
IS
l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
BEGIN
IF p_operation = OE_PC_GLOBALS.UPDATE_OP THEN
IF p_attribute_name IS NOT NULL THEN
IF nvl(p_group_number,-1) = -1 THEN
FND_MESSAGE.SET_NAME('ONT','OE_PC_UPDATE_FIELD_NO_CONDN');
ELSE
FND_MESSAGE.SET_NAME('ONT','OE_PC_UPDATE_FIELD_VIOLATION');
END IF;
FND_MESSAGE.SET_TOKEN('ATTRIBUTE',p_attribute_name);
ELSE
IF nvl(p_group_number,-1) = -1 THEN
FND_MESSAGE.SET_NAME('ONT','OE_PC_UPDATE_NO_CONDN');
ELSE
FND_MESSAGE.SET_NAME('ONT','OE_PC_UPDATE_VIOLATION');
END IF;
FND_MESSAGE.SET_TOKEN('OBJECT',p_object_name);
END IF;
ELSIF p_operation = OE_PC_GLOBALS.CREATE_OP THEN
IF nvl(p_group_number,-1) = -1 THEN
FND_MESSAGE.SET_NAME('ONT','OE_PC_CREATE_NO_CONDN');
ELSE
FND_MESSAGE.SET_NAME('ONT','OE_PC_CREATE_VIOLATION');
END IF;
FND_MESSAGE.SET_TOKEN('OBJECT',p_object_name);
ELSIF p_operation = OE_PC_GLOBALS.DELETE_OP THEN
IF nvl(p_group_number,-1) = -1 THEN
FND_MESSAGE.SET_NAME('ONT','OE_PC_DELETE_NO_CONDN');
ELSE
FND_MESSAGE.SET_NAME('ONT','OE_PC_DELETE_VIOLATION');
END IF;
FND_MESSAGE.SET_TOKEN('OBJECT',p_object_name);
ELSIF p_operation = OE_PC_GLOBALS.CANCEL_OP THEN
IF nvl(p_group_number,-1) = -1 THEN
FND_MESSAGE.SET_NAME('ONT','OE_PC_CANCEL_NO_CONDN');
ELSE
FND_MESSAGE.SET_NAME('ONT','OE_PC_CANCEL_VIOLATION');
END IF;
FND_MESSAGE.SET_TOKEN('OBJECT',p_object_name);
ELSIF p_operation = OE_PC_GLOBALS.SPLIT_OP THEN
IF nvl(p_group_number,-1) = -1 THEN
FND_MESSAGE.SET_NAME('ONT','OE_PC_SPLIT_NO_CONDN');
ELSE
FND_MESSAGE.SET_NAME('ONT','OE_PC_SPLIT_VIOLATION');
END IF;
FND_MESSAGE.SET_TOKEN('OBJECT',p_object_name);
END IF;
END Set_Message;
Take a look at this image (i cannot upload images yet):
Image
Could you please explain me HOW this function is called? at what stage? I mean, remember that the order was set and then they suspended the account number.
Also, i was not able to find the other part of the message: "Header orderReason Please, contact the Credit Deparment'". Why? Where is it stored? I think it is a concatenated message
This isn't a programming question, since it has to do with the functionality of the Oracle E-Business Suite. I hope I am not breaking some SO rule by answering.
Your error is coming from a "processing constraint". You can find these defined under the Order Management Super User responsibility, menu Setup->Rules->Security->Processing Constraints. You will find that message you are seeing there as well, as part of the constraint definition.
The constraints defined in that screen are compiled by Oracle EBS into PL/SQL packages named like 'OE_%PC%'. They are called from the Order Management Process Order API -- basically whenever a sales order or RMA is created, updated, deleted, or cancelled in the applications.

Assist with currency format

Good Day please can someone assist me with a currency format of ###,###,###.## everything I try I seem to be getting stuck - My code is as follows:
function CF_TOTAL_COSTFormula return Number is
total_cost number;
begin
select SUM(share_amount) into total_cost
from reservation_name rn,
reservation_daily_element_name rden
where rn.resv_name_id = rden.resv_name_id
and rn.resv_name_id = :resv_name_id
and trunc(rden.reservation_date) between trunc(rn.begin_date) and trunc(rn.end_date - 1);
return total_cost;
exception when others then
return 0;
end;
Your function returns a NUMBER. Numbers in Oracle have no format. If you want to return a formatted number, you need to return a VARCHAR2. Something like this:
function CF_TOTAL_COSTFormula return varchar2 is
total_cost varchar2(30);
begin
select to_char(SUM(share_amount),'999,999,990.00') into total_cost
from reservation_name rn,
reservation_daily_element_name rden
where rn.resv_name_id = rden.resv_name_id
and rn.resv_name_id = :resv_name_id
and trunc(rden.reservation_date) between trunc(rn.begin_date) and trunc(rn.end_date - 1);
return total_cost;
exception when others then
return 'error';
end;
As an aside, I gather from the name of your function that perhaps you are using Oracle Reports or Oracle BI Publisher. If so, you should continue to return a number and handle the display formatting in the layout, not the model.

Visual Fox Pro 6.0 Query of Logical DataType not working!

My current system has a query to generate a tax report. The problem is that sometimes orders go into our system that never get submitted but are still counted in the tax report. The flag that sets an order as submitted is called 'complete' and it will be set to TRUE using the logical datatype.
Two issues arise from the following code. First, it seems as though the field I am using as a constraint 'complete' is a FoxPro reserved function because it lights up in blue while in FoxPro. The second problem is that it will not exclude those records that never get submitted (basically the constraint is not working).
EDITED CODE:
sele bkmast
set order to county
set filt to between(sysdate, m.ld_start, m.ld_end)
go top
m.lh_countylines = ''
select 000000.0000 as ordamt, import, county, 00000000.00 as amount, date() as start, date() as end dist;
from bkmast ;
where !empty(county) ;
.and. alltrim(county) !='0' ;
.and. alltrim(county) !='8.00_Wyoming' ;
.and. alltrim(county) !='Select County' ;
order by county ;
into table countytax
m.ln_total=0
m.ln_countamt = 0
scan
m.lc_county = alltrim(county)
sele bkmast
seek m.lc_county
sum tax to m.ln_amt while county=m.lc_county
seek m.lc_county
sum ordamt to m.ln_ordamt while county=m.lc_county
sele countytax
replace ordamt with m.ln_ordamt
replace amount with m.ln_amt
replace startDate with m.ld_start
replace endDate with m.ld_end
m.ln_countamt = m.ln_countamt + ordamt
m.ln_total = m.ln_total + amount
m.lh_countylines = m.lh_countylines+elemerge(html_frm("TAXCOUNTY1"))
endscan
Any help is greatly appreciated.
Having worked with Foxpro since FoxBase back in '87, I've never known a "complete" command, nor is it directly documented in the VFP Help (yet as stated, DOES highlight in blue as a function call via Complete() ). Additionally the .AND. is long ago old indicator of query. The "End" though IS a keyword. I would try by qualifying the columns by adding the alias to the query and changing End to EndDate (and pairing up Start to StartDate), such as...
From the result of your other comment, I would do your pre-querying directly in the select statement, then do your updates...
SELECT
bk.Import,;
bk.county,;
sum( bk.OrdAmt ) AS OrdAmt,;
sum( bk.Tax ) AS Amount,;
m.ld_Start AS startDate,;
m.ld_End AS endDate;
FROM ;
bkmast bk ;
where ;
sysdate between m.ld_start and m.ld_End;
AND NOT empty( ALLTRIM( bk.county )) ;
AND NOT alltrim( bk.county ) == '0' ;
and NOT alltrim( bk.county ) == '8.00_Wyoming' ;
and NOT alltrim( bk.county ) == 'Select County' ;
AND bk.complete;
group by ;
bk.Import,;
bk.county;
order by;
bk.county ;
into;
table countytax
In this case, since the aggregations of order amount and tax, you don't need to go back to the BKMast table... its already done... you can just cycle through the result set directly. The only thing left would be to sum up the total tax and order amounts... If those variables are not used within your elemerge(html_frm("TAXCOUNTY1")) call, you can just pre-sum those directly
select CountyTax
sum OrdAmt, Amount to m.ln_CountAmt, m.ln_Total
scan
*/ These two already summed up from before the scan loop
** m.ln_countamt = m.ln_countamt + ordamt
** m.ln_total = m.ln_total + amount
*/ Now, continue with the eleMerge() function which will already have the
*/ values in the CountyTax table already summed up
m.lc_county = alltrim(county)
m.lh_countylines = m.lh_countylines+elemerge(html_frm("TAXCOUNTY1"))
endscan
What happens if you run a query where the only this in the WHERE clause is complete:
SELECT ;
000000.0000 OrdAmt,;
bk.Import,;
bk.county,;
00000000.00 Amount,;
date() as startDate,;
date() as endDate;
from bkmast bk;
where bk.Complete ;
into cursor csrTest
Does that get the right set of records? What I'm getting at is that maybe the Complete field doesn't contain what you think it does.
Tamar