dbTalk Databases Forums  

Sum Question

microsoft.public.sqlserver.olap microsoft.public.sqlserver.olap


Discuss Sum Question in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
rush_edward (AT) eddierush (DOT) net
 
Posts: n/a

Default Sum Question - 05-12-2006 , 09:19 AM






I am trying to create a row that contains the sum of all the values in
my query. My query looks like this

with

//Columns
set[main] as
'{[Measures].[cGrossSales],
[Measures].[cPYGrossSales]}'

//lists all customers
set [rowfilter] as
'FILTER({[Customer].[Chain].[lCustNbr].Members},not isempty(
[Measures].[cGrossSales]))'

select
{[main]}
on columns,

{[rowfilter]}
on rows

FROM CusItmWk_Dev

WHERE([Time_Partial].[All Time_Partial].[2006].[Qtr2 - 2006].[Period 05
- 2006].[Week 18 - 2006],
[Customer].[Type].[sType].&[VHVW])



------------
My result looks like this
cGrossSales cPYGrossSales
customer1 500 500
customer2 500 500


What I would like to do is Sum all of the customers values into a row
like thisthe row header is not so important as the values)

cGrossSales cPYGrossSales
customer1 500 500
customer2 500 500
total 1000 1000


How can I accomplish this? I do not completely understand MDX yet, but
I am trying very hard.


Reply With Quote
  #2  
Old   
Deepak Puri
 
Posts: n/a

Default Re: Sum Question - 05-12-2006 , 09:11 PM






Try VisualTotals() - like in this Adventure Works query:

Quote:
With Set [CustSet] as
VisualTotals({[Customer].[Customer].[All Customers],
[Customer].[Customer].&[18740], [Customer].[Customer].&[26837]},
"Partial Total - *")
select {[Measures].[Internet Order Quantity]} on 0,
[CustSet] on 1
from [Adventure Works]
-------------------------------------------------------
Internet Order Quantity
Partial Total - All Customers 5
Adam Hill 3
Albert Martin 2
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***


Reply With Quote
  #3  
Old   
Darren Gosbell
 
Posts: n/a

Default Re: Sum Question - 05-12-2006 , 11:02 PM



You could do this by creating a calculated member that aggregates the
'rowfilter' set and then union that member onto set on the row axis.

eg.

Quote:
with

//Columns
set[main] as
'{[Measures].[cGrossSales],
[Measures].[cPYGrossSales]}'

//lists all customers
set [rowfilter] as
'FILTER({[Customer].[Chain].[lCustNbr].Members},not isempty(
[Measures].[cGrossSales]))'

// calculate total customers
member [Customer].[Chain].[total] as 'AGGREGATE(rowfilter)'

select
{[main]} on columns,

UNION({[rowfilter]},{[Customer].[Chain].[total]})on rows

FROM CusItmWk_Dev

WHERE([Time_Partial].[All Time_Partial].[2006].[Qtr2 - 2006].[Period 05
- 2006].[Week 18 - 2006],
[Customer].[Type].[sType].&[VHVW])
Quote:

--
Regards
Darren Gosbell [MCSD]
Blog: http://www.geekswithblogs.net/darrengosbell


In article <1147443569.831871.227870 (AT) d71g2000cwd (DOT) googlegroups.com>,
rush_edward (AT) eddierush (DOT) net says...
Quote:
I am trying to create a row that contains the sum of all the values in
my query. My query looks like this

with

//Columns
set[main] as
'{[Measures].[cGrossSales],
[Measures].[cPYGrossSales]}'

//lists all customers
set [rowfilter] as
'FILTER({[Customer].[Chain].[lCustNbr].Members},not isempty(
[Measures].[cGrossSales]))'

select
{[main]}
on columns,

{[rowfilter]}
on rows

FROM CusItmWk_Dev

WHERE([Time_Partial].[All Time_Partial].[2006].[Qtr2 - 2006].[Period 05
- 2006].[Week 18 - 2006],
[Customer].[Type].[sType].&[VHVW])



------------
My result looks like this
cGrossSales cPYGrossSales
customer1 500 500
customer2 500 500


What I would like to do is Sum all of the customers values into a row
like thisthe row header is not so important as the values)

cGrossSales cPYGrossSales
customer1 500 500
customer2 500 500
total 1000 1000


How can I accomplish this? I do not completely understand MDX yet, but
I am trying very hard.


Reply With Quote
  #4  
Old   
rush_edward (AT) eddierush (DOT) net
 
Posts: n/a

Default Re: Sum Question - 05-15-2006 , 10:13 AM



Thanks guys for all of your input. Here is what I did.
....
set[rowfilter]
as
'(FILTER({[Customer].[Chain].[lCustNbr].Members}, not isempty(
[Measures].[cGrossSales])))'
member [Customer].[Chain].[Total] as 'sum({rowfilter})'
....
{[rowfilter], [Customer].[Chain].[Total]} ON ROWS


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.