Monday, March 26, 2012
Member function error
I am trying to complete a tutorial for my Database class and have come across an error which I can't get around. I enter the following code which seems to work:
ALTER TYPE student_type REPLACE AS OBJECT
(FirstName varchar2(15),
LastName varchar2(15),
Address address_type,
Contact contact_type,
DateOfBirth date,
Nationality varchar2(15),
AttendanceMode varchar2(15),
StudentNo varchar2(15),
Userid varchar(15),
FeeStatus varchar2(25),
MEMBER FUNCTION getName RETURN varchar2,
PRAGMA RESTRICT_REFERENCES (getName, WNDS, WNPS, RNDS, RNPS)
)
/
It produces the result "Type altered."
Then I enter the following code to implement my member function:
CREATE TYPE BODY student_type IS
MEMBER FUNCTION getName RETURN VARCHAR2 IS
BEGIN
RETURN (FirstName || '' || LastName);
END;
/
(not sure if I should have the "/" at the end but thats the only way I can get it to run)
and I recieve the following error message:
CREATE TYPE BODY student_type IS
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
I know I already have an object type named student_type but have been given the code to implement my member function by my teacher and assumed it would work.
Any suggestions?
Thanks in advance.
JamesYou should use
CREATE OR REPLACE TYPE BODY.....
INSTEAD OF JUST
CREATE TYPE BODY|||HI,
Enter a unique name for the database object type or modify or drop the existing object so it can be reused.
Monday, March 12, 2012
MDX to aggregate measure over specific dimensions
I'm trying to write a calculated member in SSAS 2005 that will only aggregate across certain dimensions. For example, say I have five dimensions: D1 - 5. I only want the member to aggregate across three of these dimensions. So in the cube browser, when I drag these three dimensions in, I get the correct aggregated value. But when I then drag dimensions four and five in, I want this value to stay the same. (The measure is currently in a measure group that uses all five dimensions).
I was thinking that the solution would be to have an MDX expression of the form
([Measures].[Measure],
[D1].CurrentMember,
[D2].CurrentMember,
[D3].CurrentMember,
[D4].[(All)],
[D5].[(All)])
but I would prefer not to have to list all dimensions and their hierarchies, and have to remember to add to this list if I add a dimension in the future. In SSAS 2000 I had a lookup cube that only contained the dimensions I wanted to slice by.
My other solution was to create a named query on the fact table that this measure is currently in, create a measure group on that, and then set up the dimension usage so that only the dimensions I want to slice by are referenced. However, I'm thinking that there must be a better solution, probably using some MDX that I don't know about!
Thanks in advance.
James
Take a look at the MDX Root function. Here's an example of something that might work for you using Adventure Works:
with member measures.rootdemo as (
root([Date].[Calendar Year].currentmember),
root([Product].[Category].currentmember),
root([Customer]),
[Measures].[Internet Sales Amount]
)
select
[Date].[Calendar Year].[Calendar Year].members
*
[Date].[Calendar Semester of Year].[Calendar Semester of Year].members
*
[Customer].[Country].[Country].members
on 0,
[Product].[Category].[Category].members
on 1
from [Adventure Works]
where(measures.rootdemo)
You still need to list all the dimensions but at least you don't need to list the hierarchies. Watch out for this 'feature' of the function, though, which occurs when more than one member from a hierarchy is in scope:
with member measures.rootdemo as (
root([Date].[Calendar Year].currentmember),
root([Product].[Category].currentmember),
root([Customer]),
[Measures].[Internet Sales Amount]
)
select
[Date].[Calendar Year].[Calendar Year].members
*
[Date].[Calendar Semester of Year].[Calendar Semester of Year].members
on 0,
[Product].[Category].[Category].members
on 1
from [Adventure Works]
where(measures.rootdemo,{[Customer].[Country].&[Australia],[Customer].[Country].&[United Kingdom]})
HTH,
Chris
|||Hi Chris, many thanks for your reply.
This indeed worked. Going back to my previous example, I created a calculated member as:
(Root([D4]),
Root([D5]),
[Measures].[Measure])
and the measure is only sliced by dimensions D1, D2 and D3.
Thanks for your help!
James
|||
Another approach to this problem is to put these measures into dedicated measure group which excludes dimensions D4 and D5 - then you will get the aggregates you need without calculated members. Of course, if you sometimes do need detailed information over them, then the approach with calculated member is the right one.
One more note - you don't have to use Root() function if all the attributes in your dimensions are aggregatable. You will get better performance if you simply use
([D4].[All], [D5].[All], [Measures].[Measure])
|||Hi, yes I thought those were my two options.
I don't want to create another measure group as I'll have duplicate measures and the table with this measure in is large (it's a requirement in our system to keep processing time to a minimum). I was hoping that there would be a solution where I didn't have to list every dimension I wanted to remove from the slice (and remember to add to the list if I add dimensions in the future), but at least I have a solution!
Many thanks for your help.
James
MDX Sum distinct across specific dimensions
I have a measure group that has a few measures that are not addittive across all dimensions. I need to be able to get the sum distinct across specific dimensions and am having problems getting it to work. I tried specifying that the aggregate function should be semiaddittive, but it complains that it is missing a time dimension. I have tried many variations and combinations of MDX functions including sum, aggregate, crossjoin, filter, distinct, etc. but am struggling with the right combination.
Here is a simplified example of what I am trying to do:
GroupID Title Role ConditionCount
11682 Director Operations Licensing Manager 2
11683 Director Operations Licensing Manager 3
11683 Director Operations Product Manager 3
When I group on role I need to see this:
Licensing Manager 5
Production Manager 3
When I group on Title, I need to see this:
Director Operations 5
Basically I want to do a sum distinct for the GroupID. I only want to add the ConditionCount once for each distinct GroupID since the value will be the same for all instances of an individual groupID. Is there a way to do this in MDX?
Thanks in advance for your suggestions!
Clayton
Could you create another fact table and measure group for ConditionCount? For example, if the original fact table has the fields above, a named query could be created like:
select GroupID, Avg(ConditionCount) as ConditionCount from OriginalFact group by GroupID
Then, a "sum" [Measure].[ConditionCount] measure created on this measure group, which only relates to the Group dimension, would work as above.
|||I don't quite understand your suggestion. I do have a table where GroupID is the primary key, but I can't figure out how to get it to count values once for each distinct iteration of Group ID. The rollups and sum distincts across specific dimensions works with Oracle analytic functions, but I can't figure out how to get it to work with MDX. Thanks for your response.|||Here's a more detailed description of the suggested model, which uses many-many dimensions:
Suppose this is the "TitleRole" fact table and measure group, with dimensions Group, Title and Role:
GroupID Title Role ConditionCount
11682 Director Operations Licensing Manager 2
11683 Director Operations Licensing Manager 3
11683 Director Operations Product Manager 3
There is a 2nd "Group" fact table and measure group (as suggested above), with [ConditionCount] "sum" measure - this could be the Group dimension table:
GroupID ConditionCount
11682 2
11683 3
This measure group relates directly to the "Group" dimension, but has a many-many relation with the Title and Role dimensions, via the intermediate "TitleRole" measure group. Now, if the Title: "Director Operations" is selected, [Measures].[ConditionCount] in the "Group" measure group should be 5. And if the Role: "Product Manager" is selected, [Measures].[ConditionCount] in the "Group" measure group should be 3.
|||Ah. I understand now. Let me give that I try when I get back to it in a few days and I'll respond. I already have that table set up in the data warehouse, but didn't think about trying a many-to-many relationship. Thanks again!Friday, March 9, 2012
MDX range not working
SELECT {[Measures].[0CS_TRN_LC], [Measures].[0CS_TRN_QTY]
} ON COLUMNS, NON EMPTY {CROSSJOIN(
{
[ZCS_UNIT].[DPCO991-CONSCORR]:[ZCS_UNIT].[DPCO991-99001000]
},
[0CS_ITEM].[All]:[0CS_ITEM].
)}
If the first entry in ZCS_UNIT is valid and contains data in it, my mdx statement retrieves the data accordingly. However, if the first entry is valid and does not contain any data, I do not retrieve any data at all (even if the other cons unit in the range contain data) ! Since the users put in the range of cons unit in the selection screen, there is no way to validate if the first cons unit has data or not. I tried removing the "NON EMPTY" before cross join but nothing changed.
Seems that the first entry is critical, as it has to be both valid and contains data for me to be able to retrieve anything.
This is my first MDX report (no formal training), I am writing this report for the BW system in SAP.
Is this an MDX/SAP bug, or is there something wrong with my MDX statement contruction?
Thanks.
I would advise asking your question in the SQL Server Analysis Services forum: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=83&SiteID=1 as this specific forum is targeted at reporting in the context of Team Foundation Server
Thanks,
Othmane
Saturday, February 25, 2012
MDX Query designer working correctly?
I can build a report using the wizzard, preview it, deploy it, and all is good with the world. But if I so much as click on the Data tab in the report designer, the report becomes invalid.
Is this by design, or is there some other way to edit a report created with the MDX query designer?
Regards,
Clayton
This is known issue in Report Designer.
Here is workaround:
1. After the report wizard completes, close the report.
2. Open the report in code view
3. Edit the report removing all carriage returns and all whitespace (blanks) between the two tags
<rd:MdxQuery> and <QueryDefinition>
4. Save the report and close the window
5. Open the report in Design Mode.
MDX query designer behaving correctly in Reporting Services?
I can build a report using the wizzard, preview it, deploy it, and all is good with the world. But if I so much as click on the Data tab in the report designer, the report becomes invalid.
Is this by design, or is there some other way to edit a report created with the MDX query designer?
Regards,
Clayton
This is apparently a known problem. I posted this to the Reporting Services forum as well and recieved an answer there. Heres the link:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=171034&SiteID=1
Regards,
Clayton