Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


MDX equivalent of group by MAX


MDX equivalent of group by MAX

Author
Message
blueazul
blueazul
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 319
Hello, I am pretty new to MDX --- I usually use sql to create reports or reporting procedures. However, there is a growing need for faster/flexible reporting so I'm looking into SSAS as a possible solution. However, I am really having trouble with simple queries. For example, we have a summary table that summarizes millions of transactions by grouping by a baseline and standard group of columns that all queries would be based on. In this table we have sum/count/mean/stdev/min/max. Then we use this table as the base for rollups or further groupings after joining to attribute tables. So this is like our fact table. Anyway, I have a desire to select the MAX of a group based on this table. Below is an example:



create table purchases
(
   trans_id int not null,
   dept_id int not null,
   product_id int not null,
   cost int not null,

   constraint pk_purchases primary key(trans_id)
);
go

create table summary
(
   dept_id int not null,
   product_id int not null,
   sum int not null,
   max int not null,
   min int not null,
   count int not null,

   constraint pk_fact primary key(dept_id, product_id)
);
go

create table product
(
   product_id int not null,
   vendor_id int not null,

   constraint pk_product primary key(product_id)
)
go


insert into purchases(trans_id, dept_id, product_id, cost)
values
(1, 1, 1, 100),
(2, 1, 1, 300),
(3, 1, 3, 300),
(4, 2, 1, 400),
(5, 2, 3, 400),
(6, 3, 2, 100);
go

insert into product(product_id, vendor_id)
values
(1, 1),
(2, 1),
(3, 2);
go

insert into summary(dept_id, product_id, max, min, sum, count)
select dept_id, product_id, max(cost), min(cost), sum(cost), count(1)
from dbo.purchases
group by dept_id, product_id
go

--query to get max of summarized sum by dept id, how can I do this in MDX?
--my SSAS project has the summary/product/purchases tables as dimensions and the summary table stats as measures
select max(sum), dept_id
from dbo.summary
group by dept_id



I have tried creating a member calculation using max. But it seems like its summing instead of maxing. I think it is taking the max of the depts including a <null> dept that is the sum of all dept, so the max is always the <null>, which is the sum of all depts. Just to be clear I don't have any null depts, I assume the cube creates this set as part of its pre-processing.

Thanks!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search