Using Rank function in mdx
I have the following data in my cube
Prod ID Account ID Measure
1 10 20
2 10 20
2 20 10
Now I want an mdx query which would show an aggregation against the Account ID 10 as 20 only and not 40 as the Account ID is the same which means the desired output has to be something like
Account ID Measure
10 20
20 10
Note that Prod ID and Account ID are from different Dimensions.
Please let me know how do I do this in MDX. Any help is greatly appreciated!!
Hi N
Another option is to use the Generate function and just take the last Prod Id for each Account. Your MDX will look something like
select non empty
{[Measures].[MyMeasure]
} on 0,
non empty
generate([Account ID].[Account ID].[Account ID].members
,tail(nonempty([Prod ID].Prod ID].Prod ID]*[Account ID].[Account ID].currentmember,[Measures].[MyMeasure]),1))
on 1
from MyCube
Richard
Similar Messages
-
How to use "Rank" function in Oracle?
I need to display Top 15 records by using rank function.
Here is my query...I need to pull top 15 FAQ's using the below query.. How can I use RANK function to display the Top 15 FAQ"s in the list.
Select distinct SUb1.FAQ,Sub1.FAQ_Hits,GU.display_Name_FMLS as displayname,ev.ParentLinkrecordid,ev.userid from User GU
Join Event ev
ON LOWER (ev.userid) IN (LOWER (GU.lanid), LOWER (Gu.racfid))
Join (Select distinct sm.stem as FAQ,Sum(ev.Eventresults) as FAQ_Hits,ev.ParentLinkrecordid as Topic_ID from Event ev
Join SubjectMatter sm
ON (TO_CHAR (sm.smrecordid) = ev.eventdetail1) AND ev.eventdetail1 IS NOT NULL AND sm.smtype = 1
Where (Upper(ev.eventsubtype) in (Upper('FAQ'),Upper('OPENFAQ')))
AND TO_DATE (eventdatetime, 'yyyy-mm-dd hh24:mi:ss') >= TO_DATE ('20100601', 'yyyymmdd')
and TO_DATE (eventdatetime, 'yyyy-mm-dd hh24:mi:ss') <= TO_DATE ('20100831', 'yyyymmdd')
Group by sm.stem,ev.Parentlinkrecordid
order by FAQ )sub1
ON Sub1.Topic_ID = ev.ParentLinkrecordid)A few bits that I noticed in the query ...
in (Upper('FAQ'),Upper('OPENFAQ'))1) Do you really a upper for a string which is already in upper case.
Select distinct sm.stem as FAQ,Sum(ev.Eventresults) as FAQ_Hits,ev.ParentLinkrecordid as Topic_ID2) Do you need a distinct when you are using a GROUP function viz. SUM ?
You rank query is as follows, I am not very good at the ANSI style JOIN so changed it slightly ... :-)
Also notice the usage rank function in the "sub1" query.
select distinct sub1.faq,
sub1.faq_hits,
gu.display_name_fmls as displayname,
ev.parentlinkrecordid,
ev.userid
from user gu, event ev,
(select rank() over (order by sum(ev.eventresults) desc) rnk,
sum(ev.eventresults) as faq_hits,
sm.stem as faq,
ev.parentlinkrecordid as topic_id
from event ev, subjectmatter sm
where (to_char(sm.smrecordid) = ev.eventdetail1)
and ev.eventdetail1 is not null
and sm.smtype = 1
AND upper(ev.eventsubtype) in ('FAQ', 'OPENFAQ')
and to_date(eventdatetime, 'yyyy-mm-dd hh24:mi:ss') >= to_date('20100601', 'yyyymmdd')
and to_date(eventdatetime, 'yyyy-mm-dd hh24:mi:ss') <= to_date('20100831', 'yyyymmdd')
group by sm.stem, ev.parentlinkrecordid
order by faq) sub1
where lower(ev.userid) in (lower(gu.lanid), lower(gu.racfid))
and sub1.topic_id = ev.parentlinkrecordid)
and sub1.rnk <= 15;Like mentioned above, some sample data would have helped. -
Sql tuning using rank function
Hi,
Can someone help me in writing the below qry using rank() function?
DELETE FROM stc_calllog_ext a
WHERE a.stc_save_status = 'CT'
AND ROWID IN (SELECT a.ROWID
FROM stc_calllog_ext a, calllog_ext b
WHERE a.prod_line_code= b.prod_line_code
AND a.brand_code = b.brand_code
AND a.model_number = b.model_number
AND a.stc_save_status != b.stc_save_status
AND trunc(a.stc_start_time) = trunc(b.stc_start_time)
AND a.stc_start_time BETWEEN TRUNC(SYSDATE-8) AND TRUNC(SYSDATE)
AND a.call_taker_userid = b.call_taker_userid
AND a.cons_telephone_no =b.cons_telephone_no
)With the information you have provided, I've come up with the following.
SELECT A.ACCOUNT_NO, A.PAYMENT_TYPE, A.INSTALLMENT_TYPE, A.DATE_CHANGE
FROM
(SELECT account_no, payment_type, installment_type, date_change,
LEAD( (payment_type), 1)
over (partition by account_no order by account_no, DATE_CHANGE) LEAD_PAY,
LEAD( (installment_type), 1)
over (partition by account_no order by account_no, DATE_CHANGE) LEAD_INST
from T_ACCNTS ) A
WHERE A.PAYMENT_TYPE <> NVL(A.LEAD_PAY,99)
OR A.INSTALLMENT_TYPE <> NVL(A.LEAD_INST,99)
ORDER BY 1, 4; -
Error using Rank function in Answers
Hi All,
Am trying to generate a report in Answers which lists Top Accounts with Revenue.
I Ranked the Revenue field and it is returning me correct values. ( Rank(account.revenue) )
But, when I try to filter on this field and restrict the rows which shows only top 10 Accounts, it is returning the following error:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1792, message: ORA-01792: maximum number of columns in a table or view is 1000 at OCI call OCIStmtExecute. [nQSError: 17010] SQL statement preparation failed. (HY000)
Can any one help me on this.
Thanks in Advance,
Imtiaz.Hi Joe,
This is the Physical query generated when I use Rank function and the report is fine.
select distinct D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c10 as c10,
D1.c11 as c11,
D1.c12 as c12,
D1.c13 as c13,
D1.c14 as c14,
D1.c15 as c15
from
(select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c10 as c10,
D1.c11 as c11,
D1.c12 as c12,
D1.c13 as c13,
D1.c14 as c14,
D1.c15 as c15
from
(select Case when D1.c1 is not null then Rank() OVER ( ORDER BY D1.c1 DESC NULLS LAST ) end as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c1 as c4,
D1.c4 as c5,
D1.c5 as c6,
D1.c6 as c7,
D1.c7 as c8,
D1.c8 as c9,
D1.c9 as c10,
D1.c10 as c11,
D1.c11 as c12,
D1.c12 as c13,
D1.c13 as c14,
D1.c14 as c15,
ROW_NUMBER() OVER (PARTITION BY D1.c1, D1.c2, D1.c3, D1.c4, D1.c5, D1.c6, D1.c7, D1.c8, D1.c9, D1.c10, D1.c11, D1.c12, D1.c13, D1.c14 ORDER BY D1.c1 ASC, D1.c2 ASC, D1.c3 ASC, D1.c4 ASC, D1.c5 ASC, D1.c6 ASC, D1.c7 ASC, D1.c8 ASC, D1.c9 ASC, D1.c10 ASC, D1.c11 ASC, D1.c12 ASC, D1.c13 ASC, D1.c14 ASC) as c16
from
(select distinct T690.SUM_REVN_AMT as c1,
T690.NAME as c2,
T2216.NAME as c3,
T690.X_PETROFAC_REVN as c4,
T690.SUM_WIN_PROB as c5,
T690.X_PERCENT_GET as c6,
T690.SUM_WIN_PROB * T690.X_PERCENT_GET / nullif( 100, 0) as c7,
T690.X_EC_PRIORITY as c8,
T19028.LOGIN as c9,
T690.X_COUNTRY as c10,
T690.X_REGION as c11,
T18311.NAME as c12,
T18641.NAME as c13,
T18238.NAME as c14
from
SIEBEL.S_BU T18238 left outer join (
SIEBEL.S_USER T19028 left outer join (
SIEBEL.S_OPTY T690 left outer join SIEBEL.S_STG T2216 On T690.CURR_STG_ID = T2216.ROW_ID) left outer join SIEBEL.S_ORG_EXT T1189 On T690.PR_DEPT_OU_ID = T1189.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18311 /* Competitor */ On T690.PR_CMPT_OU_ID = T18311.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18641 /* Partner */ On T690.PR_PRTNR_ID = T18641.ROW_ID) left outer join SIEBEL.S_POSTN T19114 On T690.PR_POSTN_ID = T19114.PAR_ROW_ID) left outer join SIEBEL.S_OPTY_BU T18280 On T690.ROW_ID = T18280.OPTY_ID) left outer join SIEBEL.S_OPTY_X T19415 On T690.ROW_ID = T19415.PAR_ROW_ID) On T19028.PAR_ROW_ID = T19114.PR_EMP_ID) On T18238.ROW_ID = T18280.BU_ID
) D1
) D1
where ( D1.c16 = 1 )
) D1
order by c1 desc
But When I apply Filter on this Rank column then it gives me the error. THis is the Physical query for that
select distinct Case when D1.c1 is not null then Rank() OVER ( ORDER BY D1.c1 DESC NULLS LAST ) end as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c1 as c4,
D1.c4 as c5,
D1.c5 as c6,
D1.c6 as c7,
D1.c7 as c8,
D1.c8 as c9,
D1.c9 as c10,
D1.c10 as c11,
D1.c11 as c12,
D1.c12 as c13,
D1.c13 as c14,
D1.c14 as c15
from
(select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c10 as c10,
D1.c11 as c11,
D1.c12 as c12,
D1.c13 as c13,
D1.c14 as c14
from
(select T690.SUM_REVN_AMT as c1,
T690.NAME as c2,
T2216.NAME as c3,
T690.X_PETROFAC_REVN as c4,
T690.SUM_WIN_PROB as c5,
T690.X_PERCENT_GET as c6,
T690.SUM_WIN_PROB * T690.X_PERCENT_GET / nullif( 100, 0) as c7,
T690.X_EC_PRIORITY as c8,
T19028.LOGIN as c9,
T690.X_COUNTRY as c10,
T690.X_REGION as c11,
T18311.NAME as c12,
T18641.NAME as c13,
T18238.NAME as c14,
Case when T690.SUM_REVN_AMT is not null then Rank() OVER ( ORDER BY T690.SUM_REVN_AMT DESC NULLS LAST ) end as c15
from
SIEBEL.S_BU T18238 left outer join (
SIEBEL.S_USER T19028 left outer join (
SIEBEL.S_OPTY T690 left outer join SIEBEL.S_STG T2216 On T690.CURR_STG_ID = T2216.ROW_ID) left outer join SIEBEL.S_ORG_EXT T1189 On T690.PR_DEPT_OU_ID = T1189.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18311 /* Competitor */ On T690.PR_CMPT_OU_ID = T18311.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18641 /* Partner */ On T690.PR_PRTNR_ID = T18641.ROW_ID) left outer join SIEBEL.S_POSTN T19114 On T690.PR_POSTN_ID = T19114.PAR_ROW_ID) left outer join SIEBEL.S_OPTY_BU T18280 On T690.ROW_ID = T18280.OPTY_ID) left outer join SIEBEL.S_OPTY_X T19415 On T690.ROW_ID = T19415.PAR_ROW_ID) On T19028.PAR_ROW_ID = T19114.PR_EMP_ID) On T18238.ROW_ID = T18280.BU_ID
) D1
where ( D1.c15 <= 10 )
) D1
order by c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15
Thanks,
Imtiaz -
How to use RANK function ?
Hello everyone,
here is the query I run in sql developer using RANKFunction.
SELECT Empno, Ename, Job, Mgr, Hiredate, Sal
FROM
(SELECT Empno, Ename, Job, Mgr, Hiredate, Sal,
*RANK*() OVER
(ORDER BY SAL Desc NULLS LAST) AS Emp_Rank
FROM Emp
ORDER BY SAL Desc NULLS LAST)
WHERE Emp_Rank < 6;How I can use this query in my report in obiee or is there any replacement of RANK() function in obiee so that I can use that to get my same above result.
ThanksKuldip wrote:
Thanks, you are absolutely correct. However, By doing this I am getting my output as whic I was not expecting.
Students Marks Rank
student1 95 1
student2 95 1
student3 93 3
student4 93 3
student5 91 5
The output should be as instead
Students Marks Rank
student1 95 1
student2 95 1
student3 93 2
student4 93 2
student5 91 3
Can It be done like this ?
Thanks.
Edited by: Kuldip on Mar 15, 2012 11:51 PMHi Boss,
I think you copied the above scenario from this site..
http://oracle-bi.siebelunleashed.com/articles/rank-and-dense-rank-functionsobiee/
Then why asking how to do this? Are you testing us? Doesn't that site say how to achieve this? -
Compile forms error because using rank function
Hi,
Oracle Form 9i don't known rank function in my SQL statement. When compile forms, it alerts err message: "Encountered the symbol "(" when expecting one ..."
code:
select * from (
select group_id, acct_no, acct_desc, rank() over(order by acct_no desc) rank_no from customer
where group_id='002'
) where rank_no< 10000
Help me ASAP.
Many thank,
Bum.Where is INTO clause ? Plz provide the actual code you are writing.
I think this type of queries not supported in Forms 9i.....try forms 10g or above. -
Filtering maximum rank using rank function ?
Hi ,
I have two table emp_changes(empno(number),operation_time(timestamp),operation(varchar))
and another table emp_metadata(tablename(varchar),max_time(timestamp))(it has got one row )
using this query :
select empno,operation,RANK() OVER (PARTITION BY empno ORDER BY operation_time) "time" from emp_changes
where empno in (select empno from emp_changes where operation_time BETWEEN (select max_time from emp_metadata) AND sysdate)I am getting this output:
EMPNO OPERATION time
8009 INSERT 1
8009 UPDATE 2
8009 DELETE 3
8010 INSERT 1
8013 INSERT 1
9001 UPDATE 1
9001 DELETE 2
can anyone please tell me how to achive this like ,I want to view only distinct empno,operation with max rank in time like:
EMPNO OPERATION
8009 DELETE
9001 DELETE
Thanks ,
DeekayHi, Deekay,
Analytic functions (inlcude RANK) are computed after the WHERE cluase is appled.
To use the results of an analytic function in a WHERE clause, first compute the analytic function in a sub-query, then use the value in the WHERE clause of a super-query, like this:
select empno
, operation
from ( -- Begin sub-query to compute time_rank
select empno
, operation
, RANK () OVER ( PARTITION BY empno
ORDER BY operation_time DESC
) AS time_rank
from emp_changes
where operation_time BETWEEN (
select max_time
from emp_metadata
AND sysdate
) -- End sub-query to compute time_rank
WHERE time_rank = 1
;If you'd like to post CREATE TABLE and INSERT statements for your data, then I could test this.
While it is possible to see which is the highest number returned by RANK, it is easier to see which is the lowest number; the lowest number is always 1. That's why I used DESCending order. -
Top 'n' using rank () function
Hi...
I'm using BO XI 3.0. In my report I need a user to enter TOP 'n' (n=5,10,20,50,100).
For example:
Caller No No of Calls
23467891 10
67698089 35
22377868 17
76378467 10
76374678 20
89978978 6
87786777 11
I already create dimension object for Caller No and measure object for No of Calls in universe.
So I use a rank filter in edit query but it doesn't work.
I also create another measure object in universe name =ranking
rank(No_of_Calls) over(partition by (Caller No) order by (No_of_Calls)).. but it's not work...
So can anybody help me....thanksHi,
Following information might be helpful in resolving the issue.
General Syntax of Ranking :
Rank( measure; (dimensions); [Top|Bottom])
Here is the work flow with an example :- (use efashion universe )
1) Create a webi report selecting objects quarter, year, sales revenue and create a cross tab
2) While creating a cross tab, use the Object Year in columns and object Quarter for rows.
3)Define a variable Var1 = Rank ([Sales Revenue] ; [Quarter]; [Year]) ForEach ([Year])
4) Insert a blank column next to year in the cross tab.
5) Drag and drop the variable Var1 in the new blank column inserted next to Object Year..
You will now find that you have ranking for the years 2001, 2002, 2003 being reflected
independently.
Regards,
Sarbhjeet Kaur -
How to use rank function in obiee rpd using evalute..
i created a logical column:
EVALUATE('RANK() OVER (PARTITION BY %1,%2)' AS DOUBLE PRECISION , Composites.Composites_Fact.MEMBER_LOCKED_BASE_RETURN, Composites.Composites_Fact.COMP_ID)
please provide some solutionThere is a known bug with EVALUATE when returning numbers. When I has the same problem Oracle Metalink has adviced to use CAST on the end result of the EVALUATE and return it as a FLOAT datatype.
CAST(EVALUATE('my_function(%1)', logical_table.ROWID) AS FLOAT) -
I am trying to modify an object in a universe built on BW using MDX. The object is [ZCALDAY2].[NAME]. The object brings back a list of dates yyyymmdd. I would like it to only bring back yyyymm ( and distinct values only). Is this possible?
I have tried <EXPRESSION>MID([ZCALDAY2].[NAME],1,6)</EXPRESSION> - no luck! Any help would be appreciated
Thanks
TomNot supported in BW
-
Wrong order in pivot table using Rank function
Hi Gurus,
I have the following query:
SELECT Periods."Year" saw_0, Periods."Month" saw_1, SalesFacts.Dollars saw_2, RANK(SalesFacts.Dollars BY Periods."Year") saw_3
FROM SupplierSales ORDER BY saw_0, saw_3
In table view the order is correct.
However in pivot table for 1998 (year) the order is correct, for 1999 not!
Ordering : 1. Year, 2. RANK
Page: Year, Rows : Months
Measures : Dollars and RANK
( I tried to put the RANK into Rows section, the result is same )
What is the reason of this strange behavior?
Thanks
LaszloTry Sort Column and Row properties given in pivot Table Chart...
Maybe your problem will resolve -
Hi Expert,
Could you please let me know how can I use rank function in MDX to achieve the result in below format. Highest value should be ranked as 1
Actual/Expected Dataset appears as:
Thanks ChandanHi C,
You can use the mdx RANK() function. For example, this query has ranking of cities by sales amount. You could create two sets, and two calcs with RANK() functions for your challenge.
WITH
SET OrderedCities AS Order
([Geography].[City].[City].members
, [Measures].[Reseller Sales Amount], BDESC
MEMBER [Measures].[City Rank] AS Rank
([Geography].[City].CurrentMember, OrderedCities)
SELECT {[Measures].[City Rank],[Measures].[Reseller Sales Amount],[Measures].[City Rank]} ON 0
,[Geography].[City].[City].MEMBERS
ON 1
FROM [Adventure Works]
Hope that helps,
Richard -
Use variables in ParallePeriod function in MDX
Hello, I am using PARALLELPERIOD () function in MDX. the syntax is
PARALLELPERIOD([Date].[Calendar Hierarchy].[Year],1,[Date].[Calendar Hierarchy].[Date].&[20131201]). My question is can i use two variables in this? like PARALLELPERIOD( @Level,1,@Member). I know we can do PARALLELPERIOD([Date].[Calendar Hierarchy].[Year],1,@Member).
With this two variables, i can use same query for calendar hierarchy and week hierarchy etc. Please let me know your thoughts. A work around solution is also fine.
or can I derive @level from @member on the fly? something like PARALLELPERIOD( @Member.level,1,@Member)
thanks in advance.
prajwal kumar potulaYou can use variables like that client side. That may be a .NET function that generates MDX, or SSRS does the same thing.
Regarding whether you can derive @Level from @Member, yes you can. Once you have substituted @Member in the query, you can use the .Level function, so it would look like this - after substitution:
PARALLELPERIOD( [Date].[Calendar Hierarchy].[Date].&[20131201].Level,
1,
[Date].[Calendar Hierarchy].[Date].&[20131201]
Christian Wade
http://christianwade.wordpress.com/
Please mark correct responses as answers! -
Rank function on Union reports
Hi All,
I have a requirement where i have 2 reports the first report is a single and simple report where i have to show top 10 countries based on a measure value and it should have a section break on country which i have achieved the same using a rank function.
Another report which has got 20 union reports but rank function is not working the same way as a single and simple report, i couldn't get any possible solution for this. Any pointers would be much appreciated
Regards
PavanHi srini,
I did not get you, what exactly you mean keeping the rank in outer query? i have used rank function in each of the 20 union reports. -
I created a simple sql query using rank function as shown below. My question is how do I check the values in the total_income to see if they are different?
Query:
select * from
select cardholderid, appcnum,total_income, Rank() over (PARTITION BY A.APPCNUM
ORDER BY A.EFFENDDATE DESC, A.EFFSTARTDATE DESC, A.CREATEDATE DESC) as Rank
from
TBL_EPIC_BILLSTATUS A
) tmp
where Rank in (2,3)
Results:
CARDHOLDER
APPCNUM
TOTAL_INCOME
RANK
704355
2121362
21912
2
704355
2121362
20938
3what do you mean by check values in total income?? you have column total column there right??
if i understand it right, you do another rank for total income..
Rank() over (partition by APPCnum order by total_income desc) as [total income rank]
Hope it Helps!!
That wouldn't quite help as even if they were the same value, rank would still give 1 and 2. Dense_rank would give them both 1 if they were the same but wouldn't help identify if they were the same from a dynamic view. You could either do a lead to read the
total_income of the next if that is appropriate or you'd have to pivot them to one row and then compare
Maybe you are looking for
-
Set Window Size when opening Image from Photo Gallery
Is it possible in XML to set a window size (height and width)? My code for the Image Gallery is below, and I can't figure out a way to set the window size.
-
Hi Gurus, Request your advice on this one. After payroll posting run, the GL linked /559 wagetype is populated. What is the best way to transfer the amount in this to the GL of bank account automatically. i.e Debit the GL linked to /559 wagetype and
-
Buffer table not up to date - BBP_PD_PO_SAVE Function Module
Hi SRM Experts, I am trying to develop custom program for uploading POs into SRM and got struck at the time of BBP_PD_PO_SAVE function Module. I followed the follwoing steps: Step 1: Creating PO with BBP_PD_PO_CREATE - this step executed successfully
-
Too many photos hanging around??
I have had LR for about 3 months. I have bought 90 dollars of books. I get so confused. I have 12,000 pictures on a external hard drive. I can import them to Elements and LR and do what i want with them.... My problem is this. I down load the picture
-
Implementi​ng PLL in FPGA LabVIEW
Hello, I want to implement PLL in FPGA by refering to the example(the file is attached). I've modified the example, so that it can work in single phase PLL (the file is attached). However, it is not working. To be honest, I'm new in LabVIEW, so just